Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Adding OSCP 4 support to check_openshift_node #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion check_openshift_node
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,20 @@ check_condition() {
check_condition Ready true
check_condition DiskPressure false
check_condition MemoryPressure false
check_condition OutOfDisk false

# Get Kubernetes version
get_kube_ver

# Depending on the Kubernetes version include additional Node info
if [[ ${kube_major_ver} -ge 1 ]]; then
if [[ ${kube_minor_ver} -le 11 ]]; then
# OpenShift 3.x used up to Kubernetes 1.11
check_condition OutOfDisk false
elif [[ ${kube_minor_ver} -ge 12 ]]; then
# OpenShift 4.x starts at Kubernetes 1.12
check_condition PIDPressure false
fi
fi

finish "$exit_status" \
"$(join_args ', ' ${output[@]+"${output[@]}"})" \
Expand Down
34 changes: 33 additions & 1 deletion utils
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ readonly state_warning=1
readonly state_critical=2
readonly state_unknown=3

readonly OPENSHIFT_CLIENT_BINARY=/usr/bin/oc
# Set `oc` location
# dynamically locate `oc` with which, but if that fails fall back
# to static location of /usr/bin/oc
if which oc >> /dev/null 2>&1; then
readonly OPENSHIFT_CLIENT_BINARY=$(which oc)
else
readonly OPENSHIFT_CLIENT_BINARY=/usr/bin/oc
fi

#
# Print arguments joined by delimiter
Expand Down Expand Up @@ -169,4 +176,29 @@ finish() {
exit "$exit_status"
}

#
# Determine Kubernetes version
#
get_kube_ver() {
# oc >= 4 has `oc version -o json` however oc <= 3 does not
# so we need to parse stdout to figure out what version is being used
oc_ver_out=$(run_oc "$opt_cfgfile" version)
if echo "${oc_ver_out}" | grep -q 'kubernetes'; then
# OpenShift 3 formatting
kube_major_ver=$(echo "${oc_ver_out}" | grep 'kubernetes' | cut -d' ' -f 2 | cut -d'v' -f 2 | cut -d'+' -f 1 | tail -n1 | cut -d'.' -f 1)
export kube_major_ver
kube_minor_ver=$(echo "${oc_ver_out}" | grep 'kubernetes' | cut -d' ' -f 2 | cut -d'v' -f 2 | cut -d'+' -f 1 | tail -n1 | cut -d'.' -f 2)
export kube_minor_ver
elif echo "${oc_ver_out}" | grep -q 'Kubernetes Version'; then
# OpenShift 4 formatting
kube_major_ver=$(echo "${oc_ver_out}" | grep 'Kubernetes' | cut -d' ' -f 3 | cut -d'v' -f 2 | cut -d'+' -f 1 | tail -n1 | cut -d'.' -f 1)
export kube_major_ver
kube_minor_ver=$(echo "${oc_ver_out}" | grep 'Kubernetes' | cut -d' ' -f 3 | cut -d'v' -f 2 | cut -d'+' -f 1 | tail -n1 | cut -d'.' -f 2)
export kube_minor_ver
else
output+=( "Could not determine Kubernetes version" )
exit_status=$(merge_status "$exit_status" "$state_critical")
fi
}

# vim: set sw=2 sts=2 et :