Skip to content

Commit

Permalink
feat: support setting minReadySeconds on the stateful sets
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Robinson <[email protected]>
  • Loading branch information
mattrobinsonsre committed Jul 11, 2024
1 parent 0dddaea commit 802f01b
Show file tree
Hide file tree
Showing 31 changed files with 105 additions and 12 deletions.
1 change: 1 addition & 0 deletions api/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type KubernetesConfig struct {
UpdateStrategy appsv1.StatefulSetUpdateStrategy `json:"updateStrategy,omitempty"`
Service *ServiceConfig `json:"service,omitempty"`
IgnoreAnnotations []string `json:"ignoreAnnotations,omitempty"`
MinReadySeconds *int32 `json:"minReadySeconds,omitempty"`
}

// ServiceConfig define the type of service to be created and its annotations
Expand Down
5 changes: 5 additions & 0 deletions api/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions charts/redis-cluster/templates/redis-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ spec:
name: {{ .Values.redisCluster.redisSecret.secretName | quote }}
key: {{ .Values.redisCluster.redisSecret.secretKey | quote }}
{{- end }}
minReadySeconds: {{ .Values.redisCluster.minReadySeconds | default 0 }}

{{- if .Values.storageSpec }}
storage: {{ toYaml .Values.storageSpec | nindent 4 }}
Expand Down
3 changes: 2 additions & 1 deletion charts/redis-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ redisCluster:
enabled: false
maxUnavailable: 1
minAvailable: 1

# minReadySeconds: 0

follower:
replicas: 3
serviceType: ClusterIP
Expand Down
6 changes: 6 additions & 0 deletions charts/redis-operator/crds/redis-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down Expand Up @@ -6749,6 +6752,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down
6 changes: 6 additions & 0 deletions charts/redis-operator/crds/redis-replication.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down Expand Up @@ -6141,6 +6144,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down
6 changes: 6 additions & 0 deletions charts/redis-operator/crds/redis-sentinel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down Expand Up @@ -3595,6 +3598,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down
6 changes: 6 additions & 0 deletions charts/redis-operator/crds/redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down Expand Up @@ -6133,6 +6136,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down
1 change: 1 addition & 0 deletions charts/redis-replication/templates/redis-replication.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spec:
{{- if .Values.redisReplication.ignoreAnnotations}}
ignoreAnnotations: {{ toYaml .Values.redisReplication.ignoreAnnotations | nindent 6 }}
{{- end }}
minReadySeconds: {{ .Values.redisReplication.minReadySeconds | default 0 }}

redisExporter:
enabled: {{ .Values.redisExporter.enabled }}
Expand Down
3 changes: 2 additions & 1 deletion charts/redis-replication/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ redisReplication:
# memory: 128Mi
ignoreAnnotations: []
# - "redis.opstreelabs.in/ignore"

# minReadySeconds: 0

# Overwite name for resources
# name: ""

Expand Down
1 change: 1 addition & 0 deletions charts/redis-sentinel/templates/redis-sentinel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ spec:
{{- if .Values.redisSentinel.ignoreAnnotations}}
ignoreAnnotations: {{ toYaml .Values.redisSentinel.ignoreAnnotations | nindent 6 }}
{{- end }}
minReadySeconds: {{ .Values.redisSentinel.minReadySeconds | default 0 }}

redisExporter:
enabled: {{ .Values.redisExporter.enabled }}
Expand Down
3 changes: 2 additions & 1 deletion charts/redis-sentinel/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ redisSentinel:
# memory: 128Mi
ignoreAnnotations: []
# - "redis.opstreelabs.in/ignore"

# minReadySeconds: 0

# Overwite name for resources
# name: ""

Expand Down
3 changes: 2 additions & 1 deletion charts/redis/templates/redis-standalone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ spec:
{{- if .Values.redisStandalone.ignoreAnnotations}}
ignoreAnnotations: {{ toYaml .Values.redisStandalone.ignoreAnnotations | nindent 6 }}
{{- end }}

minReadySeconds: {{ .Values.redisStandalone.minReadySeconds | default 0 }}

