@@ -288,10 +288,13 @@ func (in *ReconcileStatefulSet) patchStatefulSet(deployment *coh.Coherence, curr
288288 name := current .GetName ()
289289 original , _ := storage .GetPrevious ().GetResource (coh .ResourceTypeStatefulSet , name )
290290
291- // We NEVER change the replicas or Phase in an update.
291+ // We NEVER change the replicas or Status in an update.
292292 // Replicas is handled by scaling so we always set the desired replicas to match the current replicas
293293 desired .Spec .Replicas = current .Spec .Replicas
294+ // We need to ensure we do not create a patch due to differences in StatefulSet Status
294295 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 )
295298
296299 // a callback function that the 3-way patch method will call just before it applies a patch
297300 callback := func () {
@@ -315,6 +318,37 @@ func (in *ReconcileStatefulSet) patchStatefulSet(deployment *coh.Coherence, curr
315318 return patched , err
316319}
317320
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+
318352// Scale will scale a StatefulSet up or down
319353func (in * ReconcileStatefulSet ) scale (deployment * coh.Coherence , sts * appsv1.StatefulSet , current , desired int32 ) (reconcile.Result , error ) {
320354 // 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