Skip to content

Commit db08dcd

Browse files
authored
fix: move VCT logic before diff calculation for stateful set (#1322)
fixes #1321 Signed-off-by: Mikolaj Pawlikowski <mikolaj@pawlikowski.pl>
1 parent 5ea1410 commit db08dcd

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

pkg/k8sutils/statefulset.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ func patchStatefulSet(ctx context.Context, storedStateful, newStateful *appsv1.S
185185
// Sync system-managed fields to ensure atomic update.
186186
syncManagedFields(storedStateful, newStateful)
187187

188+
// Save the new VolumeClaimTemplates for later use in HandlePVCResizing
189+
newStatefulCopy := newStateful.DeepCopy()
190+
191+
// Since VolumeClaimTemplate fields are immutable, revert to the stored configuration.
192+
if hasVolumeClaimTemplates(newStateful, storedStateful) {
193+
if newStateful.Annotations == nil {
194+
newStateful.Annotations = make(map[string]string)
195+
}
196+
newStateful.Annotations["storageCapacity"] = storedStateful.Annotations["storageCapacity"]
197+
newStateful.Spec.VolumeClaimTemplates = storedStateful.Spec.VolumeClaimTemplates
198+
}
199+
188200
// Calculate the patch between the stored and new objects, ignoring immutable or unnecessary fields.
189201
patchResult, err := patch.DefaultPatchMaker.Calculate(storedStateful, newStateful,
190202
patch.IgnoreStatusFields(),
@@ -206,15 +218,9 @@ func patchStatefulSet(ctx context.Context, storedStateful, newStateful *appsv1.S
206218

207219
// If VolumeClaimTemplates exist, handle PVC resizing.
208220
if hasVolumeClaimTemplates(newStateful, storedStateful) {
209-
if err := HandlePVCResizing(ctx, storedStateful, newStateful, cl); err != nil {
221+
if err := HandlePVCResizing(ctx, storedStateful, newStatefulCopy, cl); err != nil {
210222
return err
211223
}
212-
// Since VolumeClaimTemplate fields are immutable, revert to the stored configuration.
213-
if newStateful.Annotations == nil {
214-
newStateful.Annotations = make(map[string]string)
215-
}
216-
newStateful.Annotations["storageCapacity"] = storedStateful.Annotations["storageCapacity"]
217-
newStateful.Spec.VolumeClaimTemplates = storedStateful.Spec.VolumeClaimTemplates
218224
}
219225

220226
// Merge missing annotations from the stored object into the new object.

0 commit comments

Comments
 (0)