Skip to content

Commit

Permalink
Merge pull request #48 from sillydong/master
Browse files Browse the repository at this point in the history
set ConfigMap manually
  • Loading branch information
jchanam authored May 24, 2018
2 parents 2d75ec7 + 381c0ae commit bc98d8a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
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

0 comments on commit bc98d8a

Please sign in to comment.