Skip to content

Commit e07011f

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 e07011f

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

deploy/operator.yaml

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

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func CmdRun() *cobra.Command {
9797
Run: RunOperator,
9898
Args: cobra.NoArgs,
9999
}
100+
cmd.Flags().String("health-probe-bind-address", ":8081", "HTTP address for health/readiness probes (e.g., :8081)")
100101
return cmd
101102
}
102103

0 commit comments

Comments
 (0)