confsnap

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package confsnap keeps a byte-for-byte copy of the host configuration files that more than one node stack writes, so a failed migration or upgrade can put them back. A snapshot is a directory: a blob per regular file and a manifest that records every path, its kind, mode and owner. The manifest is written last and atomically, so a snapshot that exists is complete and a crash while taking one leaves nothing to restore.

Snapshots hold credentials (kubelet client keys), so the directory and the blobs are private to the owner.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSnapshot = errors.New("no configuration snapshot")

ErrNoSnapshot is returned by Restore when dir holds no complete snapshot.

View Source
var ErrSnapshotExists = errors.New("a configuration snapshot already exists")

ErrSnapshotExists is returned by Take when dir already holds a complete snapshot. That snapshot is the only record of a configuration a crash may have interrupted the restore of, so it is never overwritten: the caller restores or discards it first.

Functions

func Discard

func Discard(dir string) error

Discard removes the snapshot.

func Exists

func Exists(dir string) bool

Exists reports whether dir holds a complete snapshot.

func PathsFor

func PathsFor(modes ...isolation.Mode) []string

PathsFor returns SharedPaths plus the host paths that the node stacks of the given modes write in place, so a snapshot taken before one of them is built restores everything it can overwrite. A container slot's rootfs maps the same-path directories to the host, so preparing one writes the host's CNI plugins (/opt/cni/bin) while the old slot still runs.

func Restore

func Restore(dir, root string) error

Restore puts every recorded path back as it was when the snapshot was taken: the same bytes, mode, owner and links. Files that were created below a recorded directory since are removed, and a path recorded as absent is removed. It is idempotent, and leaves a file alone when it already matches. Every path is attempted, and the errors are joined.

func SharedPaths

func SharedPaths() []string

SharedPaths returns the host configuration paths that the node stacks of different isolation modes (or two versions of one) both write, at the same location: the containerd and kubelet configuration, the kubelet identity and PKI, the CNI configuration and the LocalDNS files. Units and binaries are not here; each backend restores those itself. The list is a superset: a path a mode does not use on the host is recorded as absent and stays absent.

func Take

func Take(dir, root string, paths []string) (err error)

Take records the state of paths, which are absolute in-node paths, below root (empty means the real filesystem root) into dir. A complete snapshot already in dir is refused with ErrSnapshotExists; an incomplete one, which a crash during an earlier Take leaves, is replaced. The snapshot is durable once Take returns: every saved file and the manifest are synced, the manifest last, so a manifest on disk always names files that are there. A directory is recorded with everything below it; symbolic links are recorded, not followed. A path that does not exist is recorded as absent. Sockets, devices and other special files are an error, since they cannot be put back.

Types

type Kind

type Kind string

Kind is what a path was when the snapshot was taken.

const (
	// Absent means the path did not exist; restoring removes it.
	Absent  Kind = "absent"
	File    Kind = "file"
	Dir     Kind = "dir"
	Symlink Kind = "symlink"
)

Jump to

Keyboard shortcuts

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