@@ -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