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

set ConfigMap manually #48

Merged
merged 4 commits into from
May 24, 2018
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
2 changes: 2 additions & 0 deletions api/redisfailover/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ type RedisSettings struct {
ExporterVersion string `json:"exporterVersion,omitempty"`
Image string `json:"image,omitempty"`
Version string `json:"version,omitempty"`
ConfigMap string `json:"configMap,omitempty"`
}

// SentinelSettings defines the specification of the sentinel cluster
type SentinelSettings struct {
Replicas int32 `json:"replicas,omitempty"`
Resources RedisFailoverResources `json:"resources,omitempty"`
ConfigMap string `json:"configMap,omitempty"`
}

// RedisFailoverResources sets the limits and requests for a container
Expand Down
22 changes: 18 additions & 4 deletions operator/redisfailover/service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,15 @@ func (r *RedisFailoverKubeClient) EnsureSentinelService(rf *redisfailoverv1alpha

// EnsureSentinelConfigMap makes sure the sentinel configmap exists
func (r *RedisFailoverKubeClient) EnsureSentinelConfigMap(rf *redisfailoverv1alpha2.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error {
cm := generateSentinelConfigMap(rf, labels, ownerRefs)
return r.K8SService.CreateOrUpdateConfigMap(rf.Namespace, cm)
if rf.Spec.Sentinel.ConfigMap != "" {
if _, err := r.K8SService.GetConfigMap(rf.Namespace, rf.Spec.Sentinel.ConfigMap); err != nil {
return err
}
} else {
cm := generateSentinelConfigMap(rf, labels, ownerRefs)
return r.K8SService.CreateOrUpdateConfigMap(rf.Namespace, cm)
}
return nil
}

// EnsureSentinelDeployment makes sure the sentinel deployment exists in the desired state
Expand All @@ -76,8 +83,15 @@ func (r *RedisFailoverKubeClient) EnsureRedisStatefulset(rf *redisfailoverv1alph

// EnsureRedisConfigMap makes sure the sentinel configmap exists
func (r *RedisFailoverKubeClient) EnsureRedisConfigMap(rf *redisfailoverv1alpha2.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error {
cm := generateRedisConfigMap(rf, labels, ownerRefs)
return r.K8SService.CreateOrUpdateConfigMap(rf.Namespace, cm)
if rf.Spec.Redis.ConfigMap != "" {
if _, err := r.K8SService.GetConfigMap(rf.Namespace, rf.Spec.Redis.ConfigMap); err != nil {
return err
}
} else {
cm := generateRedisConfigMap(rf, labels, ownerRefs)
return r.K8SService.CreateOrUpdateConfigMap(rf.Namespace, cm)
}
return nil
}

// EnsureRedisService makes sure the redis statefulset exists
Expand Down
10 changes: 6 additions & 4 deletions operator/redisfailover/service/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func generateRedisService(rf *redisfailoverv1alpha2.RedisFailover, labels map[st
}

func generateSentinelConfigMap(rf *redisfailoverv1alpha2.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *corev1.ConfigMap {
name := GetSentinelName(rf)
name := GetSentinelConfigMapName(rf)
namespace := rf.Namespace

labels = util.MergeLabels(labels, generateLabels(sentinelRoleName, rf.Name))
Expand All @@ -98,7 +98,7 @@ sentinel parallel-syncs mymaster 2`,
}

func generateRedisConfigMap(rf *redisfailoverv1alpha2.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *corev1.ConfigMap {
name := GetRedisName(rf)
name := GetRedisConfigMapName(rf)
namespace := rf.Namespace

labels = util.MergeLabels(labels, generateLabels(redisRoleName, rf.Name))
Expand All @@ -119,6 +119,7 @@ tcp-keepalive 60`,

func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *appsv1beta2.StatefulSet {
name := GetRedisName(rf)
configMapName := GetRedisConfigMapName(rf)
namespace := rf.Namespace

spec := rf.Spec
Expand Down Expand Up @@ -208,7 +209,7 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: name,
Name: configMapName,
},
},
},
Expand All @@ -229,6 +230,7 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma

func generateSentinelDeployment(rf *redisfailoverv1alpha2.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *appsv1beta2.Deployment {
name := GetSentinelName(rf)
configMapName := GetSentinelConfigMapName(rf)
namespace := rf.Namespace

spec := rf.Spec
Expand Down Expand Up @@ -347,7 +349,7 @@ func generateSentinelDeployment(rf *redisfailoverv1alpha2.RedisFailover, labels
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: name,
Name: configMapName,
},
},
},
Expand Down
16 changes: 16 additions & 0 deletions operator/redisfailover/service/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,27 @@ import (
redisfailoverv1alpha2 "github.com/spotahome/redis-operator/api/redisfailover/v1alpha2"
)

// GetRedisConfigMapName returns the name for redis configmap
func GetRedisConfigMapName(rf *redisfailoverv1alpha2.RedisFailover) string {
if rf.Spec.Redis.ConfigMap != "" {
return rf.Spec.Redis.ConfigMap
}
return GetRedisName(rf)
}

// GetRedisName returns the name for redis resources
func GetRedisName(rf *redisfailoverv1alpha2.RedisFailover) string {
return generateName(redisName, rf.Name)
}

// GetSentinelConfigMapName returns the name for sentinel configmap
func GetSentinelConfigMapName(rf *redisfailoverv1alpha2.RedisFailover) string {
if rf.Spec.Sentinel.ConfigMap != "" {
return rf.Spec.Sentinel.ConfigMap
}
return GetSentinelName(rf)
}

// GetSentinelName returns the name for sentinel resources
func GetSentinelName(rf *redisfailoverv1alpha2.RedisFailover) string {
return generateName(sentinelName, rf.Name)
Expand Down