From 56242c99db45081b5bf7c7bdedea4f08324e036d Mon Sep 17 00:00:00 2001 From: "guozhi.li" Date: Wed, 12 Oct 2022 14:10:12 +0800 Subject: [PATCH 1/3] add rf Annotations to sts --- operator/redisfailover/service/generator.go | 1 + service/k8s/statefulset.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index 3d1f9c936..83afaa088 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -280,6 +280,7 @@ func generateRedisStatefulSet(rf *redisfailoverv1.RedisFailover, labels map[stri ss := &appsv1.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ + Annotations: rf.Annotations, Name: name, Namespace: namespace, Labels: labels, diff --git a/service/k8s/statefulset.go b/service/k8s/statefulset.go index 0bbbee003..1aefeed4b 100644 --- a/service/k8s/statefulset.go +++ b/service/k8s/statefulset.go @@ -5,6 +5,8 @@ import ( "fmt" "strings" + "github.com/spotahome/redis-operator/operator/redisfailover/util" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -99,6 +101,7 @@ func (s *StatefulSetService) CreateOrUpdateStatefulSet(namespace string, statefu // namespace is our spec(https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#concurrency-control-and-consistency), // we will replace the current namespace state. statefulSet.ResourceVersion = storedStatefulSet.ResourceVersion + statefulSet.Annotations = util.MergeLabels(statefulSet.Annotations, storedStatefulSet.Annotations) return s.UpdateStatefulSet(namespace, statefulSet) } From db420c781484a18f81827c33cae38cd8d988f7c1 Mon Sep 17 00:00:00 2001 From: "guozhi.li" Date: Thu, 13 Oct 2022 10:00:06 +0800 Subject: [PATCH 2/3] support custom cmd. value is empty --- service/redis/client.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/service/redis/client.go b/service/redis/client.go index e3d070b2f..63d722a17 100644 --- a/service/redis/client.go +++ b/service/redis/client.go @@ -306,7 +306,8 @@ func (c *client) SetCustomRedisConfig(ip string, port string, configs []string, return err } // If the configuration is an empty line , it will result in an incorrect configSet, which will not run properly down the line. - if strings.TrimSpace(param) == "" || strings.TrimSpace(value) == "" { + // `config set save ""` should support + if strings.TrimSpace(param) == "" { continue } if err := c.applyRedisConfig(param, value, rClient); err != nil { From af99b4fa2ae92a144514a91afad324486e090da8 Mon Sep 17 00:00:00 2001 From: "guozhi.li" Date: Tue, 22 Nov 2022 15:57:04 +0800 Subject: [PATCH 3/3] add MergeAnnotations func --- operator/redisfailover/util/label.go | 12 ++++++++++++ service/k8s/statefulset.go | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/operator/redisfailover/util/label.go b/operator/redisfailover/util/label.go index e60450d46..381489964 100644 --- a/operator/redisfailover/util/label.go +++ b/operator/redisfailover/util/label.go @@ -11,3 +11,15 @@ func MergeLabels(allLabels ...map[string]string) map[string]string { } return res } + +// MergeAnnotations merges all the annotations maps received as argument into a single new label map. +func MergeAnnotations(allMergeAnnotations ...map[string]string) map[string]string { + res := map[string]string{} + + for _, labels := range allMergeAnnotations { + for k, v := range labels { + res[k] = v + } + } + return res +} diff --git a/service/k8s/statefulset.go b/service/k8s/statefulset.go index 1aefeed4b..5031ab9c9 100644 --- a/service/k8s/statefulset.go +++ b/service/k8s/statefulset.go @@ -101,7 +101,7 @@ func (s *StatefulSetService) CreateOrUpdateStatefulSet(namespace string, statefu // namespace is our spec(https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#concurrency-control-and-consistency), // we will replace the current namespace state. statefulSet.ResourceVersion = storedStatefulSet.ResourceVersion - statefulSet.Annotations = util.MergeLabels(statefulSet.Annotations, storedStatefulSet.Annotations) + statefulSet.Annotations = util.MergeAnnotations(statefulSet.Annotations, storedStatefulSet.Annotations) return s.UpdateStatefulSet(namespace, statefulSet) }