From 7bb8896cc97aa484c5ff87d4634b3ae391a87455 Mon Sep 17 00:00:00 2001 From: free6om Date: Mon, 15 Apr 2024 19:43:48 +0800 Subject: [PATCH] fix: reconfigure not working (#7056) --- pkg/controller/rsm2/in_place_update_util.go | 13 +++++++-- .../rsm2/in_place_update_util_test.go | 12 ++++++++- pkg/controller/rsm2/instance_util_test.go | 27 ------------------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/pkg/controller/rsm2/in_place_update_util.go b/pkg/controller/rsm2/in_place_update_util.go index 6eaf867eb64..b759a1c5bbd 100644 --- a/pkg/controller/rsm2/in_place_update_util.go +++ b/pkg/controller/rsm2/in_place_update_util.go @@ -61,13 +61,22 @@ func supportPodVerticalScaling() bool { func filterInPlaceFields(src *corev1.PodTemplateSpec) *corev1.PodTemplateSpec { template := src.DeepCopy() // filter annotations - // keep Restart annotation var annotations map[string]string if len(template.Annotations) > 0 { + annotations = make(map[string]string) + // keep Restart annotation if restart, ok := template.Annotations[constant.RestartAnnotationKey]; ok { - annotations = make(map[string]string, 1) annotations[constant.RestartAnnotationKey] = restart } + // keep Reconfigure annotation + for k, v := range template.Annotations { + if strings.HasPrefix(k, constant.UpgradeRestartAnnotationKey) { + annotations[k] = v + } + } + if len(annotations) == 0 { + annotations = nil + } } template.Annotations = annotations // filter labels diff --git a/pkg/controller/rsm2/in_place_update_util_test.go b/pkg/controller/rsm2/in_place_update_util_test.go index 7e43053b4cc..011a87458cc 100644 --- a/pkg/controller/rsm2/in_place_update_util_test.go +++ b/pkg/controller/rsm2/in_place_update_util_test.go @@ -21,6 +21,7 @@ package rsm2 import ( "fmt" + "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -28,6 +29,7 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/rand" "k8s.io/apimachinery/pkg/version" @@ -41,13 +43,21 @@ var _ = Describe("instance util test", func() { Context("filterInPlaceFields", func() { It("should work well", func() { pod := buildRandomPod() + restartTime := (metav1.Time{Time: time.Now()}).Format(time.RFC3339) + pod.Annotations[constant.RestartAnnotationKey] = restartTime + reconfigureKey := "config.kubeblocks.io/restart-foo-bar-config" + reconfigureValue := "7cdb79ffdb" + pod.Annotations[reconfigureKey] = reconfigureValue podTemplate := &corev1.PodTemplateSpec{ ObjectMeta: pod.ObjectMeta, Spec: pod.Spec, } result := filterInPlaceFields(podTemplate) - Expect(result.Annotations).Should(BeNil()) + Expect(result.Annotations).Should(HaveKey(constant.RestartAnnotationKey)) + Expect(result.Annotations[constant.RestartAnnotationKey]).Should(Equal(restartTime)) + Expect(result.Annotations).Should(HaveKey(reconfigureKey)) + Expect(result.Annotations[reconfigureKey]).Should(Equal(reconfigureValue)) Expect(result.Labels).Should(BeNil()) Expect(result.Spec.ActiveDeadlineSeconds).Should(BeNil()) Expect(result.Spec.Tolerations).Should(BeNil()) diff --git a/pkg/controller/rsm2/instance_util_test.go b/pkg/controller/rsm2/instance_util_test.go index 7f76672ab17..4e82c9e23a2 100644 --- a/pkg/controller/rsm2/instance_util_test.go +++ b/pkg/controller/rsm2/instance_util_test.go @@ -21,7 +21,6 @@ package rsm2 import ( "fmt" - "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -29,7 +28,6 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" workloads "github.com/apecloud/kubeblocks/apis/workloads/v1alpha1" @@ -412,29 +410,4 @@ var _ = Describe("instance util test", func() { Expect(instanceNameList).Should(Equal(podNamesExpected)) }) }) - - Context("filterInPlaceFields", func() { - It("should work well", func() { - pod := buildRandomPod() - restartTime := (metav1.Time{Time: time.Now()}).Format(time.RFC3339) - pod.Annotations[constant.RestartAnnotationKey] = restartTime - podTemplateSpec := &corev1.PodTemplateSpec{ - ObjectMeta: pod.ObjectMeta, - Spec: pod.Spec, - } - result := filterInPlaceFields(podTemplateSpec) - Expect(result).ShouldNot(BeNil()) - Expect(result.Annotations).Should(HaveKey(constant.RestartAnnotationKey)) - Expect(result.Annotations[constant.RestartAnnotationKey]).Should(Equal(restartTime)) - Expect(result.Labels).Should(BeNil()) - Expect(result.Spec.ActiveDeadlineSeconds).Should(BeNil()) - Expect(result.Spec.Tolerations).Should(BeNil()) - for _, container := range result.Spec.InitContainers { - Expect(container.Image).Should(BeEmpty()) - } - for _, container := range result.Spec.Containers { - Expect(container.Image).Should(BeEmpty()) - } - }) - }) })