From dc41b36531708f8e3f26e1adc9e53f2b6dd287fd Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 4 Sep 2018 12:08:44 +0200 Subject: [PATCH 1/3] [DEVOPS-823] Increase checks time --- operator/redisfailover/handler.go | 4 +++ operator/redisfailover/service/constants.go | 11 ------- operator/redisfailover/service/generator.go | 34 +++++---------------- operator/redisfailover/service/heal.go | 4 +++ 4 files changed, 16 insertions(+), 37 deletions(-) diff --git a/operator/redisfailover/handler.go b/operator/redisfailover/handler.go index c4ce02b73..57bb06367 100644 --- a/operator/redisfailover/handler.go +++ b/operator/redisfailover/handler.go @@ -62,6 +62,10 @@ func (r *RedisFailoverHandler) Add(_ context.Context, obj runtime.Object) error return fmt.Errorf("can't handle redis failover state, parentLabels map[string]string, ownerRefs []metav1.OwnerReferencenot a redisfailover object") } + if err := rf.Validate(); err != nil { + return err + } + // Create owner refs so the objects manager by this handler have ownership to the // received RF. oRefs := r.createOwnerReferences(rf) diff --git a/operator/redisfailover/service/constants.go b/operator/redisfailover/service/constants.go index 079adf75d..1ce7f320a 100644 --- a/operator/redisfailover/service/constants.go +++ b/operator/redisfailover/service/constants.go @@ -5,17 +5,6 @@ const ( logNamespaceField = "namespace" ) -const ( - // ExporterImage defines the redis exporter image - ExporterImage = "oliver006/redis_exporter" - // ExporterImageVersion defines the redis exporter version - ExporterImageVersion = "v0.11.3" - // RedisImage defines the redis image - RedisImage = "redis" - // RedisImageVersion defines the redis image version - RedisImageVersion = "3.2-alpine" -) - // variables refering to the redis exporter port const ( exporterPort = 9121 diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index fb86b9611..e95e370a3 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -18,6 +18,8 @@ const ( redisConfigurationVolumeName = "redis-config" redisShutdownConfigurationVolumeName = "redis-shutdown-config" redisStorageVolumeName = "redis-data" + + graceTime = 60 ) func generateSentinelService(rf *redisfailoverv1alpha2.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *corev1.Service { @@ -202,7 +204,7 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma fmt.Sprintf("/redis/%s", redisConfigFileName), }, ReadinessProbe: &corev1.Probe{ - InitialDelaySeconds: 15, + InitialDelaySeconds: graceTime, TimeoutSeconds: 5, Handler: corev1.Handler{ Exec: &corev1.ExecAction{ @@ -215,7 +217,7 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma }, }, LivenessProbe: &corev1.Probe{ - InitialDelaySeconds: 5, + InitialDelaySeconds: graceTime, TimeoutSeconds: 5, Handler: corev1.Handler{ Exec: &corev1.ExecAction{ @@ -348,7 +350,7 @@ func generateSentinelDeployment(rf *redisfailoverv1alpha2.RedisFailover, labels "--sentinel", }, ReadinessProbe: &corev1.Probe{ - InitialDelaySeconds: 15, + InitialDelaySeconds: graceTime, TimeoutSeconds: 5, Handler: corev1.Handler{ Exec: &corev1.ExecAction{ @@ -361,7 +363,7 @@ func generateSentinelDeployment(rf *redisfailoverv1alpha2.RedisFailover, labels }, }, LivenessProbe: &corev1.Probe{ - InitialDelaySeconds: 5, + InitialDelaySeconds: graceTime, TimeoutSeconds: 5, Handler: corev1.Handler{ Exec: &corev1.ExecAction{ @@ -541,31 +543,11 @@ func getQuorum(rf *redisfailoverv1alpha2.RedisFailover) int32 { } func getRedisImage(rf *redisfailoverv1alpha2.RedisFailover) string { - image := RedisImage - if rf.Spec.Redis.Image != "" { - image = rf.Spec.Redis.Image - } - - version := RedisImageVersion - if rf.Spec.Redis.Version != "" { - version = rf.Spec.Redis.Version - } - - return fmt.Sprintf("%s:%s", image, version) + return fmt.Sprintf("%s:%s", rf.Spec.Redis.Image, rf.Spec.Redis.Version) } func getRedisExporterImage(rf *redisfailoverv1alpha2.RedisFailover) string { - image := ExporterImage - if rf.Spec.Redis.ExporterImage != "" { - image = rf.Spec.Redis.ExporterImage - } - - version := ExporterImageVersion - if rf.Spec.Redis.ExporterVersion != "" { - version = rf.Spec.Redis.ExporterVersion - } - - return fmt.Sprintf("%s:%s", image, version) + return fmt.Sprintf("%s:%s", rf.Spec.Redis.ExporterImage, rf.Spec.Redis.ExporterVersion) } func getRedisVolumeMounts(rf *redisfailoverv1alpha2.RedisFailover) []corev1.VolumeMount { diff --git a/operator/redisfailover/service/heal.go b/operator/redisfailover/service/heal.go index 41d250bbb..b4d54794c 100644 --- a/operator/redisfailover/service/heal.go +++ b/operator/redisfailover/service/heal.go @@ -1,6 +1,7 @@ package service import ( + "errors" "strconv" redisfailoverv1alpha2 "github.com/spotahome/redis-operator/api/redisfailover/v1alpha2" @@ -41,6 +42,9 @@ func (r *RedisFailoverHealer) SetRandomMaster(rf *redisfailoverv1alpha2.RedisFai if err != nil { return err } + if len(ssp.Items) < 1 { + return errors.New("number of redis pods are 0") + } newMasterIP := "" for _, pod := range ssp.Items { if newMasterIP == "" { From a2351158b9c39524b491497dfeac4f33773b61ee Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 4 Sep 2018 12:09:29 +0200 Subject: [PATCH 2/3] [DEVOPS-823] Add defaults and validator for rf spec --- api/redisfailover/v1alpha2/defaults.go | 14 +++++++++ api/redisfailover/v1alpha2/validate.go | 42 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 api/redisfailover/v1alpha2/defaults.go create mode 100644 api/redisfailover/v1alpha2/validate.go diff --git a/api/redisfailover/v1alpha2/defaults.go b/api/redisfailover/v1alpha2/defaults.go new file mode 100644 index 000000000..5ca24aee5 --- /dev/null +++ b/api/redisfailover/v1alpha2/defaults.go @@ -0,0 +1,14 @@ +package v1alpha2 + +const ( + defaultRedisNumber = 3 + defaultSentinelNumber = 3 + defaultExporterImage = "oliver006/redis_exporter" + defaultExporterImageVersion = "v0.11.3" + defaultRedisImage = "redis" + defaultRedisImageVersion = "3.2-alpine" +) + +var ( + defaultSentinelCustomConfig = []string{"down-after-milliseconds 5000", "failover-timeout 10000"} +) diff --git a/api/redisfailover/v1alpha2/validate.go b/api/redisfailover/v1alpha2/validate.go new file mode 100644 index 000000000..3d073aa2b --- /dev/null +++ b/api/redisfailover/v1alpha2/validate.go @@ -0,0 +1,42 @@ +package v1alpha2 + +import ( + "errors" +) + +// Validate set the values by default if not defined and checks if the values given are valid +func (r *RedisFailover) Validate() error { + if r.Spec.Redis.Replicas == 0 { + r.Spec.Redis.Replicas = defaultRedisNumber + } else if r.Spec.Redis.Replicas < defaultRedisNumber { + return errors.New("number of redises in spec is less than the minimum") + } + + if r.Spec.Sentinel.Replicas == 0 { + r.Spec.Sentinel.Replicas = defaultSentinelNumber + } else if r.Spec.Sentinel.Replicas < defaultSentinelNumber { + return errors.New("number of sentinels in spec is less than the minimum") + } + + if r.Spec.Redis.Image == "" { + r.Spec.Redis.Image = defaultRedisImage + } + + if r.Spec.Redis.Version == "" { + r.Spec.Redis.Version = defaultRedisImageVersion + } + + if r.Spec.Redis.ExporterImage == "" { + r.Spec.Redis.ExporterImage = defaultExporterImage + } + + if r.Spec.Redis.ExporterVersion == "" { + r.Spec.Redis.ExporterVersion = defaultExporterImageVersion + } + + if len(r.Spec.Sentinel.CustomConfig) == 0 { + r.Spec.Sentinel.CustomConfig = defaultSentinelCustomConfig + } + + return nil +} From 866cf89546898dc621a5173696d1393d315870e0 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 4 Sep 2018 12:15:49 +0200 Subject: [PATCH 3/3] [DEVOPS-823] Bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4c9617560..48505c188 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION := 0.5.1 +VERSION := 0.5.2 # Name of this service/application SERVICE_NAME := redis-operator