Skip to content

Commit 4e1b572

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 aaf2d60 commit 4e1b572

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
@@ -6189,7 +6189,7 @@ spec:
61896189
sourceNamespace: default
61906190
`
61916191

6192-
const Sha256_deploy_operator_yaml = "aa8da1c289a05b3c94b9393b04307d38814a67625ac6a8006dace4d09366f35b"
6192+
const Sha256_deploy_operator_yaml = "1e940d1e2206f9b692fdcfa0f9bd80fe6a8247f70429216c359ec4851219c2e5"
61936193

61946194
const File_deploy_operator_yaml = `apiVersion: apps/v1
61956195
kind: Deployment
@@ -6234,6 +6234,13 @@ spec:
62346234
containers:
62356235
- name: noobaa-operator
62366236
image: NOOBAA_OPERATOR_IMAGE
6237+
args:
6238+
- operator
6239+
- run
6240+
- --health-probe-bind-address=:8081
6241+
ports:
6242+
- name: healthz
6243+
containerPort: 8081
62376244
volumeMounts:
62386245
- name: bound-sa-token
62396246
mountPath: /var/run/secrets/openshift/serviceaccount
@@ -6243,6 +6250,29 @@ spec:
62436250
# SHOULD BE RETURNED ONCE COSI IS BACK
62446251
# - name: socket
62456252
# mountPath: /var/lib/cosi
6253+
readinessProbe:
6254+
httpGet:
6255+
path: /readyz
6256+
port: healthz
6257+
initialDelaySeconds: 5
6258+
periodSeconds: 10
6259+
timeoutSeconds: 5
6260+
failureThreshold: 3
6261+
livenessProbe:
6262+
httpGet:
6263+
path: /healthz
6264+
port: healthz
6265+
initialDelaySeconds: 15
6266+
periodSeconds: 10
6267+
timeoutSeconds: 5
6268+
failureThreshold: 3
6269+
startupProbe:
6270+
httpGet:
6271+
path: /healthz
6272+
port: healthz
6273+
periodSeconds: 10
6274+
timeoutSeconds: 5
6275+
failureThreshold: 30
62466276
resources:
62476277
limits:
62486278
cpu: "250m"
@@ -6926,4 +6956,3 @@ metadata:
69266956
app: prometheus-adapter
69276957
name: custom-metrics-prometheus-adapter
69286958
`
6929-

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)