podcontract

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package podcontract defines Snapshot's workload Pod contract and provides helpers to build, validate, and interpret restore Pods.

Index

Constants

View Source
const (
	// RestoreFromAnnotation names the PodSnapshot to restore in the Pod's
	// namespace.
	RestoreFromAnnotation = "nvidia.com/restore-from"

	// RestoreContainerMapAnnotation optionally maps the single captured source
	// container to one or more restore destinations. Its value is a
	// comma-separated list of source=destination pairs. When absent, restore
	// uses the captured container name as the destination.
	RestoreContainerMapAnnotation = "nvidia.com/restore-container-map"

	// DefaultSeccompLocalhostProfile is the kubelet-local profile installed by
	// the Snapshot Helm chart to block io_uring for CRIU.
	DefaultSeccompLocalhostProfile = "profiles/block-iouring.json"

	// SnapshotControlVolumeName is the per-Pod emptyDir used to carry capture and
	// restore lifecycle files between Snapshot and the workload.
	SnapshotControlVolumeName = "snapshot-control"

	// SnapshotControlMountPath is where the control volume is mounted inside a
	// Snapshot-managed workload container.
	SnapshotControlMountPath = "/snapshot-control"

	// SnapshotControlDirEnv is the canonical environment variable exposing the
	// control mount path to the workload.
	SnapshotControlDirEnv = "SNAPSHOT_CONTROL_DIR"

	// LegacySnapshotControlDirEnv is the deprecated environment variable
	// exposing the control mount path to the workload.
	//
	// Deprecated: use SnapshotControlDirEnv instead.
	LegacySnapshotControlDirEnv = "DYN_SNAPSHOT_CONTROL_DIR"

	// ReadyForSnapshotFile is written by the workload when the model is loaded
	// and the workload is ready for capture. The source Pod's kubelet readiness
	// probe observes it through the control volume.
	ReadyForSnapshotFile = "ready-for-snapshot"

	// CUDAJobFileName is the stable name under which the
	// cuda-checkpoint-helper launch-job wrapper persists the CUDA checkpoint job
	// file inside the control volume.
	CUDAJobFileName = "cuda-checkpoint-job"

	// CUDAJobFilePath is the full stable path to the persisted CUDA checkpoint
	// job file.
	CUDAJobFilePath = SnapshotControlMountPath + "/" + CUDAJobFileName

	// RestoreStandbyModeEnv asks standby-aware workload entrypoints to remain
	// inert until Snapshot replaces them with restored processes. Snapshot
	// publishes the name so producers and workloads agree on it, but does not
	// inject this workload-specific setting.
	RestoreStandbyModeEnv = "SNAPSHOT_RESTORE_STANDBY"

	// LegacyRestoreStandbyModeEnv is the previous name of RestoreStandbyModeEnv,
	// kept for existing workload integrations that still read it. Snapshot
	// publishes the name but does not inject it.
	//
	// Deprecated: use RestoreStandbyModeEnv. This alias is removed in the next
	// release.
	LegacyRestoreStandbyModeEnv = "DYN_SNAPSHOT_RESTORE_STANDBY"

	// RestoreCompleteFile is written by the Snapshot agent when restore has
	// completed and the workload may resume.
	RestoreCompleteFile = "restore-complete"
)

Snapshot workload Pod annotations and control protocol.

View Source
const (
	// RestoredCondition is the Pod status condition owned by the Snapshot node
	// agent.
	RestoredCondition = "nvidia.com/Restored"

	// RestoreReasonInProgress marks active restore execution.
	RestoreReasonInProgress = "RestoreInProgress"
	// RestoreReasonSucceeded marks a terminal all-destinations success.
	RestoreReasonSucceeded = "RestoreSucceeded"
	// RestoreReasonFailed marks a terminal all-destinations failure.
	RestoreReasonFailed = "RestoreFailed"
	// RestoreReasonPartiallySucceeded marks a terminal mixed destination outcome.
	RestoreReasonPartiallySucceeded = "RestorePartiallySucceeded"
)

