From c580eafc5e4c40f7d149081217fcc5e8b35feee8 Mon Sep 17 00:00:00 2001 From: Hiram Chirino Date: Wed, 22 Feb 2023 16:32:21 -0500 Subject: [PATCH] fix: #957 add . a readiness and heath probe Signed-off-by: Hiram Chirino --- cmd/cockroach-operator/main.go | 31 ++++++++++++++++++++++++------- install/operator.yaml | 14 ++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/cmd/cockroach-operator/main.go b/cmd/cockroach-operator/main.go index 0659ca560..850b14676 100644 --- a/cmd/cockroach-operator/main.go +++ b/cmd/cockroach-operator/main.go @@ -19,6 +19,7 @@ package main import ( "flag" "os" + "sigs.k8s.io/controller-runtime/pkg/healthz" "strings" crdbv1alpha1 "github.com/cockroachdb/cockroach-operator/apis/v1alpha1" @@ -88,13 +89,15 @@ func main() { watchNamespace := os.Getenv(watchNamespaceEnvVar) mgrOpts := ctrl.Options{ - Scheme: scheme, - Namespace: watchNamespace, - MetricsBindAddress: metricsAddr, - LeaderElection: enableLeaderElection, - LeaderElectionID: leaderElectionID, - Port: 9443, - CertDir: certDir, + Scheme: scheme, + Namespace: watchNamespace, + MetricsBindAddress: metricsAddr, + LeaderElection: enableLeaderElection, + LeaderElectionID: leaderElectionID, + LivenessEndpointName: "live", + ReadinessEndpointName: "ready", + Port: 9443, + CertDir: certDir, } if strings.Contains(watchNamespace, ",") { @@ -109,6 +112,20 @@ func main() { os.Exit(1) } + // Add readiness probe + err = mgr.AddReadyzCheck("ready-ping", healthz.Ping) + if err != nil { + setupLog.Error(err, "unable add a readiness check") + os.Exit(1) + } + + // Add liveness probe + err = mgr.AddHealthzCheck("live-ping", healthz.Ping) + if err != nil { + setupLog.Error(err, "unable add a health check") + os.Exit(1) + } + if err := (&crdbv1alpha1.CrdbCluster{}).SetupWebhookWithManager(mgr); err != nil { setupLog.Error(err, "unable to setup webhook") os.Exit(1) diff --git a/install/operator.yaml b/install/operator.yaml index a9cfead54..a98e38edb 100644 --- a/install/operator.yaml +++ b/install/operator.yaml @@ -569,6 +569,20 @@ spec: image: cockroachdb/cockroach-operator:v2.10.0 imagePullPolicy: IfNotPresent name: cockroach-operator + readinessProbe: + httpGet: + path: /ready + port: 9443 + scheme: HTTPS + periodSeconds: 5 + initialDelaySeconds: 5 + livenessProbe: + httpGet: + path: /live + port: 9443 + scheme: HTTPS + initialDelaySeconds: 10 + periodSeconds: 5 resources: requests: cpu: 10m