Skip to content

Commit d6114e4

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 5727239 commit d6114e4

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
@@ -601,20 +601,40 @@ spec:
601601
fieldPath: metadata.annotations['olm.targetNamespaces']
602602
image: quay.io/ocs-dev/ocs-operator:latest
603603
imagePullPolicy: Always
604+
livenessProbe:
605+
failureThreshold: 3
606+
httpGet:
607+
path: /healthz
608+
port: healthz
609+
initialDelaySeconds: 15
610+
periodSeconds: 10
611+
timeoutSeconds: 5
604612
name: ocs-operator
613+
ports:
614+
- containerPort: 8081
615+
name: healthz
605616
readinessProbe:
617+
failureThreshold: 3
606618
httpGet:
607619
path: /readyz
608-
port: 8081
620+
port: healthz
609621
initialDelaySeconds: 5
610622
periodSeconds: 10
623+
timeoutSeconds: 5
611624
resources: {}
612625
securityContext:
613626
allowPrivilegeEscalation: false
614627
capabilities:
615628
drop:
616629
- all
617630
readOnlyRootFilesystem: true
631+
startupProbe:
632+
failureThreshold: 30
633+
httpGet:
634+
path: /healthz
635+
port: healthz
636+
periodSeconds: 10
637+
timeoutSeconds: 5
618638
terminationMessagePolicy: FallbackToLogsOnError
619639
volumeMounts:
620640
- 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
@@ -640,13 +640,26 @@ spec:
640640
fieldPath: metadata.namespace
641641
image: quay.io/ocs-dev/ocs-operator:latest
642642
imagePullPolicy: Always
643+
livenessProbe:
644+
failureThreshold: 3
645+
httpGet:
646+
path: /healthz
647+
port: healthz
648+
initialDelaySeconds: 15
649+
periodSeconds: 10
650+
timeoutSeconds: 5
643651
name: ocs-operator
652+
ports:
653+
- containerPort: 8081
654+
name: healthz
644655
readinessProbe:
656+
failureThreshold: 3
645657
httpGet:
646658
path: /readyz
647-
port: 8081
659+
port: healthz
648660
initialDelaySeconds: 5
649661
periodSeconds: 10
662+
timeoutSeconds: 5
650663
resources:
651664
limits:
652665
cpu: 250m
@@ -660,6 +673,13 @@ spec:
660673
drop:
661674
- all
662675
readOnlyRootFilesystem: true
676+
startupProbe:
677+
failureThreshold: 30
678+
httpGet:
679+
path: /healthz
680+
port: healthz
681+
periodSeconds: 10
682+
timeoutSeconds: 5
663683
terminationMessagePolicy: FallbackToLogsOnError
664684
volumeMounts:
665685
- mountPath: /etc/private-key

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import (
6060
ctrl "sigs.k8s.io/controller-runtime"
6161
"sigs.k8s.io/controller-runtime/pkg/cache"
6262
apiclient "sigs.k8s.io/controller-runtime/pkg/client"
63+
"sigs.k8s.io/controller-runtime/pkg/healthz"
6364
"sigs.k8s.io/controller-runtime/pkg/log/zap"
6465
"sigs.k8s.io/controller-runtime/pkg/manager"
6566
metrics "sigs.k8s.io/controller-runtime/pkg/metrics/server"
@@ -311,6 +312,12 @@ func main() {
311312
os.Exit(1)
312313
}
313314

315+
// Liveness (/healthz)
316+
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
317+
setupLog.Error(err, "unable to add a health check")
318+
os.Exit(1)
319+
}
320+
314321
// Add readiness probe
315322
if err := mgr.AddReadyzCheck("readyz", storagecluster.ReadinessChecker); err != nil {
316323
setupLog.Error(err, "unable add a readiness check")

0 commit comments

Comments
 (0)