Skip to content

Commit

Permalink
Merge pull request #560 from pych/custom-probes
Browse files Browse the repository at this point in the history
Feature: Adding capabilility to define custom probes
  • Loading branch information
ese authored Apr 20, 2023
2 parents fe8090a + 8e06b38 commit c51fa70
Show file tree
Hide file tree
Showing 9 changed files with 2,734 additions and 69 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
- uses: medyagh/[email protected]
with:
kubernetes-version: ${{ matrix.kubernetes }}
minikube-version: 1.28.0
driver: none
- name: Add redisfailover CRD
run: kubectl create -f manifests/databases.spotahome.com_redisfailovers.yaml
Expand Down
6 changes: 6 additions & 0 deletions api/redisfailover/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ type RedisSettings struct {
TerminationGracePeriodSeconds int64 `json:"terminationGracePeriod,omitempty"`
ExtraVolumes []corev1.Volume `json:"extraVolumes,omitempty"`
ExtraVolumeMounts []corev1.VolumeMount `json:"extraVolumeMounts,omitempty"`
CustomLivenessProbe *corev1.Probe `json:"customLivenessProbe,omitempty"`
CustomReadinessProbe *corev1.Probe `json:"customReadinessProbe,omitempty"`
CustomStartupProbe *corev1.Probe `json:"customStartupProbe,omitempty"`
}

// SentinelSettings defines the specification of the sentinel cluster
Expand Down Expand Up @@ -97,6 +100,9 @@ type SentinelSettings struct {
ServiceAccountName string `json:"serviceAccountName,omitempty"`
ExtraVolumes []corev1.Volume `json:"extraVolumes,omitempty"`
ExtraVolumeMounts []corev1.VolumeMount `json:"extraVolumeMounts,omitempty"`
CustomLivenessProbe *corev1.Probe `json:"customLivenessProbe,omitempty"`
CustomReadinessProbe *corev1.Probe `json:"customReadinessProbe,omitempty"`
CustomStartupProbe *corev1.Probe `json:"customStartupProbe,omitempty"`
}

// AuthSettings contains settings about auth
Expand Down
30 changes: 30 additions & 0 deletions api/redisfailover/v1/zz_generated.deepcopy.go

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

8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ require (
github.com/sirupsen/logrus v1.9.0
github.com/spotahome/kooper/v2 v2.2.0
github.com/stretchr/testify v1.8.1
k8s.io/api v0.26.0
k8s.io/apiextensions-apiserver v0.26.0
k8s.io/apimachinery v0.26.0
k8s.io/client-go v0.26.0
k8s.io/api v0.24.4
k8s.io/apiextensions-apiserver v0.24.4
k8s.io/apimachinery v0.24.4
k8s.io/client-go v0.24.4
)

require (
Expand Down
393 changes: 382 additions & 11 deletions go.sum

Large diffs are not rendered by default.

900 changes: 900 additions & 0 deletions manifests/databases.spotahome.com_redisfailovers.yaml

Large diffs are not rendered by default.

900 changes: 900 additions & 0 deletions manifests/kustomize/base/databases.spotahome.com_redisfailovers.yaml

Large diffs are not rendered by default.

132 changes: 78 additions & 54 deletions operator/redisfailover/service/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,31 +330,7 @@ func generateRedisStatefulSet(rf *redisfailoverv1.RedisFailover, labels map[stri
},
VolumeMounts: volumeMounts,
Command: redisCommand,
ReadinessProbe: &corev1.Probe{
InitialDelaySeconds: graceTime,
TimeoutSeconds: 5,
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{"/bin/sh", "/redis-readiness/ready.sh"},
},
},
},
LivenessProbe: &corev1.Probe{
InitialDelaySeconds: graceTime,
TimeoutSeconds: 5,
FailureThreshold: 6,
PeriodSeconds: 15,
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"sh",
"-c",
fmt.Sprintf("redis-cli -h $(hostname) -p %[1]v ping --user pinger --pass pingpass --no-auth-warning", rf.Spec.Redis.Port),
},
},
},
},
Resources: rf.Spec.Redis.Resources,
Resources: rf.Spec.Redis.Resources,
Lifecycle: &corev1.Lifecycle{
PreStop: &corev1.LifecycleHandler{
Exec: &corev1.ExecAction{
Expand Down Expand Up @@ -394,7 +370,43 @@ func generateRedisStatefulSet(rf *redisfailoverv1.RedisFailover, labels map[stri
}
}

if rf.Spec.Redis.StartupConfigMap != "" {
if rf.Spec.Redis.CustomLivenessProbe != nil {
ss.Spec.Template.Spec.Containers[0].LivenessProbe = rf.Spec.Redis.CustomLivenessProbe
} else {
ss.Spec.Template.Spec.Containers[0].LivenessProbe = &corev1.Probe{
InitialDelaySeconds: graceTime,
TimeoutSeconds: 5,
FailureThreshold: 6,
PeriodSeconds: 15,
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"sh",
"-c",
fmt.Sprintf("redis-cli -h $(hostname) -p %[1]v ping --user pinger --pass pingpass --no-auth-warning", rf.Spec.Redis.Port),
},
},
},
}
}

if rf.Spec.Redis.CustomReadinessProbe != nil {
ss.Spec.Template.Spec.Containers[0].ReadinessProbe = rf.Spec.Redis.CustomReadinessProbe
} else {
ss.Spec.Template.Spec.Containers[0].ReadinessProbe = &corev1.Probe{
InitialDelaySeconds: graceTime,
TimeoutSeconds: 5,
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{"/bin/sh", "/redis-readiness/ready.sh"},
},
},
}
}

