Skip to content

Commit f29d468

Browse files
authored
support for healthz (#492)
1 parent 7d78ed5 commit f29d468

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

config/manager/manager.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ spec:
3030
- "--metrics-bind-addr=127.0.0.1:8080"
3131
image: controller:latest
3232
name: manager
33+
ports:
34+
- containerPort: 9440
35+
name: healthz
36+
protocol: TCP
37+
readinessProbe:
38+
httpGet:
39+
path: /readyz
40+
port: healthz
41+
livenessProbe:
42+
httpGet:
43+
path: /healthz
44+
port: healthz
3345
resources:
3446
limits:
3547
cpu: 100m

main.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var (
4242
watchNamespace string
4343
metricsAddr string
4444
enableLeaderElection bool
45+
healthAddr string
4546

4647
scheme = runtime.NewScheme()
4748
setupLog = ctrl.Log.WithName("setup")
@@ -72,13 +73,14 @@ func main() {
7273

7374
syncPeriod := 15 * time.Second
7475
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
75-
Scheme: scheme,
76-
MetricsBindAddress: metricsAddr,
77-
Port: 9443,
78-
LeaderElection: enableLeaderElection,
79-
LeaderElectionID: "effcf9b8.cluster.x-k8s.io",
80-
SyncPeriod: &syncPeriod,
81-
Namespace: watchNamespace,
76+
Scheme: scheme,
77+
MetricsBindAddress: metricsAddr,
78+
Port: 9443,
79+
LeaderElection: enableLeaderElection,
80+
LeaderElectionID: "effcf9b8.cluster.x-k8s.io",
81+
SyncPeriod: &syncPeriod,
82+
Namespace: watchNamespace,
83+
HealthProbeBindAddress: healthAddr,
8284
})
8385
if err != nil {
8486
setupLog.Error(err, "unable to start manager")
@@ -131,6 +133,16 @@ func main() {
131133
}
132134
// +kubebuilder:scaffold:builder
133135

136+
if err := mgr.AddReadyzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
137+
setupLog.Error(err, "unable to create ready check")
138+
os.Exit(1)
139+
}
140+
141+
if err := mgr.AddHealthzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
142+
setupLog.Error(err, "unable to create health check")
143+
os.Exit(1)
144+
}
145+
134146
setupLog.Info("starting manager")
135147
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
136148
setupLog.Error(err, "problem running manager")
@@ -160,4 +172,11 @@ func initFlags(fs *pflag.FlagSet) {
160172
"",
161173
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.",
162174
)
175+
176+
fs.StringVar(
177+
&healthAddr,
178+
"health-addr",
179+
":9440",
180+
"The address the health endpoint binds to.",
181+
)
163182
}

0 commit comments

Comments
 (0)