Repository navigation
Conversation
2e3ee24 to
3f3cfaa
Compare
3f3cfaa to
a2423ae
Compare
a2423ae to
321de73
Compare
321de73 to
194c288
Compare
194c288 to
2f67dab
Compare
mikebrow
left a comment
There was a problem hiding this comment.
- RunPodSandbox changes the normal path, not just restore.
sandbox_run.go moves lease creation to after SandboxStore().Create.
- On failure, the deferred cleanup now deletes the lease before the sandbox record, which is the reverse of the old order.
- pls specify the reason for this change... is it so a failed lease delete can keep the restore intent? If so the commit message should say so. Additionally, If that is the reason, it is worth confirming that ordinary sandboxes are unaffected.
- A finite deadline is now mandatory. requirePodCheckpointDeadline rejects any request without one.
- Was this the intention? Is probably correct, since a freeze with no deadline is potentially dangerous. If so, it means crictl/critest CRI users must pass --timeout, so it should be called out in the docs and error text.
-
CRIU check is cached. checkCriu uses sync.Once, so a failure persists until the daemon restarts. This matches the existing CheckpointContainer behavior.. but we might want to address this.
-
Output directory race. validateCheckpointOutputPath checks the path with Lstat and then writes via filepath.Join, not through a directory file descriptor. The restore side is openat-hardened and the write side is not. The caller is root-only, so this is low risk, but it is inconsistent.
-
Shim Init locking. Status() now runs resumeExited and reconcilePauseState, which call into the runtime while holding p.mu. They only fire when the new flags are set, so the cost is bounded. A failed reconcile makes Status return an error, we should have an e2e / local integration bucket that checks the kubelet and containerd integrations tolerate that.
-
Scope. This PR is very large. It touches the shim, the sandbox core, CRI config, and restart/recovery. Splitting the shim pause-state fix and the config rename into their own PRs would make review easier.
-
Remote controllers. CheckpointController is a Go-only interface. Shim-based or remote sandboxers report Unimplemented. The PR documents this, but it is worth confirming that this is an acceptable limitation/todo for the KEP.
...this review was assisted by IBM Bob
A runtime pause or resume can change the task state before returning an error. Reconcile the shim state with the runtime before later operations so a failed pause can still be resumed and retried. Reject operations until reconciliation finds a stable runtime state. Keep failed exit-time thaws retryable without changing the stopped process state. An executable fake runtime exercises command failures and cancellation without changing host cgroups. Signed-off-by: Radostin Stoyanov <[email protected]>
Container checkpoints capture file locks. Enable lock restoration when creating the checkpointed task so resumed processes retain those locks. Signed-off-by: Radostin Stoyanov <[email protected]>
CRIU uses the saved process and mount labels unless the runtime passes replacements. A restored process can therefore keep the source MCS category while its root filesystem uses the destination category, and SELinux denies access to the restored files. Pass the destination OCI process and mount labels to runc. Give labeled restores a private work directory with that mount label, since CRIU passes its log fd to the restored process. Keep logs after a restore attempt and remove an unused directory when deleting an unstarted task. Signed-off-by: Radostin Stoyanov <[email protected]>
Require a single task checkpoint with a valid digest and size before passing its descriptor to the task service. Reject annotations because restore options can interpret them as host filesystem paths. Signed-off-by: Radostin Stoyanov <[email protected]>
enable_criu gates CheckpointContainer, and the upcoming CheckpointPod and RestorePod RPCs will use the same setting. Those RPCs delegate to the selected sandbox controller, which need not use CRIU: CRIU is a prerequisite of the pause-container controller only. Rename enable_criu to enable_checkpoint_restore to describe the capability controlled by the setting. Keep enable_criu as a deprecated alias until containerd v2.6 and preserve the platform defaults. The new option is unset by default, so setting both names to different values is detected and rejected instead of one silently overriding the other. Verbose CRI status reports the effective value as both enableCheckpointRestore and enableCRIU until the alias is removed. Signed-off-by: Radostin Stoyanov <[email protected]>
CheckpointContainer checks that CRIU is available in the shim's PATH and meets the minimum version. The upcoming Pod checkpoint service in the pause-container controller needs the same check, but lives in the podsandbox package. Move the lookup and version check into internal/cri/util and call it from doCheckCriu, so both use the same shim PATH and minimum version. Signed-off-by: Radostin Stoyanov <[email protected]>
The CRI plugin reads the last PATH entry from the shim plugin's environment so CheckpointContainer finds CRIU where the shim runs it. The pause-container controller will need the same PATH for its Pod checkpoint service. Move the lookup into ShimPath() in internal/cri/util and use it from initCRIService(). Signed-off-by: Radostin Stoyanov <[email protected]>
The upcoming Pod checkpoint and restore support in the CRI plugin delegates runtime-specific work to the selected sandbox controller. The pause-container controller will capture Pods with cgroup freezing and CRIU, while another controller can use its own mechanism. Add an optional CheckpointController interface next to Controller. Configurations, selected containers, paths and options are passed as data, so implementations need no access to CRI stores or lifecycle callbacks. Controllers that do not implement the interface keep working unchanged, and callers detect support with a type assertion. Signed-off-by: Radostin Stoyanov <[email protected]>
The upcoming Pod checkpoint support in the pause controller freezes the Pod cgroup, so that the selected containers can be paused at the same point. The cgroup comes from the sandbox config's cgroup parent. With the systemd cgroup driver, the parent names a slice that runc nests by the dashes in its name. Add a freezer for the Pod cgroup that supports cgroup v1 and v2. It waits for the requested state until its context ends, and reports whether a freeze may have taken effect even when it fails, so that its caller knows when to thaw. Validate the cgroup parent and expand systemd slices as runc does. The root cgroup and root slice are rejected. Signed-off-by: Radostin Stoyanov <[email protected]>
Implement CheckpointController in the pause controller. Checkpoint validates the selected containers, then freezes the Pod cgroup, pauses each selected task and thaws the cgroup again, so that the tasks stop at the same point while the pause container and unselected containers keep running. It checkpoints each paused task with its runtime state and writable layer, resumes the tasks, and only then exports the checkpoint images as OCI archives and writes the manifest. The service supports only the runc v2 shim. Reject containers of other runtimes with Unimplemented before freezing the Pod: the runsc shim, for example, cannot report task state while its sandbox is frozen. Check CRIU after the runtimes, so such a Pod is not reported as missing CRIU. Take the writable-layer diff after the task checkpoint. CRIU can let a paused task run while it seizes it, for example when a plugin requires its interrupt-only mode, so a diff taken first can miss file changes that the dumped process state depends on. Label the private CRIU work directory with the container's effective SELinux mount label. CRIU passes its log fd to the process being dumped. With SELinux enforcing, that process cannot write to a log carrying containerd's storage label. When a checkpoint fails, thaw the Pod, resume the paused tasks, delete the temporary images and remove the output written so far. Temporary metadata and archive files use recognizable names. Restore returns Unimplemented until restore preparation is added. The controller checks the CRI checkpoint/restore setting itself. Signed-off-by: Radostin Stoyanov <[email protected]>
A daemon crash during a Pod checkpoint skips the in-request cleanup. It can leave the Pod cgroup frozen, the selected tasks paused, and temporary checkpoint images and partial output behind. Save a recovery marker before freezing. It records the request namespace, sandbox, cgroup parent, selected containers and output directory. Keep it through export and temporary-image deletion so cleanup can retry after a restart, and record the resumed phase before image cleanup. Write markers to a temporary file and rename it into place while holding the sandbox reservation; temporary files left by a crash are removed when the service starts. Write pod-config.json only after the marker, so that recovery owns every file a checkpoint writes. Recover interrupted checkpoints when the controller starts. Recovery attempts every marker and keeps failed ones for a retry. A failed recovery is logged and retried in the background instead of failing CRI startup, and a marker left by a failed checkpoint is recovered before the next checkpoint of the same sandbox. Recovery keeps published checkpoints and removes known partial output when the manifest is absent. Signed-off-by: Radostin Stoyanov <[email protected]>
The upcoming RestorePod RPC creates containers in CREATED state and asks the sandbox controller to prepare a containerd task checkpoint image for each of them. The process must be restored later, by StartContainer, so that the caller can complete pre-start setup first. Add TaskCheckpointImage to the container status to hold the prepared image name. When it is set, StartContainer passes the image to NewTask, so the task is restored through the normal task and NRI lifecycle, and then deletes the consumed image. RemoveContainer deletes an image that was never consumed, keeping the container until the deletion succeeds so that it can be retried. A daemon restart keeps the reference of an unstarted container. For a started or exited container, loadContainer retries the deletion of the consumed image and keeps the reference until the status update succeeds. Signed-off-by: Radostin Stoyanov <[email protected]>
Implement Restore in the pause controller. CRI creates the destination sandbox and containers first; Restore then prepares each container from the checkpoint. It reads the checkpoint directory with bounded reads that do not follow symlinks, checks that the supplied containers match the saved set, imports each container's OCI archive, checks the checkpoint index and its descriptors, and applies the saved writable layer to the new container's snapshot. It returns the task checkpoint images for the upcoming CRI RestorePod implementation, which saves them for StartContainer. Reject descriptor annotations other than the writable layer's uncompressed digest, so that a checkpoint cannot pass RestoreFromPath or other control input to the task service. Discard the image names stored in the archives and create the only image record under a name derived from the destination sandbox and container. If preparation fails, Restore deletes the images it imported; the caller removes the containers. Decode the saved CRI messages without rejecting unknown fields. They follow the CRI API version containerd was built with, and a field from a newer API cannot be applied to the destination containers either. Signed-off-by: Radostin Stoyanov <[email protected]>
A checkpoint restores process state created under the source Pod's security settings. Restoring it into a Pod with different settings could run the process with credentials, capabilities or a network setup that the destination Pod does not grant. Before importing anything, compare the destination sandbox's Linux security context, sysctls and port mappings, and each container's working directory, TTY setting and Linux security context, with the values saved at checkpoint time. Reject differences with FailedPrecondition. Compare the destination container's image config digest rather than its image reference, so that a tagged image the kubelet pinned to a digest still matches, and require the checkpoint's runtime to match the destination runtime. Command, arguments and environment may differ: they describe the new Pod, while CRIU restores the captured process with its original values. Signed-off-by: Radostin Stoyanov <[email protected]>
Restore imports a checkpoint image for each restored container, and CRI saves the image names only after Restore returns. If containerd stops in between, nothing references the imported images. Label each imported image with its destination container and sandbox. The container back-reference keeps the image only while that container exists, so garbage collection removes it with the container, and sandbox shutdown deletes every image labelled with the sandbox. Signed-off-by: Radostin Stoyanov <[email protected]>
Add the CRI CheckpointPod RPC. It checkpoints selected running containers of a ready sandbox into an output directory, and the source containers keep running. CRI resolves the requested container IDs and passes the sandbox and container configurations and status to the sandbox's CheckpointController. The controller validates the selected containers and owns the checkpoint format. Require a finite request deadline, so that the capture, during which the selected containers are paused, is bounded. The enable_checkpoint_restore setting gates the RPC. Reserve the selected containers across Pod and standalone container checkpoints, which would otherwise share a container's checkpoint scratch state. Signed-off-by: Radostin Stoyanov <[email protected]>
Add the CRI RestorePod RPC. It creates a new sandbox and containers through the normal CRI lifecycle, and asks the sandbox controller to prepare them from a checkpoint written by CheckpointPod. It saves the prepared task checkpoint references and returns the containers in CREATED state, so that StartContainer can restore their processes after pre-start setup. If restore fails, roll back the created resources and the prepared checkpoint images. Check the names and IDs the controller returns before saving any reference. RestorePod does not pull images: the kubelet pulls them with its pull policy and credentials, and a missing image fails with FailedPrecondition before any resources are created. Signed-off-by: Radostin Stoyanov <[email protected]>
RestorePod creates the sandbox and containers, asks the controller to prepare them and only then saves each container's task checkpoint image. If containerd stops in between, the CREATED containers carry no record that they must be restored: StartContainer would run the image entrypoint instead of restoring the process, and nothing removes the partly restored Pod. Save a restore transaction in the sandbox metadata before RunPodSandbox creates the lease, network namespace or pause container, and mark the containers created for the restore as RestorePending. StartContainer rejects a pending container. Saving a container's task checkpoint reference clears RestorePending, and RestorePod commits the transaction once every reference is saved. RunPodSandbox now saves the sandbox record before it creates the sandbox lease, for every sandbox, so the transaction exists before any resource that a rollback must release. When CRI starts, it removes the sandboxes of uncommitted transactions through RemovePodSandbox before it accepts requests, even when checkpoint/restore is disabled. A failed rollback keeps the transaction and stops CRI initialization, so the next start retries it instead of leaving restorable containers behind. Signed-off-by: Radostin Stoyanov <[email protected]>
The unit tests of CheckpointPod and RestorePod replace the runtime with fakes, so they do not show that a Pod survives a real checkpoint and restore. Add CRI integration tests that use the runtime handler of the test run. With runc, a container keeps a random token and a count in shell memory and writes both to a file. The test checkpoints the Pod, checks that the source container keeps running, restores the checkpoint into a new Pod and starts the restored container. A restored process continues with the same token, while a newly started process writes a new one. The test is skipped when CRIU is not installed or the runc flavor is not runc. With runsc, the test checks that the pause-container backend rejects the container with Unimplemented, writes no output and leaves the Pod running. Give each Pod its own cgroup parent, a cgroupfs path or a systemd slice, because the backend freezes the parent during capture. Signed-off-by: Radostin Stoyanov <[email protected]>
Describe the Pod CRI APIs, sandbox-controller capabilities and the built-in runc and CRIU flow, including recovery and trust assumptions. Show the crictl workflow and distinguish the built-in backend from native gVisor and Kata checkpoint mechanisms. Signed-off-by: Radostin Stoyanov <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Critical correctness and contract issues remain: the adapter uses an unbounded context that causes all checkpoint/restore calls to fail, while the CRI entry point lacks required validation for sandbox ownership and non-empty container selections.
4 open issues
Review effort: Lite
| Containers: make([]podCheckpointManifestContainer, 0, len(containers)), | ||
| } | ||
| checkpointImages := make([]string, 0, len(containers)) | ||
| for _, container := range containers { |
There was a problem hiding this comment.
Any reason why we can't dump in parallel here?
There was a problem hiding this comment.
🟡 Changes recommended
Four critical active findings remain: container removal can discard the only recoverable checkpoint, restore compatibility omits mounts and other spec fields, and checkpoint reservations do not synchronize with concurrent lifecycle operations.
4 open issues
4 resolved since last review
Review effort: Lite
| if err := c.client.ImageService().Delete(ctx, image, images.SynchronousDelete()); err != nil && !errdefs.IsNotFound(err) { | ||
| return fmt.Errorf("failed to delete task checkpoint image %q for container %q: %w", image, container.ID, err) | ||
| } | ||
| // Keep the reference for an unstarted container until its metadata is removed. | ||
| // If removal fails, StartContainer must not create a task without restoring it. | ||
| if status.StartedAt == 0 && status.FinishedAt == 0 { | ||
| return nil |
| if !slices.EqualFunc(checkpoint.GetEnvs(), restore.GetEnvs(), func(a, b *runtime.KeyValue) bool { return proto.Equal(a, b) }) { | ||
| return fmt.Errorf("restore environment does not match the checkpointed container: %w", errdefs.ErrFailedPrecondition) | ||
| } | ||
| if checkpoint.GetWorkingDir() != restore.GetWorkingDir() { |
| release, err := c.reserveContainerCheckpoints(containerIDs) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer release() |
| // containerCheckpointsInProgress prevents Pod and standalone container | ||
| // checkpoint calls from sharing a container's checkpoint scratch state. | ||
| containerCheckpointsInProgress sync.Map |
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@rst0git How do you store criu images? The previous format was sub-optimal and introduced undesired overhead: https://lore.kernel.org/criu/[email protected]/T/#t. please review these review comments https://gist.github.com/avagin/e035cd38abf40e110e1b824990980df8 |
|
@rst0git How shared namespaces are handled? Are /dev/shm contents preserved? |


This pull request implements the Pod-level checkpoint and restore CRI RPCs proposed by KEP-5823.
CheckpointPodcoordinates a Pod checkpoint as a single operation, where the Pod cgroup is frozen and all containers in the sandbox are captured at a consistent point in time.RestorePodcreates a sandbox from the savedPodSandboxConfigand per-containerContainerConfigprovided by the caller, it validates that the checkpoint is compatible with the restore request, applies the checkpointed writable layer before restoring the containers.