if rf.Spec.Redis.CustomStartupProbe != nil {
ss.Spec.Template.Spec.Containers[0].StartupProbe = rf.Spec.Redis.CustomStartupProbe
} else if rf.Spec.Redis.StartupConfigMap != "" {
ss.Spec.Template.Spec.Containers[0].StartupProbe = &corev1.Probe{
InitialDelaySeconds: graceTime,
TimeoutSeconds: 5,
Expand Down Expand Up @@ -517,33 +529,7 @@ func generateSentinelDeployment(rf *redisfailoverv1.RedisFailover, labels map[st
},
VolumeMounts: volumeMounts,
Command: sentinelCommand,
ReadinessProbe: &corev1.Probe{
InitialDelaySeconds: graceTime,
TimeoutSeconds: 5,
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"sh",
"-c",
"redis-cli -h $(hostname) -p 26379 ping",
},
},
},
},
LivenessProbe: &corev1.Probe{
InitialDelaySeconds: graceTime,
TimeoutSeconds: 5,
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"sh",
"-c",
"redis-cli -h $(hostname) -p 26379 ping",
},
},
},
},
Resources: rf.Spec.Sentinel.Resources,
Resources: rf.Spec.Sentinel.Resources,
},
},
Volumes: volumes,
Expand All @@ -552,7 +538,45 @@ func generateSentinelDeployment(rf *redisfailoverv1.RedisFailover, labels map[st
},
}

if rf.Spec.Sentinel.StartupConfigMap != "" {
if rf.Spec.Sentinel.CustomLivenessProbe != nil {
sd.Spec.Template.Spec.Containers[0].LivenessProbe = rf.Spec.Sentinel.CustomLivenessProbe
} else {
sd.Spec.Template.Spec.Containers[0].LivenessProbe = &corev1.Probe{
InitialDelaySeconds: graceTime,
TimeoutSeconds: 5,
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"sh",
"-c",
"redis-cli -h $(hostname) -p 26379 ping",
},
},
},
}
}

if rf.Spec.Sentinel.CustomReadinessProbe != nil {
sd.Spec.Template.Spec.Containers[0].ReadinessProbe = rf.Spec.Sentinel.CustomReadinessProbe
} else {
sd.Spec.Template.Spec.Containers[0].ReadinessProbe = &corev1.Probe{
InitialDelaySeconds: graceTime,
TimeoutSeconds: 5,
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"sh",
"-c",
"redis-cli -h $(hostname) -p 26379 ping",
},
},
},
}
}

if rf.Spec.Sentinel.CustomStartupProbe != nil {
sd.Spec.Template.Spec.Containers[0].StartupProbe = rf.Spec.Sentinel.CustomStartupProbe
} else if rf.Spec.Sentinel.StartupConfigMap != "" {
sd.Spec.Template.Spec.Containers[0].StartupProbe = &corev1.Probe{
InitialDelaySeconds: graceTime,
TimeoutSeconds: 5,
Expand Down
Loading

0 comments on commit c51fa70

Please sign in to comment.