Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature]add rf Annotations to sts #495

Merged
merged 3 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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.MergeAnnotations(statefulSet.Annotations, storedStatefulSet.Annotations)
return s.UpdateStatefulSet(namespace, statefulSet)
}

Expand Down
3 changes: 2 additions & 1 deletion service/redis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down