Skip to content

Commit 902f063

Browse files
authored
health: add liveness and readiness probes (#508)
1 parent 7a6d2ee commit 902f063

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

config/manager/manager.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ spec:
2828
image: controller:latest
2929
imagePullPolicy: Always
3030
name: manager
31+
ports:
32+
- containerPort: 9440
33+
name: healthz
34+
protocol: TCP
35+
readinessProbe:
36+
httpGet:
37+
path: /readyz
38+
port: healthz
39+
livenessProbe:
40+
httpGet:
41+
path: /healthz
42+
port: healthz
3143
terminationGracePeriodSeconds: 10
3244
tolerations:
3345
- effect: NoSchedule

main.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
2828
"sigs.k8s.io/controller-runtime/pkg/client/config"
29+
"sigs.k8s.io/controller-runtime/pkg/healthz"
2930

3031
_ "net/http/pprof"
3132

@@ -63,6 +64,7 @@ func main() {
6364
openStackClusterConcurrency int
6465
openStackMachineConcurrency int
6566
syncPeriod time.Duration
67+
healthAddr string
6668
)
6769

6870
flag.StringVar(
@@ -111,6 +113,12 @@ func main() {
111113
"The minimum interval at which watched resources are reconciled (e.g. 15m)",
112114
)
113115

116+
flag.StringVar(&healthAddr,
117+
"health-addr",
118+
":9440",
119+
"The address the health endpoint binds to.",
120+
)
121+
114122
flag.Parse()
115123

116124
if watchNamespace != "" {
@@ -132,12 +140,13 @@ func main() {
132140
}
133141

134142
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
135-
Scheme: scheme,
136-
MetricsBindAddress: metricsAddr,
137-
LeaderElection: enableLeaderElection,
138-
LeaderElectionID: "controller-leader-election-capo",
139-
SyncPeriod: &syncPeriod,
140-
Namespace: watchNamespace,
143+
Scheme: scheme,
144+
MetricsBindAddress: metricsAddr,
145+
LeaderElection: enableLeaderElection,
146+
LeaderElectionID: "controller-leader-election-capo",
147+
SyncPeriod: &syncPeriod,
148+
Namespace: watchNamespace,
149+
HealthProbeBindAddress: healthAddr,
141150
})
142151
if err != nil {
143152
setupLog.Error(err, "unable to start manager")
@@ -165,6 +174,16 @@ func main() {
165174
}
166175
// +kubebuilder:scaffold:builder
167176

177+
if err := mgr.AddReadyzCheck("ping", healthz.Ping); err != nil {
178+
setupLog.Error(err, "unable to create ready check")
179+
os.Exit(1)
180+
}
181+
182+
if err := mgr.AddHealthzCheck("ping", healthz.Ping); err != nil {
183+
setupLog.Error(err, "unable to create health check")
184+
os.Exit(1)
185+
}
186+
168187
setupLog.Info("starting manager")
169188
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
170189
setupLog.Error(err, "problem running manager")

0 commit comments

Comments
 (0)