@@ -19,6 +19,7 @@ package main
19
19
import (
20
20
"flag"
21
21
"os"
22
+ "sigs.k8s.io/controller-runtime/pkg/healthz"
22
23
"strings"
23
24
24
25
crdbv1alpha1 "github.com/cockroachdb/cockroach-operator/apis/v1alpha1"
@@ -88,13 +89,15 @@ func main() {
88
89
watchNamespace := os .Getenv (watchNamespaceEnvVar )
89
90
90
91
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 ,
98
101
}
99
102
100
103
if strings .Contains (watchNamespace , "," ) {
@@ -109,6 +112,20 @@ func main() {
109
112
os .Exit (1 )
110
113
}
111
114
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
+
112
129
if err := (& crdbv1alpha1.CrdbCluster {}).SetupWebhookWithManager (mgr ); err != nil {
113
130
setupLog .Error (err , "unable to setup webhook" )
114
131
os .Exit (1 )
0 commit comments