Skip to content

Commit 3eb84c9

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 e0a1a8d commit 3eb84c9

File tree

4 files changed

+77
-2
lines changed

4 files changed

+77
-2
lines changed

deploy/operator.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ spec:
4141
containers:
4242
- name: noobaa-operator
4343
image: NOOBAA_OPERATOR_IMAGE
44+
args:
45+
- operator
46+
- run
47+
- --health-probe-bind-address=:8081
48+
ports:
49+
- name: healthz
50+
containerPort: 8081
4451
volumeMounts:
4552
- name: bound-sa-token
4653
mountPath: /var/run/secrets/openshift/serviceaccount
@@ -50,6 +57,29 @@ spec:
5057
# SHOULD BE RETURNED ONCE COSI IS BACK
5158
# - name: socket
5259
# mountPath: /var/lib/cosi
60+
readinessProbe:
61+
httpGet:
62+
path: /readyz
63+
port: healthz
64+
initialDelaySeconds: 5
65+
periodSeconds: 10
66+
timeoutSeconds: 5
67+
failureThreshold: 3
68+
livenessProbe:
69+
httpGet:
70+
path: /healthz
71+
port: healthz
72+
initialDelaySeconds: 15
73+
periodSeconds: 10
74+
timeoutSeconds: 5
75+
failureThreshold: 3
76+
startupProbe:
77+
httpGet:
78+
path: /healthz
79+
port: healthz
80+
periodSeconds: 10
81+
timeoutSeconds: 5
82+
failureThreshold: 30
5383
resources:
5484
limits:
5585
cpu: "250m"

pkg/bundle/deploy.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6187,7 +6187,7 @@ spec:
61876187
sourceNamespace: default
61886188
`
61896189

6190-
const Sha256_deploy_operator_yaml = "aa8da1c289a05b3c94b9393b04307d38814a67625ac6a8006dace4d09366f35b"
6190+
const Sha256_deploy_operator_yaml = "1e940d1e2206f9b692fdcfa0f9bd80fe6a8247f70429216c359ec4851219c2e5"
61916191

61926192
const File_deploy_operator_yaml = `apiVersion: apps/v1
61936193
kind: Deployment
@@ -6232,6 +6232,13 @@ spec:
62326232
containers:
62336233
- name: noobaa-operator
62346234
image: NOOBAA_OPERATOR_IMAGE
6235+
args:
6236+
- operator
6237+
- run
6238+
- --health-probe-bind-address=:8081
6239+
ports:
6240+
- name: healthz
6241+
containerPort: 8081
62356242
volumeMounts:
62366243
- name: bound-sa-token
62376244
mountPath: /var/run/secrets/openshift/serviceaccount
@@ -6241,6 +6248,29 @@ spec:
62416248
# SHOULD BE RETURNED ONCE COSI IS BACK
62426249
# - name: socket
62436250
# mountPath: /var/lib/cosi
6251+
readinessProbe:
6252+
httpGet:
6253+
path: /readyz
6254+
port: healthz
6255+
initialDelaySeconds: 5
6256+
periodSeconds: 10
6257+
timeoutSeconds: 5
6258+
failureThreshold: 3
6259+
livenessProbe:
6260+
httpGet:
6261+
path: /healthz
6262+
port: healthz
6263+
initialDelaySeconds: 15
6264+
periodSeconds: 10
6265+
timeoutSeconds: 5
6266+
failureThreshold: 3
6267+
startupProbe:
6268+
httpGet:
6269+
path: /healthz
6270+
port: healthz
6271+
periodSeconds: 10
6272+
timeoutSeconds: 5
6273+
failureThreshold: 30
62446274
resources:
62456275
limits:
62466276
cpu: "250m"
@@ -6924,4 +6954,3 @@ metadata:
69246954
app: prometheus-adapter
69256955
name: custom-metrics-prometheus-adapter
69266956
`
6927-

pkg/operator/manager.go

Lines changed: 14 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,8 @@ 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, _ := cmd.Flags().GetString("health-probe-bind-address")
4750

4851
config := util.KubeConfig()
4952

@@ -66,6 +69,7 @@ func RunOperator(cmd *cobra.Command, args []string) {
6669
Metrics: metricsServer.Options{
6770
BindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
6871
},
72+
HealthProbeBindAddress: probeAddr, // Serve /healthz and /readyz here
6973
})
7074
if err != nil {
7175
log.Fatalf("Failed to create manager: %s", err)
@@ -97,6 +101,16 @@ func RunOperator(cmd *cobra.Command, args []string) {
97101
log.Fatalf("Failed AddToClusterScopedManager: %s", err)
98102
}
99103

104+
// Register health and readiness endpoints on mgr
105+
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
106+
log.Fatalf("Failed to add health check: %s", err)
107+
}
108+
109+
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
110+
log.Fatalf("Failed to add readiness check: %s", err)
111+
}
112+
113+
100114
util.Panic(mgr.Add(manager.RunnableFunc(func(ctx context.Context) error {
101115
system.RunOperatorCreate(cmd, args)
102116
return nil

pkg/operator/operator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ func Cmd() *cobra.Command {
3333
Use: "operator",
3434
Short: "Deployment using operator",
3535
}
36+
// health-probe flag available on operator and inherited by subcommands
37+
cmd.PersistentFlags().String("health-probe-bind-address", ":8081", "HTTP address for health/readiness probes (e.g., :8081)")
3638
cmd.AddCommand(
3739
CmdInstall(),
3840
CmdUninstall(),

0 commit comments

Comments
 (0)