Skip to content

Commit c580eaf

Browse files
committed
fix: cockroachdb#957 add . a readiness and heath probe
Signed-off-by: Hiram Chirino <[email protected]>
1 parent e8f430f commit c580eaf

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

Diff for: cmd/cockroach-operator/main.go

+24-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"flag"
2121
"os"
22+
"sigs.k8s.io/controller-runtime/pkg/healthz"
2223
"strings"
2324

2425
crdbv1alpha1 "github.com/cockroachdb/cockroach-operator/apis/v1alpha1"
@@ -88,13 +89,15 @@ func main() {
8889
watchNamespace := os.Getenv(watchNamespaceEnvVar)
8990

9091
mgrOpts := ctrl.Options{
91-
Scheme: scheme,
92-
Namespace: watchNamespace,
93-
MetricsBindAddress: metricsAddr,
94-
LeaderElection: enableLeaderElection,
95-
LeaderElectionID: leaderElectionID,
96-
Port: 9443,
97-
CertDir: certDir,
92+
Scheme: scheme,
93+
Namespace: watchNamespace,
94+
MetricsBindAddress: metricsAddr,
95+
LeaderElection: enableLeaderElection,
96+
LeaderElectionID: leaderElectionID,
97+
LivenessEndpointName: "live",
98+
ReadinessEndpointName: "ready",
99+
Port: 9443,
100+
CertDir: certDir,
98101
}
99102

100103
if strings.Contains(watchNamespace, ",") {
@@ -109,6 +112,20 @@ func main() {
109112
os.Exit(1)
110113
}
111114

115+
// Add readiness probe
116+
err = mgr.AddReadyzCheck("ready-ping", healthz.Ping)
117+
if err != nil {
118+
setupLog.Error(err, "unable add a readiness check")
119+
os.Exit(1)
120+
}
121+
122+
// Add liveness probe
123+
err = mgr.AddHealthzCheck("live-ping", healthz.Ping)
124+
if err != nil {
125+
setupLog.Error(err, "unable add a health check")
126+
os.Exit(1)
127+
}
128+
112129
if err := (&crdbv1alpha1.CrdbCluster{}).SetupWebhookWithManager(mgr); err != nil {
113130
setupLog.Error(err, "unable to setup webhook")
114131
os.Exit(1)

Diff for: install/operator.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,20 @@ spec:
569569
image: cockroachdb/cockroach-operator:v2.10.0
570570
imagePullPolicy: IfNotPresent
571571
name: cockroach-operator
572+
readinessProbe:
573+
httpGet:
574+
path: /ready
575+
port: 9443
576+
scheme: HTTPS
577+
periodSeconds: 5
578+
initialDelaySeconds: 5
579+
livenessProbe:
580+
httpGet:
581+
path: /live
582+
port: 9443
583+
scheme: HTTPS
584+
initialDelaySeconds: 10
585+
periodSeconds: 5
572586
resources:
573587
requests:
574588
cpu: 10m

0 commit comments

Comments
 (0)