Stable reasons used on the nvidia.com/Restored Pod condition. Dependency-wait reasons remain agent-internal; consumers should use ClassifyRestoreOutcome.

Variables

This section is empty.

Functions

func Build

func Build(pod *corev1.Pod, request Request, options Options) (*corev1.Pod, error)

Build returns a restore-shaped deep copy of pod. The caller's Pod is never mutated, including when validation fails. Workload-specific standby behavior and container commands remain the caller's responsibility. Mapping sources must come from the referenced PodSnapshot; this pure builder performs no API read to derive them.

func GetRestoreFromSnapshotName

func GetRestoreFromSnapshotName(annotations map[string]string) (string, error)

GetRestoreFromSnapshotName returns the same-namespace PodSnapshot named by the restore-from annotation.

func Validate

func Validate(pod *corev1.Pod, request Request) error

Validate verifies that pod implements Snapshot's minimum restore protocol. Optional workload policy such as startup gating and seccomp selection is not part of this agent-facing validation. Validate performs no API reads and never mutates the Pod.

func ValidateContainerMappings

func ValidateContainerMappings(mappings []ContainerMapping, capturedSource string) error

ValidateContainerMappings enforces the one-source-to-many-destinations contract after parsing.

Types

type ContainerMapping

type ContainerMapping struct {
	Source      string
	Destination string
}

ContainerMapping maps the one captured source container to a restore destination in the target Pod.

func ContainerMappingsFromAnnotations

func ContainerMappingsFromAnnotations(
	annotations map[string]string,
	capturedSource string,
) ([]ContainerMapping, error)

ContainerMappingsFromAnnotations parses the optional flat restore mapping. Absence keeps the existing same-name restore behavior.

type Options

type Options struct {
	// SeccompProfile is the kubelet-local profile applied to each restore
	// destination container. Empty leaves seccomp configuration entirely
	// caller-owned.
	SeccompProfile string

	// EnableStartupGate replaces each destination container's startup probe
	// with a restore-completion gate. Workload owners opt in when Kubernetes
	// must withhold readiness and liveness until restore completes.
	EnableStartupGate bool
}

Options controls optional restore Pod shaping. Its zero value applies only the mechanics required by Snapshot's minimum restore protocol.

type Request

type Request struct {
	SnapshotName    string
	SourceContainer string
	Mappings        []ContainerMapping
}

Request identifies the PodSnapshot source and its restore destinations. Empty Mappings default to restoring SourceContainer into a same-named destination container.

type RestoreOutcome

type RestoreOutcome string

RestoreOutcome is the stable, consumer-facing state of a restore request.

const (
	// RestoreOutcomeUnknown means the Restored condition exists but cannot be
	// classified safely by this API version.
	RestoreOutcomeUnknown RestoreOutcome = "Unknown"
	// RestoreOutcomePending means restore has not reached a terminal outcome.
	// It includes an absent condition and active restore execution.
	RestoreOutcomePending RestoreOutcome = "Pending"
	// RestoreOutcomeSucceeded means every requested destination was restored.
	RestoreOutcomeSucceeded RestoreOutcome = "Succeeded"
	// RestoreOutcomeFailed means no requested destination was restored.
	RestoreOutcomeFailed RestoreOutcome = "Failed"
	// RestoreOutcomePartiallySucceeded means some, but not all, requested
	// destinations were restored.
	RestoreOutcomePartiallySucceeded RestoreOutcome = "PartiallySucceeded"
)

func ClassifyRestoreOutcome

func ClassifyRestoreOutcome(conditions []corev1.PodCondition) RestoreOutcome

ClassifyRestoreOutcome returns the public restore outcome represented by Pod conditions. A missing Restored condition is Pending. An unrecognized status or reason is Unknown so callers can apply their own version-skew policy.

func (RestoreOutcome) Terminal

func (o RestoreOutcome) Terminal() bool

Terminal reports whether the restore outcome is final.

Jump to

Keyboard shortcuts

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