Skip to content

Commit 0a84e13

Browse files
committed
add liveness, readiness, and startup probes to noobaa-operator
- integrate controller-runtime healthz and readyz endpoints into the namespace-scoped manager - expose probe server on :8081 and register default checks - update operator Deployment with liveness, readiness, and startup probes Signed-off-by: Oded Viner <[email protected]>
1 parent 22f1cc3 commit 0a84e13

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

deploy/operator.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ spec:
4242
- name: noobaa-operator
4343
image: NOOBAA_OPERATOR_IMAGE
4444
terminationMessagePolicy: FallbackToLogsOnError
45+
ports:
46+
- name: readyz
47+
containerPort: 8081
4548
volumeMounts:
4649
- name: bound-sa-token
4750
mountPath: /var/run/secrets/openshift/serviceaccount
@@ -51,6 +54,29 @@ spec:
5154
# SHOULD BE RETURNED ONCE COSI IS BACK
5255
# - name: socket
5356
# mountPath: /var/lib/cosi
57+
readinessProbe:
58+
httpGet:
59+
path: /readyz
60+
port: readyz
61+
initialDelaySeconds: 5
62+
periodSeconds: 10
63+
timeoutSeconds: 5
64+
failureThreshold: 3
65+
livenessProbe:
66+
httpGet:
67+
path: /readyz
68+
port: readyz
69+
initialDelaySeconds: 15
70+
periodSeconds: 10
71+
timeoutSeconds: 5
72+
failureThreshold: 3
73+
startupProbe:
74+
httpGet:
75+
path: /readyz
76+
port: readyz
77+
periodSeconds: 10
78+
timeoutSeconds: 5
79+
failureThreshold: 30
5480
resources:
5581
limits:
5682
cpu: "250m"

pkg/bundle/deploy.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6231,6 +6231,9 @@ spec:
62316231
- name: noobaa-operator
62326232
image: NOOBAA_OPERATOR_IMAGE
62336233
terminationMessagePolicy: FallbackToLogsOnError
6234+
ports:
6235+
- name: readyz
6236+
containerPort: 8081
62346237
volumeMounts:
62356238
- name: bound-sa-token
62366239
mountPath: /var/run/secrets/openshift/serviceaccount
@@ -6240,6 +6243,29 @@ spec:
62406243
# SHOULD BE RETURNED ONCE COSI IS BACK
62416244
# - name: socket
62426245
# mountPath: /var/lib/cosi
6246+
readinessProbe:
6247+
httpGet:
6248+
path: /readyz
6249+
port: readyz
6250+
initialDelaySeconds: 5
6251+
periodSeconds: 10
6252+
timeoutSeconds: 5
6253+
failureThreshold: 3
6254+
livenessProbe:
6255+
httpGet:
6256+
path: /readyz
6257+
port: readyz
6258+
initialDelaySeconds: 15
6259+
periodSeconds: 10
6260+
timeoutSeconds: 5
6261+
failureThreshold: 3
6262+
startupProbe:
6263+
httpGet:
6264+
path: /readyz
6265+
port: readyz
6266+
periodSeconds: 10
6267+
timeoutSeconds: 5
6268+
failureThreshold: 30
62436269
resources:
62446270
limits:
62456271
cpu: "250m"
@@ -6923,4 +6949,3 @@ metadata:
69236949
app: prometheus-adapter
69246950
name: custom-metrics-prometheus-adapter
69256951
`
6926-

pkg/operator/manager.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/operator-framework/operator-lib/leader"
2626
"sigs.k8s.io/controller-runtime/pkg/cache"
27+
"sigs.k8s.io/controller-runtime/pkg/healthz"
2728
"sigs.k8s.io/controller-runtime/pkg/manager"
2829
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
2930
metricsServer "sigs.k8s.io/controller-runtime/pkg/metrics/server"
@@ -44,6 +45,11 @@ func RunOperator(cmd *cobra.Command, args []string) {
4445
util.InitLogger(logrus.DebugLevel)
4546
}
4647
version.RunVersion(cmd, args)
48+
// Probe address from CLI flag (defaults to :8081)
49+
probeAddr := os.Getenv("HEALTH_PROBE_BIND_ADDRESS")
50+
if probeAddr == "" {
51+
probeAddr = ":8081"
52+
}
4753

4854
config := util.KubeConfig()
4955

@@ -66,6 +72,7 @@ func RunOperator(cmd *cobra.Command, args []string) {
6672
Metrics: metricsServer.Options{
6773
BindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
6874
},
75+
HealthProbeBindAddress: probeAddr, // Serve /healthz and /readyz here
6976
})
7077
if err != nil {
7178
log.Fatalf("Failed to create manager: %s", err)
@@ -97,6 +104,11 @@ func RunOperator(cmd *cobra.Command, args []string) {
97104
log.Fatalf("Failed AddToClusterScopedManager: %s", err)
98105
}
99106

107+
// Register readiness endpoint on mgr
108+
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
109+
log.Fatalf("Failed to add readiness check: %s", err)
110+
}
111+
100112
util.Panic(mgr.Add(manager.RunnableFunc(func(ctx context.Context) error {
101113
system.RunOperatorCreate(cmd, args)
102114
return nil

0 commit comments

Comments
 (0)