Skip to content

feat(sandbox): add CheckpointRestore upgrade strategy with UpgradeControl#670

Merged
furykerry merged 5 commits into
openkruise:masterfrom
zmberg:sandboxupdateops-checkpoint
Jul 20, 2026
Merged

feat(sandbox): add CheckpointRestore upgrade strategy with UpgradeControl#670
furykerry merged 5 commits into
openkruise:masterfrom
zmberg:sandboxupdateops-checkpoint

Conversation

@zmberg

@zmberg zmberg commented Jul 20, 2026

Copy link
Copy Markdown
Member

Summary

This PR implements the CheckpointRestore upgrade strategy for Sandboxes, enabling zero-downtime upgrades by checkpointing the sandbox writable layer before pod recreation and restoring it afterward.

Key Changes

New: UpgradeControl state machine (upgrade_control.go)

  • Extracted upgrade logic from commonControl into a dedicated UpgradeControl struct
  • State machine flow: PreUpgrade → Checkpointing → UpgradePod → PostUpgrade → Succeeded
  • Checkpointing state uses fallthrough to seamlessly transition to UpgradePod once checkpoint completes

API changes

  • Added CheckpointRestore upgrade policy type to Sandbox and SandboxUpdateOps CRDs
  • Added CheckpointTypePodInfo checkpoint type label for upgrade-specific checkpoints
  • Generated CRD manifests updated

CheckpointControl enhancements (checkpoint.go)

  • EnsureCheckpointForUpgrade: creates a Checkpoint CR for the sandbox being upgraded
  • GetCheckpointIDForUpgrade: retrieves the checkpoint ID from the latest completed checkpoint
  • CleanupForUpgrade: cleans up checkpoint resources after upgrade completes
  • listCheckpointsForSandbox: filters out Checkpoints with non-nil DeletionTimestamp to avoid using stale checkpoints being deleted

Configurable checkpoint annotation key

  • Removed hardcoded AnnotationCheckpointID constant from annotations.go
  • Added --checkpoint-id-annotation-key controller flag; when empty, no checkpoint ID annotation is written to pods
  • PodControl.CreatePod guards against empty key/ID before writing annotation

SandboxUpdateOps integration (patch.go)

  • Updated to support the new CheckpointRestore upgrade policy

Test Coverage

  • Added 2 test cases for DeletionTimestamp filtering in TestListCheckpointsForSandbox
  • Added TestCreatePodCheckpointAnnotation with 4 cases covering annotation key configuration behavior
  • Updated existing upgrade tests in common_control_test.go and upgrade_control_test.go

Review Guidance

  • Focus review on upgrade_control.go state machine logic, especially the fallthrough from Checkpointing to UpgradePod
  • Verify listCheckpointsForSandbox DeletionTimestamp filtering is correct
  • Check that the configurable annotation key properly handles empty/default cases

…trol

- Extract upgrade state machine from commonControl into UpgradeControl struct
  (PreUpgrade → Checkpointing → UpgradePod → PostUpgrade → Succeeded)
- Add CheckpointRestore upgrade policy type to Sandbox and SandboxUpdateOps CRDs
- Add EnsureCheckpointForUpgrade, GetCheckpointIDForUpgrade, CleanupForUpgrade
  methods to CheckpointControl for upgrade-specific checkpoint operations
- Filter out Checkpoints with DeletionTimestamp in listCheckpointsForSandbox
  to avoid using stale checkpoints being deleted
- Make checkpoint ID annotation key configurable via --checkpoint-id-annotation-key
  controller flag; remove hardcoded AnnotationCheckpointID constant
- Add unit tests for DeletionTimestamp filtering and annotation key behavior

Signed-off-by: liheng <liheng.zms@alibaba-inc.com>
@kruise-bot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from zmberg by writing /assign @zmberg in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Move CleanupForUpgrade from performRecreateUpgrade (UpgradePod phase)
to after PostUpgrade succeeds. This ensures checkpoint CRs are retained
for debugging if PostUpgrade fails and needs retry.

