restore

package
v0.33.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package restore implements in-namespace restore of a snapshot tree.

Restore walks the selected namespaced snapshot hierarchy, fetches each node's manifests-with-data-restoration response with scope=node, and stages the complete post-order result before applying any object. This keeps every response bounded while preserving the server compiler's child-before-parent apply order. The compiler already rewrites PVCs with spec.dataSourceRef -> VolumeSnapshot (and a domain controller sets the dataSource on VirtualDiskSnapshot for domain disks), so CSI provisions volume data from the snapshot that already exists in the target namespace. There is no VolumeRestoreRequest and no SnapshotContent BFS.

Cross-namespace restore is intentionally out of scope: it is modelled as download (namespace A) -> import (namespace B) -> restore (in namespace B), which recreates the Snapshot and the VolumeSnapshot/VirtualDiskSnapshot leaves in B.

Index

Constants

View Source
const (

	// DefaultControlPlaneTimeout bounds one restore control-plane call.
	DefaultControlPlaneTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, cfg Config) error

Run executes an in-namespace restore: anchor selection to the positional Snapshot, preflight the addressed node, fetch apply-ready manifests for the target namespace, apply every object as-is, and optionally wait for restored PVCs to bind.

func ValidateNodeAPIVersion

func ValidateNodeAPIVersion(apiVersion string) error

ValidateNodeAPIVersion validates the canonical apiVersion syntax accepted by --node-api-version and persisted Kubernetes object identities.

Types

type Config

type Config struct {
	// Namespace is both the source Snapshot namespace and the restore target namespace.
	Namespace string
	// Snapshot is the name of the root Snapshot to restore.
	Snapshot string

	// SelectedNodeKind restricts the restore to a single node subtree when non-empty.
	// The selector is resolved within Snapshot's status.childrenSnapshotRefs hierarchy
	// by generated snapshot-CR identity, captured status.sourceRef identity, or the
	// original archive identity preserved on an import-mode marker.
	// RestoreManifestsScoped is called with the matched node's real snapshot-CR NodeRef.
	// Preflight checks the selected node's Ready (or readyToUse for VolumeSnapshot), not
	// the root — so a Ready child can be restored even when the root is
	// Ready=False/ChildSnapshotDeleted.
	SelectedNodeKind string
	// SelectedNodeName is the name of the selected node. Required when SelectedNodeKind is set.
	SelectedNodeName string
	// SelectedNodeAPIVersion optionally restricts generated and original identities to
	// one exact Kubernetes apiVersion. Core resources use "v1"; named groups use
	// "<group>/<version>".
	SelectedNodeAPIVersion string

	// Scope narrows the server-side manifest compilation: aggapi.RestoreScopeSubtree (the
	// zero value behaves identically) compiles the addressed node and its whole subtree;
	// aggapi.RestoreScopeNode compiles only the addressed node, with no descendants.
	Scope aggapi.RestoreScope
	// FilterKind and FilterName, when both set, restrict the restore to a single captured
	// object within the addressed node. The server accepts this only together with
	// Scope == aggapi.RestoreScopeNode (see validate in cmd/restore) and 400s otherwise.
	FilterKind string
	FilterName string
	// FilterAPIVersion further disambiguates FilterKind/FilterName when the node captures
	// more than one object of the same kind+name under different API versions. Not yet
	// exposed as a CLI flag (kind+name is unambiguous within a node); forwarded as-is.
	FilterAPIVersion string

	// Edit, when true, opens the resolved manifests in the user's preferred editor
	// (kubectl-style: $KUBE_EDITOR, $EDITOR, vi) before the preflight and apply
	// passes. A non-zero editor exit, unchanged content, or empty content aborts
	// the restore without applying anything.
	Edit bool
	// AutoEdit opens the resolved manifests once when the pre-mutation DryRunAll
	// pass returns Kubernetes Invalid. Command callers enable it only when both
	// stdin and stdout are interactive terminals and --no-auto-edit is absent.
	// Edit and DryRun always suppress this automatic session.
	AutoEdit bool

	// DryRun, when true, passes DryRunAll to every SSA apply so the API server
	// validates and admits objects without persisting them. The --wait loop is
	// skipped entirely in dry-run mode because nothing was created.
	DryRun bool
	// Wait, when true, blocks until all restored PersistentVolumeClaims reach Bound.
	Wait bool
	// Timeout bounds the Bound wait (only used when Wait is true).
	Timeout time.Duration
	// PollInterval is the Bound polling cadence (only used when Wait is true).
	PollInterval time.Duration
	// ControlPlaneTimeout bounds each Source, discovery, Get, List, and Patch call
	// independently. It is not a deadline for the complete restore.
	ControlPlaneTimeout time.Duration

	// Source fetches the apply-ready manifests (manifests-with-data-restoration).
	Source Source
	// Dynamic applies the restored objects and reads PVC status during the wait.
	Dynamic dynamic.Interface
	// Mapper resolves object GVKs to resources and their namespacing scope.
	Mapper meta.RESTMapper
	// Log receives progress output.
	Log *slog.Logger
	// contains filtered or unexported fields
}

Config holds all parameters for one in-namespace restore run.

type Source

type Source interface {
	RestoreManifestsScoped(ctx context.Context, ref aggapi.NodeRef, targetNamespace string, opts aggapi.RestoreScopeOptions) ([]byte, error)
}

Source reads the apply-ready manifest array for a snapshot subtree (or, with aggapi.RestoreScopeNode and an object filter, a single captured object) from the state-snapshotter aggregated API. It is satisfied by *aggapi.Client and stubbed in tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL