@@ -16,6 +16,7 @@ usage() {
16
16
17
17
Options are:
18
18
-m MODE Which check to perform
19
+ -M EXIT_CODE Override default exit code when resource is missing
19
20
-H APISERVER API URL to query, kubectl is used if this option is not set
20
21
-T TOKEN Authorization token for API
21
22
-t TOKENFILE Path to file with token in it
@@ -37,15 +38,15 @@ usage() {
37
38
Modes are:
38
39
apiserver Not for kubectl, should be used for each apiserver independently
39
40
components Check for health of k8s components (etcd, controller-manager, scheduler etc.)
41
+ daemonsets Check for daemonsets readiness
42
+ deployments Check for deployments availability
43
+ jobs Check for failed jobs
40
44
nodes Check for active nodes
41
45
pods Check for restart count of containters in the pods
42
- deployments Check for deployments availability
43
- daemonsets Check for daemonsets readiness
44
- unboundpvs Check for unbound persistent volumes.
45
46
replicasets Check for replicasets readiness
46
47
statefulsets Check for statefulsets readiness
47
48
tls Check for tls secrets expiration dates
48
- jobs Check for failed jobs
49
+ unboundpvs Check for unbound persistent volumes.
49
50
EOF
50
51
51
52
exit 2
@@ -63,10 +64,11 @@ die() {
63
64
exit " ${2:- 2} "
64
65
}
65
66
66
- while getopts " :m:H:T:t:K:N:n:o:c:w:bh" arg; do
67
+ while getopts " :m:M: H:T:t:K:N:n:o:c:w:bh" arg; do
67
68
case $arg in
68
69
h) usage ;;
69
70
m) MODE=" $OPTARG " ;;
71
+ M) MISSING=" ${OPTARG} " ;;
70
72
o) TIMEOUT=" ${OPTARG} " ;;
71
73
H) APISERVER=" ${OPTARG%/ } " ;;
72
74
T) TOKEN=" $OPTARG " ;;
@@ -180,7 +182,7 @@ mode_nodes() {
180
182
if [ $EXITCODE = 0 ]; then
181
183
if [ -z " ${nodes[*]} " ]; then
182
184
OUTPUT=" No nodes found"
183
- EXITCODE=2
185
+ [ -z ${MISSING} ] && EXITCODE=2 || EXITCODE= ${MISSING}
184
186
else
185
187
OUTPUT=" OK. ${# nodes[@]} nodes are Ready"
186
188
BRIEF_OUTPUT=" ${# nodes[@]} "
@@ -213,7 +215,7 @@ mode_components() {
213
215
if [ $EXITCODE = 0 ]; then
214
216
if [ -z " ${components[*]} " ]; then
215
217
OUTPUT=" No components found"
216
- EXITCODE=2
218
+ [ -z ${MISSING} ] && EXITCODE=2 || EXITCODE= ${MISSING}
217
219
else
218
220
OUTPUT=" OK. Healthy: $healthy_comps "
219
221
fi
@@ -312,7 +314,7 @@ mode_tls() {
312
314
if [ $EXITCODE = 0 ]; then
313
315
if [ -z " $ns " ]; then
314
316
OUTPUT=" No TLS certs found"
315
- EXITCODE=2
317
+ [ -z ${MISSING} ] && EXITCODE=2 || EXITCODE= ${MISSING}
316
318
else
317
319
if [ $count_ok -gt 1 ]; then
318
320
OUTPUT=" OK. $count_ok TLS secrets are OK"
@@ -397,7 +399,7 @@ mode_pods() {
397
399
398
400
if [ -z " $ns " ]; then
399
401
OUTPUT=" No pods found"
400
- EXITCODE=2
402
+ [ -z ${MISSING} ] && EXITCODE=2 || EXITCODE= ${MISSING}
401
403
else
402
404
if [ " $max_restart_count " -ge " $WARN " ]; then
403
405
OUTPUT=" Container $bad_container : $max_restart_count restarts. "
@@ -448,7 +450,7 @@ mode_deployments() {
448
450
if [ $EXITCODE = 0 ]; then
449
451
if [ -z " $ns " ]; then
450
452
OUTPUT=" No deployments found"
451
- EXITCODE=2
453
+ [ -z ${MISSING} ] && EXITCODE=2 || EXITCODE= ${MISSING}
452
454
else
453
455
if [ $count_avail -gt 1 ]; then
454
456
OUTPUT=" OK. $count_avail deploymens are available"
@@ -509,7 +511,7 @@ mode_daemonsets() {
509
511
if [ $EXITCODE = 0 ]; then
510
512
if [ -z " $ns " ]; then
511
513
OUTPUT=" No daemonsets found"
512
- EXITCODE=2
514
+ [ -z ${MISSING} ] && EXITCODE=2 || EXITCODE= ${MISSING}
513
515
else
514
516
if [ $count_avail -gt 1 ]; then
515
517
OUTPUT=" OK. $count_avail daemonsets are ready"
@@ -571,7 +573,7 @@ mode_replicasets() {
571
573
if [ $EXITCODE = 0 ]; then
572
574
if [ -z " $ns " ]; then
573
575
OUTPUT=" No replicasets found"
574
- EXITCODE=2
576
+ [ -z ${MISSING} ] && EXITCODE=2 || EXITCODE= ${MISSING}
575
577
else
576
578
if [ $count_avail -gt 1 ]; then
577
579
OUTPUT=" OK. $count_avail replicasets are ready"
@@ -634,7 +636,7 @@ mode_statefulsets() {
634
636
if [ $EXITCODE = 0 ]; then
635
637
if [ -z " $ns " ]; then
636
638
OUTPUT=" No statefulsets found"
637
- EXITCODE=2
639
+ [ -z ${MISSING} ] && EXITCODE=2 || EXITCODE= ${MISSING}
638
640
else
639
641
if [ $count_avail -gt 1 ]; then
640
642
OUTPUT=" OK. $count_avail statefulsets are ready"
0 commit comments