Signed-off-by: liheng <liheng.zms@alibaba-inc.com>
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.20388% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.34%. Comparing base (bc355be) to head (af87800).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
pkg/controller/sandbox/core/upgrade_control.go 92.46% 10 Missing and 5 partials ⚠️
...xupdateops/validating/sandboxupdateops_validate.go 78.57% 1 Missing and 2 partials ⚠️
pkg/controller/sandboxupdateops/patch.go 50.00% 1 Missing and 1 partial ⚠️
pkg/controller/sandbox/sandbox_controller.go 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #670      +/-   ##
==========================================
+ Coverage   80.06%   80.34%   +0.27%     
==========================================
  Files         229      231       +2     
  Lines       17862    18057     +195     
==========================================
+ Hits        14302    14507     +205     
+ Misses       2975     2963      -12     
- Partials      585      587       +2     
Flag Coverage Δ
unittests 80.34% <93.20%> (+0.27%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

zmberg added 2 commits July 20, 2026 14:42
Add comprehensive unit tests for upgrade_control.go and checkpoint.go:
- TestEnsureCheckpointForUpgrade: 6 cases covering create/wait/succeed/fail/error paths
- TestGetCheckpointIDForUpgrade: 4 cases covering with/without ID, no CPs, list error
- TestCleanupForUpgrade: 4 cases covering delete all, no-op, list/delete errors
- TestEnsureSandboxUpgraded_CheckpointRestore: 5 cases covering full CheckpointRestore lifecycle
- TestPerformRecreateUpgrade_ContainerStatuses: 4 cases covering Waiting/Terminated/PodInitializing/ContainerCreating
- TestPerformRecreateUpgrade_CheckpointRestore_CreatePod: verifies checkpoint ID is used during pod creation
- TestExecuteUpgradeAction_NilAction/NilPod: covers nil action and nil pod defensive paths
- TestHasUpgradeAction: 7 cases covering all lifecycle/action combinations

Coverage improvement:
- checkpoint.go new functions: 0% -> 100%
- EnsureSandboxUpgraded: 70.2% -> 95.2%
- performRecreateUpgrade: 61.5% -> 88.5%
- executeUpgradeAction: 91.7% -> 100%
- hasUpgradeAction: 88.9% -> 100%
- Overall core package: 87.7% -> 95.2%

Signed-off-by: liheng <liheng.zms@alibaba-inc.com>
Signed-off-by: liheng <liheng.zms@alibaba-inc.com>
@kruise-bot

Copy link
Copy Markdown

@zmberg: you cannot LGTM your own PR.

Details

In response to this:

/lgtm

Instructions 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/test-infra repository.

Comment thread pkg/controller/sandbox/core/upgrade_control.go Outdated
Comment thread pkg/controller/sandbox/core/common_control.go
Comment thread pkg/controller/sandbox/core/upgrade_control.go Outdated
…immutability validation

- Fix CheckpointRestore strategy to enter full upgrade lifecycle (PreUpgrade ->
  Checkpointing -> UpgradePod -> PostUpgrade) by extending upgrade trigger
  condition and inplace update guard in sandbox_controller and common_control
- Abstract RequiresPodReplacementUpgrade helper to deduplicate Recreate ||
  CheckpointRestore condition check across packages
- Propagate checkpoint CR name through createCheckpoint and
  EnsureCheckpointForUpgrade return values, surface it in upgrade condition
  message and klog for better observability
- Add validating webhook to reject container image changes in patch when
  UpdateStrategy.Type is CheckpointRestore (checkpoint restore requires image
  immutability)

Signed-off-by: liheng <liheng.zms@alibaba-inc.com>
@furykerry
furykerry merged commit 489c727 into openkruise:master Jul 20, 2026
21 of 22 checks passed
@zmberg
zmberg deleted the sandboxupdateops-checkpoint branch July 20, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants