From d18352f6b7a494bd3c5079cfd79ab4c1010180c4 Mon Sep 17 00:00:00 2001 From: ztonny Date: Wed, 3 Sep 2025 12:42:12 +0800 Subject: [PATCH 1/3] [Enhancement] #425 if the statefulset needs to create rather than update, return the CreateClientObject() before equal() --- pkg/common/utils/k8s/client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/common/utils/k8s/client.go b/pkg/common/utils/k8s/client.go index ecd40b20..174fc346 100644 --- a/pkg/common/utils/k8s/client.go +++ b/pkg/common/utils/k8s/client.go @@ -99,9 +99,6 @@ func ApplyStatefulSet(ctx context.Context, k8sclient client.Client, st *appv1.St return err } - //check the statefulset need update or not. - ev := equal(st, &est) - // apply pre-processing before create statefulset for _, pasf := range pasfs { pasf(st, nil) @@ -111,6 +108,9 @@ func ApplyStatefulSet(ctx context.Context, k8sclient client.Client, st *appv1.St return CreateClientObject(ctx, k8sclient, st) } + //check the statefulset need update or not. + ev := equal(st, &est) + //if have restart annotation we should exclude it impacts on hash. if ev { klog.Infof("ApplyStatefulSet Sync exist statefulset name=%s, namespace=%s, equals to new statefulset.", est.Name, est.Namespace) From b342fb69c195466a40ad32c06e5bb3885610ca24 Mon Sep 17 00:00:00 2001 From: ztonny Date: Wed, 3 Sep 2025 17:16:14 +0800 Subject: [PATCH 2/3] Revert "[Enhancement] #425" This reverts commit d18352f6b7a494bd3c5079cfd79ab4c1010180c4. --- pkg/common/utils/k8s/client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/common/utils/k8s/client.go b/pkg/common/utils/k8s/client.go index 174fc346..ecd40b20 100644 --- a/pkg/common/utils/k8s/client.go +++ b/pkg/common/utils/k8s/client.go @@ -99,6 +99,9 @@ func ApplyStatefulSet(ctx context.Context, k8sclient client.Client, st *appv1.St return err } + //check the statefulset need update or not. + ev := equal(st, &est) + // apply pre-processing before create statefulset for _, pasf := range pasfs { pasf(st, nil) @@ -108,9 +111,6 @@ func ApplyStatefulSet(ctx context.Context, k8sclient client.Client, st *appv1.St return CreateClientObject(ctx, k8sclient, st) } - //check the statefulset need update or not. - ev := equal(st, &est) - //if have restart annotation we should exclude it impacts on hash. if ev { klog.Infof("ApplyStatefulSet Sync exist statefulset name=%s, namespace=%s, equals to new statefulset.", est.Name, est.Namespace) From c7b125a6adea337743948fa456b5408471a386ad Mon Sep 17 00:00:00 2001 From: ztonny Date: Wed, 3 Sep 2025 17:25:27 +0800 Subject: [PATCH 3/3] [Bug] fix issue #427 fix Test_ApplyStatefulSet UT testcase; --- pkg/common/utils/k8s/client_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/common/utils/k8s/client_test.go b/pkg/common/utils/k8s/client_test.go index ab62cbd4..284f3cc0 100644 --- a/pkg/common/utils/k8s/client_test.go +++ b/pkg/common/utils/k8s/client_test.go @@ -18,6 +18,8 @@ package k8s import ( "context" + "testing" + "github.com/FoundationDB/fdb-kubernetes-operator/api/v1beta2" "github.com/apache/doris-operator/pkg/common/utils/resource" appv1 "k8s.io/api/apps/v1" @@ -28,7 +30,6 @@ import ( "k8s.io/utils/pointer" client "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - "testing" ) func Test_ApplyService(t *testing.T) { @@ -95,14 +96,18 @@ func Test_ApplyStatefulSet(t *testing.T) { fakeClient := fake.NewClientBuilder().WithObjects(svcs...).Build() tsts := []*appv1.StatefulSet{ - &appv1.StatefulSet{ + { ObjectMeta: metav1.ObjectMeta{ Name: "testnoexist", Namespace: "test", }, - Spec: appv1.StatefulSetSpec{}, + Spec: appv1.StatefulSetSpec{ + Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"namespace": "test", "name": "testnoexist"}}, + Replicas: pointer.Int32(1), + Template: corev1.PodTemplateSpec{Spec: corev1.PodSpec{Containers: []corev1.Container{{Name: "fe", Image: "test"}}}}, + }, }, - &appv1.StatefulSet{ + { ObjectMeta: metav1.ObjectMeta{ Name: "test2", Namespace: "test",