Skip to content

Commit

Permalink
fix: reconfigure not working (#7056)
Browse files Browse the repository at this point in the history
  • Loading branch information
free6om authored Apr 15, 2024
1 parent 932d50b commit 7bb8896
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
13 changes: 11 additions & 2 deletions pkg/controller/rsm2/in_place_update_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/rsm2/in_place_update_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ package rsm2

import (
"fmt"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

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"

Expand All @@ -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())
Expand Down
27 changes: 0 additions & 27 deletions pkg/controller/rsm2/instance_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ package rsm2

import (
"fmt"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

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"
Expand Down Expand Up @@ -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())
}
})
})
})

0 comments on commit 7bb8896

Please sign in to comment.