@@ -285,16 +285,26 @@ func (in *ReconcileStatefulSet) updateStatefulSet(deployment *coh.Coherence, cur
285
285
// Patch the StatefulSet if required, returning a bool to indicate whether a patch was applied.
286
286
func (in * ReconcileStatefulSet ) patchStatefulSet (deployment * coh.Coherence , current , desired * appsv1.StatefulSet , storage utils.Storage ) (bool , error ) {
287
287
logger := in .GetLog ().WithValues ("Namespace" , deployment .Namespace , "Name" , deployment .Name )
288
- name := current .GetName ()
289
- original , _ := storage .GetPrevious ().GetResource (coh .ResourceTypeStatefulSet , name )
288
+ resource , _ := storage .GetPrevious ().GetResource (coh .ResourceTypeStatefulSet , current .GetName ())
289
+ original := & appsv1.StatefulSet {}
290
+ err := resource .As (original )
291
+ if err != nil {
292
+ return false , err
293
+ }
290
294
291
295
// We NEVER change the replicas or Status in an update.
292
296
// Replicas is handled by scaling so we always set the desired replicas to match the current replicas
293
297
desired .Spec .Replicas = current .Spec .Replicas
298
+ original .Spec .Replicas = current .Spec .Replicas
294
299
// We need to ensure we do not create a patch due to differences in StatefulSet Status
295
- desired .Status = current .Status
296
- // If the StatefulSet has PVs we need to ensure we do not create a patch due to ignorable differences in PV
297
- in .mergeVolumeClaims (desired , current )
300
+ desired .Status = appsv1.StatefulSetStatus {}
301
+ current .Status = appsv1.StatefulSetStatus {}
302
+ original .Status = appsv1.StatefulSetStatus {}
303
+
304
+ // The VolumeClaimTemplates of a StetfulSet cannot be changed so blank them out for the patch
305
+ desired .Spec .VolumeClaimTemplates = []corev1.PersistentVolumeClaim {}
306
+ current .Spec .VolumeClaimTemplates = []corev1.PersistentVolumeClaim {}
307
+ original .Spec .VolumeClaimTemplates = []corev1.PersistentVolumeClaim {}
298
308
299
309
// a callback function that the 3-way patch method will call just before it applies a patch
300
310
callback := func () {
@@ -304,7 +314,7 @@ func (in *ReconcileStatefulSet) patchStatefulSet(deployment *coh.Coherence, curr
304
314
}
305
315
}
306
316
307
- patched , err := in .ThreeWayPatchWithCallback (name , current , original . Spec , desired , callback )
317
+ patched , err := in .ThreeWayPatchWithCallback (current . GetName () , current , original , desired , callback )
308
318
// log the result of patching
309
319
switch {
310
320
case err != nil :
@@ -318,37 +328,6 @@ func (in *ReconcileStatefulSet) patchStatefulSet(deployment *coh.Coherence, curr
318
328
return patched , err
319
329
}
320
330
321
- // If the desired StatefulSet has PVs update the desired PV to avid needless merges
322
- func (in * ReconcileStatefulSet ) mergeVolumeClaims (desired , current * appsv1.StatefulSet ) {
323
- if len (desired .Spec .VolumeClaimTemplates ) == 0 {
324
- return
325
- }
326
-
327
- // Make a map of current PVs by name
328
- m := make (map [string ]corev1.PersistentVolumeClaim )
329
- for _ , pv := range current .Spec .VolumeClaimTemplates {
330
- m [pv .Name ] = pv
331
- }
332
-
333
- dfltVolumeMode := corev1 .PersistentVolumeFilesystem
334
-
335
- for i , pv := range desired .Spec .VolumeClaimTemplates {
336
- currentPV , found := m [pv .Name ]
337
- if found {
338
- // Update the desired PV statuses
339
- pv .Status = currentPV .Status
340
-
341
- // Set the desired volume mode to the default if it is not set
342
- if pv .Spec .VolumeMode == nil {
343
- pv .Spec .VolumeMode = & dfltVolumeMode
344
- }
345
-
346
- // set the updated PV back into the desired array
347
- desired .Spec .VolumeClaimTemplates [i ] = pv
348
- }
349
- }
350
- }
351
-
352
331
// Scale will scale a StatefulSet up or down
353
332
func (in * ReconcileStatefulSet ) scale (deployment * coh.Coherence , sts * appsv1.StatefulSet , current , desired int32 ) (reconcile.Result , error ) {
354
333
// if the StatefulSet is not stable we cannot scale (e.g. it might already be in the middle of a rolling upgrade)
0 commit comments