Skip to content

Commit 68ac93e

Browse files
committed
Add liveness probe to OCS Operator
- Register /healthz endpoint in main.go - Add liveness, readiness, and startup probes to manager Deployment Signed-off-by: Oded Viner <[email protected]>
1 parent bc932b9 commit 68ac93e

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
lines changed

config/manager/manager.yaml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ spec:
3030
image: ocs-dev/ocs-operator:latest
3131
imagePullPolicy: Always
3232
name: ocs-operator
33+
ports:
34+
- name: healthz
35+
containerPort: 8081
3336
env:
3437
- name: WATCH_NAMESPACE
3538
valueFrom:
@@ -38,13 +41,30 @@ spec:
3841
readinessProbe:
3942
httpGet:
4043
path: /readyz
41-
port: 8081
44+
port: healthz
4245
initialDelaySeconds: 5
4346
periodSeconds: 10
47+
timeoutSeconds: 5
48+
failureThreshold: 3
49+
livenessProbe:
50+
httpGet:
51+
path: /healthz
52+
port: healthz
53+
initialDelaySeconds: 15
54+
periodSeconds: 10
55+
timeoutSeconds: 5
56+
failureThreshold: 3
57+
startupProbe:
58+
httpGet:
59+
path: /healthz
60+
port: healthz
61+
periodSeconds: 10
62+
timeoutSeconds: 5
63+
failureThreshold: 30
4464
securityContext:
4565
allowPrivilegeEscalation: false
4666
capabilities:
47-
drop:
67+
drop:
4868
- all
4969
readOnlyRootFilesystem: true
5070
terminationMessagePolicy: FallbackToLogsOnError

deploy/csv-templates/ocs-operator.csv.yaml.in

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,20 +624,40 @@ spec:
624624
fieldPath: metadata.annotations['olm.targetNamespaces']
625625
image: quay.io/ocs-dev/ocs-operator:latest
626626
imagePullPolicy: Always
627+
livenessProbe:
628+
failureThreshold: 3
629+
httpGet:
630+
path: /healthz
631+
port: healthz
632+
initialDelaySeconds: 15
633+
periodSeconds: 10
634+
timeoutSeconds: 5
627635
name: ocs-operator
636+
ports:
637+
- containerPort: 8081
638+
name: healthz
628639
readinessProbe:
640+
failureThreshold: 3
629641
httpGet:
630642
path: /readyz
631-
port: 8081
643+
port: healthz
632644
initialDelaySeconds: 5
633645
periodSeconds: 10
646+
timeoutSeconds: 5
634647
resources: {}
635648
securityContext:
636649
allowPrivilegeEscalation: false
637650
capabilities:
638651
drop:
639652
- all
640653
readOnlyRootFilesystem: true
654+
startupProbe:
655+
failureThreshold: 30
656+
httpGet:
657+
path: /healthz
658+
port: healthz
659+
periodSeconds: 10
660+
timeoutSeconds: 5
641661
terminationMessagePolicy: FallbackToLogsOnError
642662
volumeMounts:
643663
- mountPath: /etc/private-key

deploy/ocs-operator/manifests/ocs-operator.clusterserviceversion.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,13 +663,26 @@ spec:
663663
fieldPath: metadata.namespace
664664
image: quay.io/ocs-dev/ocs-operator:latest
665665
imagePullPolicy: Always
666+
livenessProbe:
667+
failureThreshold: 3
668+
httpGet:
669+
path: /healthz
670+
port: healthz
671+
initialDelaySeconds: 15
672+
periodSeconds: 10
673+
timeoutSeconds: 5
666674
name: ocs-operator
675+
ports:
676+
- containerPort: 8081
677+
name: healthz
667678
readinessProbe:
679+
failureThreshold: 3
668680
httpGet:
669681
path: /readyz
670-
port: 8081
682+
port: healthz
671683
initialDelaySeconds: 5
672684
periodSeconds: 10
685+
timeoutSeconds: 5
673686
resources:
674687
limits:
675688
cpu: 250m
@@ -683,6 +696,13 @@ spec:
683696
drop:
684697
- all
685698
readOnlyRootFilesystem: true
699+
startupProbe:
700+
failureThreshold: 30
701+
httpGet:
702+
path: /healthz
703+
port: healthz
704+
periodSeconds: 10
705+
timeoutSeconds: 5
686706
terminationMessagePolicy: FallbackToLogsOnError
687707
volumeMounts:
688708
- mountPath: /etc/private-key

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import (
6161
ctrl "sigs.k8s.io/controller-runtime"
6262
"sigs.k8s.io/controller-runtime/pkg/cache"
6363
apiclient "sigs.k8s.io/controller-runtime/pkg/client"
64+
"sigs.k8s.io/controller-runtime/pkg/healthz"
6465
"sigs.k8s.io/controller-runtime/pkg/log/zap"
6566
"sigs.k8s.io/controller-runtime/pkg/manager"
6667
metrics "sigs.k8s.io/controller-runtime/pkg/metrics/server"
@@ -305,6 +306,12 @@ func main() {
305306
os.Exit(1)
306307
}
307308

309+
// Liveness (/healthz)
310+
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
311+
setupLog.Error(err, "unable to add a health check")
312+
os.Exit(1)
313+
}
314+
308315
// Add readiness probe
309316
if err := mgr.AddReadyzCheck("readyz", storagecluster.ReadinessChecker); err != nil {
310317
setupLog.Error(err, "unable add a readiness check")

0 commit comments

Comments
 (0)