From 0e2b901762f1dff2a0e532574c3a8f8e0d4c7f34 Mon Sep 17 00:00:00 2001 From: Matthew Cary Date: Mon, 22 Nov 2021 19:20:57 -0800 Subject: [PATCH] Clean up deep copy needed for UpdateStatefulSet Change-Id: Id732358183d682d1a945cfee56f83bcaac0d7c31 --- pkg/controller/statefulset/stateful_set.go | 3 +-- pkg/controller/statefulset/stateful_set_control.go | 2 ++ pkg/controller/statefulset/stateful_set_control_test.go | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/controller/statefulset/stateful_set.go b/pkg/controller/statefulset/stateful_set.go index 6c1d1ee7fac..57da437f897 100644 --- a/pkg/controller/statefulset/stateful_set.go +++ b/pkg/controller/statefulset/stateful_set.go @@ -472,8 +472,7 @@ func (ssc *StatefulSetController) syncStatefulSet(ctx context.Context, set *apps klog.V(4).Infof("Syncing StatefulSet %v/%v with %d pods", set.Namespace, set.Name, len(pods)) var status *apps.StatefulSetStatus var err error - // TODO: investigate where we mutate the set during the update as it is not obvious. - status, err = ssc.control.UpdateStatefulSet(ctx, set.DeepCopy(), pods) + status, err = ssc.control.UpdateStatefulSet(ctx, set, pods) if err != nil { return err } diff --git a/pkg/controller/statefulset/stateful_set_control.go b/pkg/controller/statefulset/stateful_set_control.go index a353e86bae0..63a924d6a09 100644 --- a/pkg/controller/statefulset/stateful_set_control.go +++ b/pkg/controller/statefulset/stateful_set_control.go @@ -75,6 +75,8 @@ type defaultStatefulSetControl struct { // in no particular order. Clients using the burst strategy should be careful to ensure they // understand the consistency implications of having unpredictable numbers of pods available. func (ssc *defaultStatefulSetControl) UpdateStatefulSet(ctx context.Context, set *apps.StatefulSet, pods []*v1.Pod) (*apps.StatefulSetStatus, error) { + set = set.DeepCopy() // set is modified when a new revision is created in performUpdate. Make a copy now to avoid mutation errors. + // list all revisions and sort them revisions, err := ssc.ListRevisions(set) if err != nil { diff --git a/pkg/controller/statefulset/stateful_set_control_test.go b/pkg/controller/statefulset/stateful_set_control_test.go index f9d65e6da8a..9b56c7cb0cd 100644 --- a/pkg/controller/statefulset/stateful_set_control_test.go +++ b/pkg/controller/statefulset/stateful_set_control_test.go @@ -2326,7 +2326,6 @@ func scaleUpStatefulSetControl(set *apps.StatefulSet, if err := invariants(set, om); err != nil { return err } - //fmt.Printf("Ravig pod conditions %v %v", set.Status.ReadyReplicas, *set.Spec.Replicas) } return invariants(set, om) }