From dac56641a302c200f803cdd6b274f4d44d0848c0 Mon Sep 17 00:00:00 2001 From: wu8685 Date: Tue, 29 Oct 2024 10:31:32 +0800 Subject: [PATCH 1/4] add pod label to indicate PodOpsLifecycle phase --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index fee566ce..5d7750e1 100644 --- a/go.mod +++ b/go.mod @@ -94,7 +94,7 @@ require ( k8s.io/apiserver v0.22.6 // indirect k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect k8s.io/kubectl v0.29.0 - kusionstack.io/kube-api v0.6.3 + kusionstack.io/kube-api v0.6.4 sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/go.sum b/go.sum index 5fd95e01..08e40eff 100644 --- a/go.sum +++ b/go.sum @@ -1139,8 +1139,8 @@ k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/ k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -kusionstack.io/kube-api v0.6.3 h1:HKgB6E95DVRGkZ2OjXkuV4YE327gGt24sBFJRB+tc6A= -kusionstack.io/kube-api v0.6.3/go.mod h1:J0+EHiroG/88X904Y9TV9iMRcoEuD5tXMTLMBDSwM+Y= +kusionstack.io/kube-api v0.6.4 h1:w/O+XJXt4MrcRNCnNgt5Da1PXFqldEEU0T1pO8OOb7o= +kusionstack.io/kube-api v0.6.4/go.mod h1:fYwuojoLs71ox8uyvyKNsJU4CtPtptSfJ3PUSt/3Hgg= kusionstack.io/resourceconsist v0.0.1 h1:+k/jriq5Ld7fQUYfWSMGynz/FesHtl3Rk2fmQPjBe0g= kusionstack.io/resourceconsist v0.0.1/go.mod h1:816xS/fY6EOUbPFjXIWW/TGs8/YE46qP4ElKeIiwFdU= modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw= From f1958121bd555812e023ca15c130ceb23de35162 Mon Sep 17 00:00:00 2001 From: wu8685 Date: Tue, 29 Oct 2024 11:33:45 +0800 Subject: [PATCH 2/4] add UT --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5d7750e1..fee566ce 100644 --- a/go.mod +++ b/go.mod @@ -94,7 +94,7 @@ require ( k8s.io/apiserver v0.22.6 // indirect k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect k8s.io/kubectl v0.29.0 - kusionstack.io/kube-api v0.6.4 + kusionstack.io/kube-api v0.6.3 sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/go.sum b/go.sum index 08e40eff..5fd95e01 100644 --- a/go.sum +++ b/go.sum @@ -1139,8 +1139,8 @@ k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/ k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -kusionstack.io/kube-api v0.6.4 h1:w/O+XJXt4MrcRNCnNgt5Da1PXFqldEEU0T1pO8OOb7o= -kusionstack.io/kube-api v0.6.4/go.mod h1:fYwuojoLs71ox8uyvyKNsJU4CtPtptSfJ3PUSt/3Hgg= +kusionstack.io/kube-api v0.6.3 h1:HKgB6E95DVRGkZ2OjXkuV4YE327gGt24sBFJRB+tc6A= +kusionstack.io/kube-api v0.6.3/go.mod h1:J0+EHiroG/88X904Y9TV9iMRcoEuD5tXMTLMBDSwM+Y= kusionstack.io/resourceconsist v0.0.1 h1:+k/jriq5Ld7fQUYfWSMGynz/FesHtl3Rk2fmQPjBe0g= kusionstack.io/resourceconsist v0.0.1/go.mod h1:816xS/fY6EOUbPFjXIWW/TGs8/YE46qP4ElKeIiwFdU= modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw= From ea5c565f6443d45d05d68cde39ff1989cc981f85 Mon Sep 17 00:00:00 2001 From: wu8685 Date: Tue, 29 Oct 2024 23:57:39 +0800 Subject: [PATCH 3/4] add creating label when replacing pod created --- pkg/controllers/collaset/synccontrol/replace.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/controllers/collaset/synccontrol/replace.go b/pkg/controllers/collaset/synccontrol/replace.go index 2cf9432b..9c9ea05e 100644 --- a/pkg/controllers/collaset/synccontrol/replace.go +++ b/pkg/controllers/collaset/synccontrol/replace.go @@ -154,6 +154,7 @@ func (r *RealSyncControl) replaceOriginPods( ownedIDs[newPodId].Remove(podcontext.JustCreateContextDataKey) } newPod.Labels[appsv1alpha1.PodReplacePairOriginName] = originPod.GetName() + newPod.Labels[appsv1alpha1.PodCreatingLabel] = strconv.FormatInt(time.Now().UnixNano(), 10) newPodContext.Put(podcontext.RevisionContextDataKey, replaceRevision.Name) // create pvcs for new pod err = r.pvcControl.CreatePodPvcs(ctx, instance, newPod, resources.ExistingPvcs) From 7684946e66c5ec9a322985e8700bb16ca55a88ab Mon Sep 17 00:00:00 2001 From: wu8685 Date: Wed, 30 Oct 2024 00:07:57 +0800 Subject: [PATCH 4/4] add UT --- .../collaset/collaset_controller_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/controllers/collaset/collaset_controller_test.go b/pkg/controllers/collaset/collaset_controller_test.go index f9a4bff0..dc4bd92d 100644 --- a/pkg/controllers/collaset/collaset_controller_test.go +++ b/pkg/controllers/collaset/collaset_controller_test.go @@ -130,6 +130,19 @@ var _ = Describe("collaset controller", func() { return expectedStatusReplicas(c, cs, 0, 0, 0, 2, 2, 0, 0, 0) }, 5*time.Second, 1*time.Second).Should(BeNil()) + Eventually(func() bool { + Expect(c.List(context.TODO(), podList, client.InNamespace(cs.Namespace))).Should(BeNil()) + return len(podList.Items) == 2 + }, 5*time.Second, 1*time.Second).Should(BeTrue()) + + for _, pod := range podList.Items { + if pod.Name == originPodName { + continue + } + + Expect(pod.Labels[appsv1alpha1.PodCreatingLabel]).ShouldNot(BeEquivalentTo("")) + } + // update collaset with recreate update observedGeneration := cs.Status.ObservedGeneration Expect(updateCollaSetWithRetry(c, cs.Namespace, cs.Name, func(cls *appsv1alpha1.CollaSet) bool {