Skip to content

allow adding/removing VCTs for StatefulSet with OnPodRollingUpdate #2043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ninavdl
Copy link

@ninavdl ninavdl commented May 19, 2025

Ⅰ. Describe what this PR does

Currently, when OnPodRollingUpdate is enabled, as per https://openkruise.io/docs/user-manuals/advancedstatefulset#validation-rules-onpodrollingupdate-mode it is not supported to add/remove volumeClaimTemplates to an existing Advanced StatefulSet.

This PR adds a feature flag RecreatePodWhenChangeVCTInStatefulSetGate (similar to the already existing RecreatePodWhenChangeVCTInCloneSetGate), with which VCTs can be added to an existing StatefulSet with OnPodRollingUpdate. Adding/removing a VCT then causes the Pods to be recreated.

Ⅱ. Does this pull request fix one issue?

NONE

Ⅲ. Describe how to verify it

  • Create StatefulSet with OnPodRollingUpdate
  • After reconciliation, add or remove a VCT to the StatefulSet and mount it in a Pod template
  • Observe that the Pod is recreated with the new VCT.

Ⅳ. Special notes for reviews

@kruise-bot kruise-bot requested review from shiyan2016 and zmberg May 19, 2025 09:43
@kruise-bot
Copy link

[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 assign veophi for approval by writing /assign @veophi 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.

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

@kruise-bot
Copy link

Welcome @ninavdl! It looks like this is your first PR to openkruise/kruise 🎉

@kruise-bot kruise-bot added the size/L size/L: 100-499 label May 19, 2025
@ABNER-1 ABNER-1 self-requested a review May 19, 2025 09:50
@ninavdl ninavdl force-pushed the feature/recreate-pod-statefulset-vct-change branch from 9f1b0df to 10ab9e8 Compare May 19, 2025 09:50
…tatefulSet with OnPodRollingUpdate changes

Signed-off-by: Nina van der Linden <[email protected]>
@ninavdl ninavdl force-pushed the feature/recreate-pod-statefulset-vct-change branch from 10ab9e8 to 04f73b9 Compare May 19, 2025 09:57
Copy link

codecov bot commented May 19, 2025

Codecov Report

Attention: Patch coverage is 87.23404% with 6 lines in your changes missing coverage. Please review.

Project coverage is 43.90%. Comparing base (4025f61) to head (e85fa5b).
Report is 20 commits behind head on master.

Files with missing lines Patch % Lines
pkg/controller/statefulset/stateful_set_control.go 57.14% 2 Missing and 1 partial ⚠️
...oller/statefulset/statefulset_predownload_image.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2043      +/-   ##
==========================================
+ Coverage   43.77%   43.90%   +0.12%     
==========================================
  Files         316      316              
  Lines       31615    31670      +55     
==========================================
+ Hits        13841    13906      +65     
+ Misses      16373    16368       -5     
+ Partials     1401     1396       -5     
Flag Coverage Δ
unittests 43.90% <87.23%> (+0.12%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

@ninavdl ninavdl force-pushed the feature/recreate-pod-statefulset-vct-change branch from e7fed35 to f2e9155 Compare May 19, 2025 11:46
@ninavdl ninavdl force-pushed the feature/recreate-pod-statefulset-vct-change branch from f2e9155 to ea2a91d Compare May 19, 2025 11:54
@ABNER-1
Copy link
Member

ABNER-1 commented May 28, 2025

Hi, @ninavdl.
Thank you for contributing this feature.
I'll review it as soon as possible.

Copy link
Member

@ABNER-1 ABNER-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @ninavdl .
Great job! Your contribution is highly appreciated.
Here are some suggestions to make it even better.

if !canInPlace {
return nil
}
if opts.RecreatePodWhenChangedVolumeClaimTemplate && !opts.IgnoreVolumeClaimTemplatesHashDiff {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it necessary to make this change? It doesn't seem essential.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The hash is only recorded for the CloneSet.
  2. When adding or removing VCTs in a StatefulSet, users may need to add or remove corresponding volume mounts. This implies that the Pod cannot be updated in place.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opts.RecreatePodWhenChangedVolumeClaimTemplate is true if the feature gate RecreatePodWhenChangeVCTInCloneSetGate or RecreatePodWhenChangeVCTInStatefulSetGate is enabled

@@ -918,6 +918,110 @@ var _ = SIGDescribe("AppStatefulSetStorage", func() {
sst.WaitForStatusPVCReadyReplicas(ss, 1)
})
})

ginkgo.Describe("Recreate Pod when modifying volumeClaimTemplate with OnPodRollingUpdate", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add cases about sts withInPlaceUpdateReady.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a case about rename volume name in vcts and volumeMounts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a case for renaming VCTs.
What do you mean by sts withInPlaceUpdateReady?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sry.
By default, the StatefulSets created by NewStatefulSet use the Recreate update strategy.
We should add test cases to cover all scenarios (adding, removing, and renaming) for StatefulSets with InPlaceIfPossiblePodUpdateStrategyType update strategy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may refer to

injectSC := func(podUpdatePolicy appsv1beta1.PodUpdateStrategyType, ss *appsv1beta1.StatefulSet, volumeClaimUpdateStrategy appsv1beta1.VolumeClaimUpdateStrategyType, scNames ...string) {
if podUpdatePolicy == appsv1beta1.InPlaceIfPossiblePodUpdateStrategyType {
ss.Spec.UpdateStrategy.RollingUpdate = &appsv1beta1.RollingUpdateStatefulSetStrategy{
PodUpdatePolicy: podUpdatePolicy,
}
ss.Spec.Template.Spec.ReadinessGates = append(ss.Spec.Template.Spec.ReadinessGates, v1.PodReadinessGate{ConditionType: appspub.InPlaceUpdateReady})
}

@ABNER-1
Copy link
Member

ABNER-1 commented Jun 3, 2025

Please add a TODO item near UpdatePodClaimForRetentionPolicy to address the removal of PVCs when users delete VCTs.

@ABNER-1
Copy link
Member

ABNER-1 commented Jun 3, 2025

Please add a TODO item near UpdatePodClaimForRetentionPolicy to address the removal of PVCs when users delete VCTs.

Perhaps we can add a label to help users identify these PVCs.
If we do not recommend deletion during the update process due to the possibility of rollback, this label can allow users to manually clean up PVCs that are no longer referenced by any Pod after a certain period.

@ABNER-1 ABNER-1 self-assigned this Jun 4, 2025
Nina van der Linden added 2 commits June 16, 2025 13:43
Signed-off-by: Nina van der Linden <[email protected]>
Signed-off-by: Nina van der Linden <[email protected]>
@ninavdl ninavdl force-pushed the feature/recreate-pod-statefulset-vct-change branch from 45518a9 to e85fa5b Compare June 16, 2025 11:43
Copy link
Member

@furykerry furykerry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ninavdl this patch only ensure the pod is recreated if VCT of statefulset changes, but it does not address the problem of changing existing PVC. currently PVC is only deleted when statefulset scale down or statefulset itself get deleted. So we may have to add another PersistentVolumeClaimRetentionPolicyType to make the patch really work

@@ -377,7 +379,8 @@ func ValidateVolumeClaimTemplateUpdate(c client.Client, sts, oldSts *appsv1beta1
sts.Spec.VolumeClaimUpdateStrategy.Type == appsv1beta1.OnPVCDeleteVolumeClaimUpdateStrategyType {
return nil
}
if len(sts.Spec.VolumeClaimTemplates) != len(oldSts.Spec.VolumeClaimTemplates) {
if len(sts.Spec.VolumeClaimTemplates) != len(oldSts.Spec.VolumeClaimTemplates) &&
!utilfeature.DefaultFeatureGate.Enabled(features.RecreatePodWhenChangeVCTInStatefulSetGate) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can check against the feature gate features.RecreatePodWhenChangeVCTInStatefulSetGate and return nil early in L379

@kruise-bot
Copy link

@ninavdl: PR needs rebase.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase size/L size/L: 100-499
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants