Skip to content

Commit

Permalink
Merge pull request #86 from spotahome/devops-823-improve-update-process
Browse files Browse the repository at this point in the history
[DEVOPS-823] Improve update process
  • Loading branch information
jchanam authored Sep 4, 2018
2 parents bac9c2f + 866cf89 commit 500ed2d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := 0.5.1
VERSION := 0.5.2

# Name of this service/application
SERVICE_NAME := redis-operator
Expand Down
14 changes: 14 additions & 0 deletions api/redisfailover/v1alpha2/defaults.go
Original file line number Diff line number Diff line change
@@ -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"}
)
42 changes: 42 additions & 0 deletions api/redisfailover/v1alpha2/validate.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions operator/redisfailover/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 0 additions & 11 deletions operator/redisfailover/service/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 8 additions & 26 deletions operator/redisfailover/service/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions operator/redisfailover/service/heal.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package service

import (
"errors"
"strconv"

redisfailoverv1alpha2 "github.com/spotahome/redis-operator/api/redisfailover/v1alpha2"
Expand Down Expand Up @@ -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 == "" {
Expand Down

0 comments on commit 500ed2d

Please sign in to comment.