Skip to content

Commit

Permalink
Merge pull request #495 from jiuker/feature_keep_rf_annotations
Browse files Browse the repository at this point in the history
[feature]add rf Annotations to sts
  • Loading branch information
ese authored Nov 22, 2022
2 parents 94cea5b + af99b4f commit 243ff47
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions operator/redisfailover/service/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions operator/redisfailover/util/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions service/k8s/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -105,6 +107,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.MergeAnnotations(statefulSet.Annotations, storedStatefulSet.Annotations)
return s.UpdateStatefulSet(namespace, statefulSet)
}

Expand Down

0 comments on commit 243ff47

Please sign in to comment.