From 01eae1fe3db9debf6813070dbc986f74af5c6a26 Mon Sep 17 00:00:00 2001 From: Siyu Wang Date: Tue, 18 Jan 2022 13:57:37 +0800 Subject: [PATCH] CloneSet refresh pod states before skipping update when paused (#893) --- .../cloneset/sync/cloneset_update.go | 8 +++---- test/e2e/apps/cloneset.go | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pkg/controller/cloneset/sync/cloneset_update.go b/pkg/controller/cloneset/sync/cloneset_update.go index 179baf1750..6a28d16236 100644 --- a/pkg/controller/cloneset/sync/cloneset_update.go +++ b/pkg/controller/cloneset/sync/cloneset_update.go @@ -48,10 +48,6 @@ func (c *realControl) Update(cs *appsv1alpha1.CloneSet, requeueDuration := requeueduration.Duration{} coreControl := clonesetcore.New(cs) - if cs.Spec.UpdateStrategy.Paused { - return requeueDuration.Get(), nil - } - // 1. refresh states for all pods var modified bool for _, pod := range pods { @@ -69,6 +65,10 @@ func (c *realControl) Update(cs *appsv1alpha1.CloneSet, return requeueDuration.Get(), nil } + if cs.Spec.UpdateStrategy.Paused { + return requeueDuration.Get(), nil + } + // 2. calculate update diff and the revision to update diffRes := calculateDiffsWithExpectation(cs, pods, currentRevision.Name, updateRevision.Name) if diffRes.updateNum == 0 { diff --git a/test/e2e/apps/cloneset.go b/test/e2e/apps/cloneset.go index 46f726a526..489f758bb4 100644 --- a/test/e2e/apps/cloneset.go +++ b/test/e2e/apps/cloneset.go @@ -111,6 +111,29 @@ var _ = SIGDescribe("CloneSet", func() { gomega.Expect(pods[i].CreationTimestamp.Sub(lastPodCondition.LastTransitionTime.Time) <= time.Duration(cs.Spec.MinReadySeconds)*time.Second+allowFluctuation).To(gomega.BeTrue()) } }) + + ginkgo.It("pods should be ready when paused=true", func() { + cs := tester.NewCloneSet("clone-"+randStr, 3, appsv1alpha1.CloneSetUpdateStrategy{ + Type: appsv1alpha1.RecreateCloneSetUpdateStrategyType, + Paused: true, + }) + cs, err = tester.CreateCloneSet(cs) + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + + ginkgo.By("Wait for replicas satisfied") + gomega.Eventually(func() int32 { + cs, err = tester.GetCloneSet(cs.Name) + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + return cs.Status.Replicas + }, 3*time.Second, time.Second).Should(gomega.Equal(int32(3))) + + ginkgo.By("Wait for all pods ready") + gomega.Eventually(func() int32 { + cs, err = tester.GetCloneSet(cs.Name) + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + return cs.Status.ReadyReplicas + }, 120*time.Second, 3*time.Second).Should(gomega.Equal(int32(3))) + }) }) framework.KruiseDescribe("CloneSet Updating", func() {