redisExporter:
enabled: {{ .Values.redisExporter.enabled }}
image: "{{ .Values.redisExporter.image }}:{{ .Values.redisExporter.tag }}"
Expand Down
1 change: 1 addition & 0 deletions charts/redis/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ redisStandalone:
# memory: 128Mi
ignoreAnnotations: []
# - "redis.opstreelabs.in/ignore"
# minReadySeconds: 0

labels: {}
# foo: bar
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/redis.redis.opstreelabs.in_redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down Expand Up @@ -6133,6 +6136,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down Expand Up @@ -6749,6 +6752,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down Expand Up @@ -6141,6 +6144,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down Expand Up @@ -3595,6 +3598,9 @@ spec:
type: string
type: object
type: array
minReadySeconds:
format: int32
type: integer
redisSecret:
description: ExistingPasswordSecret is the struct to access the
existing secret
Expand Down
5 changes: 5 additions & 0 deletions k8sutils/redis-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type RedisClusterService struct {

// generateRedisClusterParams generates Redis cluster information
func generateRedisClusterParams(cr *redisv1beta2.RedisCluster, replicas int32, externalConfig *string, params RedisClusterSTS) statefulSetParameters {
var minreadyseconds int32 = 0
if cr.Spec.KubernetesConfig.MinReadySeconds != nil {
minreadyseconds = *cr.Spec.KubernetesConfig.MinReadySeconds
}
res := statefulSetParameters{
Replicas: &replicas,
ClusterMode: true,
Expand All @@ -47,6 +51,7 @@ func generateRedisClusterParams(cr *redisv1beta2.RedisCluster, replicas int32, e
UpdateStrategy: cr.Spec.KubernetesConfig.UpdateStrategy,
IgnoreAnnotations: cr.Spec.KubernetesConfig.IgnoreAnnotations,
HostNetwork: cr.Spec.HostNetwork,
MinReadySeconds: minreadyseconds,
}
if cr.Spec.RedisExporter != nil {
res.EnableMetrics = cr.Spec.RedisExporter.Enabled
Expand Down
2 changes: 2 additions & 0 deletions k8sutils/redis-cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func Test_generateRedisClusterParams(t *testing.T) {
FSGroup: ptr.To(int64(1000)),
},
PriorityClassName: "high-priority",
MinReadySeconds: 5,
Affinity: &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
Expand Down Expand Up @@ -94,6 +95,7 @@ func Test_generateRedisClusterParams(t *testing.T) {
FSGroup: ptr.To(int64(1000)),
},
PriorityClassName: "high-priority",
MinReadySeconds: 5,
Affinity: &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
Expand Down
6 changes: 6 additions & 0 deletions k8sutils/redis-replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func CreateReplicationRedis(cr *redisv1beta2.RedisReplication, cl kubernetes.Int
labels := getRedisLabels(cr.ObjectMeta.Name, replication, "replication", cr.ObjectMeta.Labels)
annotations := generateStatefulSetsAnots(cr.ObjectMeta, cr.Spec.KubernetesConfig.IgnoreAnnotations)
objectMetaInfo := generateObjectMetaInformation(stateFulName, cr.Namespace, labels, annotations)

err := CreateOrUpdateStateFul(
cl,
logger,
Expand All @@ -81,6 +82,10 @@ func CreateReplicationRedis(cr *redisv1beta2.RedisReplication, cl kubernetes.Int

func generateRedisReplicationParams(cr *redisv1beta2.RedisReplication) statefulSetParameters {
replicas := cr.Spec.GetReplicationCounts("Replication")
var minreadyseconds int32 = 0
if cr.Spec.KubernetesConfig.MinReadySeconds != nil {
minreadyseconds = *cr.Spec.KubernetesConfig.MinReadySeconds
}
res := statefulSetParameters{
Replicas: &replicas,
ClusterMode: false,
Expand All @@ -93,6 +98,7 @@ func generateRedisReplicationParams(cr *redisv1beta2.RedisReplication) statefulS
TerminationGracePeriodSeconds: cr.Spec.TerminationGracePeriodSeconds,
UpdateStrategy: cr.Spec.KubernetesConfig.UpdateStrategy,
IgnoreAnnotations: cr.Spec.KubernetesConfig.IgnoreAnnotations,
MinReadySeconds: minreadyseconds,
}
if cr.Spec.KubernetesConfig.ImagePullSecrets != nil {
res.ImagePullSecrets = cr.Spec.KubernetesConfig.ImagePullSecrets
Expand Down
2 changes: 1 addition & 1 deletion k8sutils/redis-replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func Test_generateRedisReplicationParams(t *testing.T) {
FSGroup: ptr.To(int64(1000)),
},
PriorityClassName: "high-priority",
MinReadySeconds: 5,
Affinity: &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
Expand Down Expand Up @@ -86,7 +87,6 @@ func Test_generateRedisReplicationParams(t *testing.T) {
if err != nil {
t.Fatalf("Failed to unmarshal file %s: %v", path, err)
}

actual := generateRedisReplicationParams(input)
assert.EqualValues(t, expected, actual, "Expected %+v, got %+v", expected, actual)
}
Expand Down
5 changes: 5 additions & 0 deletions k8sutils/redis-sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func (service RedisSentinelSTS) CreateRedisSentinelSetup(ctx context.Context, cl

// Create Redis Sentile Params for the statefulset
func generateRedisSentinelParams(cr *redisv1beta2.RedisSentinel, replicas int32, externalConfig *string, affinity *corev1.Affinity) statefulSetParameters {
var minreadyseconds int32 = 0
if cr.Spec.KubernetesConfig.MinReadySeconds != nil {
minreadyseconds = *cr.Spec.KubernetesConfig.MinReadySeconds
}
res := statefulSetParameters{
Replicas: &replicas,
ClusterMode: false,
Expand All @@ -99,6 +103,7 @@ func generateRedisSentinelParams(cr *redisv1beta2.RedisSentinel, replicas int32,
ServiceAccountName: cr.Spec.ServiceAccountName,
UpdateStrategy: cr.Spec.KubernetesConfig.UpdateStrategy,
IgnoreAnnotations: cr.Spec.KubernetesConfig.IgnoreAnnotations,
MinReadySeconds: minreadyseconds,
}

if cr.Spec.KubernetesConfig.ImagePullSecrets != nil {
Expand Down
1 change: 1 addition & 0 deletions k8sutils/redis-sentinel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func Test_generateRedisSentinelParams(t *testing.T) {
FSGroup: ptr.To(int64(1000)),
},
PriorityClassName: "high-priority",
MinReadySeconds: 5,
Affinity: &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
Expand Down
5 changes: 5 additions & 0 deletions k8sutils/redis-standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func CreateStandaloneRedis(cr *redisv1beta2.Redis, cl kubernetes.Interface) erro
// generateRedisStandalone generates Redis standalone information
func generateRedisStandaloneParams(cr *redisv1beta2.Redis) statefulSetParameters {
replicas := int32(1)
var minreadyseconds int32 = 0
if cr.Spec.KubernetesConfig.MinReadySeconds != nil {
minreadyseconds = *cr.Spec.KubernetesConfig.MinReadySeconds
}
res := statefulSetParameters{
Replicas: &replicas,
ClusterMode: false,
Expand All @@ -89,6 +93,7 @@ func generateRedisStandaloneParams(cr *redisv1beta2.Redis) statefulSetParameters
Tolerations: cr.Spec.Tolerations,
UpdateStrategy: cr.Spec.KubernetesConfig.UpdateStrategy,
IgnoreAnnotations: cr.Spec.KubernetesConfig.IgnoreAnnotations,
MinReadySeconds: minreadyseconds,
}
if cr.Spec.KubernetesConfig.ImagePullSecrets != nil {
res.ImagePullSecrets = cr.Spec.KubernetesConfig.ImagePullSecrets
Expand Down
7 changes: 4 additions & 3 deletions k8sutils/redis-standalone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (
func Test_generateRedisStandaloneParams(t *testing.T) {
path := filepath.Join("..", "tests", "testdata", "redis-standalone.yaml")
expected := statefulSetParameters{
Replicas: ptr.To(int32(1)),
ClusterMode: false,
NodeConfVolume: false,
Replicas: ptr.To(int32(1)),
ClusterMode: false,
NodeConfVolume: false,
MinReadySeconds: 5,
// Metadata: metav1.ObjectMeta{
// Name: "redis-standalone",
// Namespace: "redis",
Expand Down
Loading

0 comments on commit 802f01b

Please sign in to comment.