-
Notifications
You must be signed in to change notification settings - Fork 44
/
chronyc
executable file
·44 lines (41 loc) · 1.57 KB
/
chronyc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
# description: Checks if the worker clocks are synced using chronyc
[ -z ${UTILSFILE} ] && source $(echo "$(dirname ${0})/../utils")
tmperrorfile=$(mktemp)
trap "rm ${errorfile}" EXIT
echo 0 >$tmperrorfile
if oc auth can-i debug node >/dev/null 2>&1; then
msg "Collecting NTP data... (${BLUE}using oc debug, it can take a while${NOCOLOR})"
# shellcheck disable=SC2016
for node in $(oc get nodes -o go-template='{{range .items}}{{$node := .}}{{range .status.conditions}}{{if eq .type "Ready"}}{{if eq .status "True"}}node/{{$node.metadata.name}}{{"\n"}}{{end}}{{end}}{{end}}{{end}}'); do
# See https://medium.com/@robert.i.sandor/getting-started-with-parallelization-in-bash-e114f4353691
((i = i % PARALLELJOBS))
((i++ == 0)) && wait
(
# shellcheck disable=2016
ocdebugorwait # Pause for no OC debug running
if ! SOURCES=$(oc debug --image="${OCDEBUGIMAGE}" "${node}" -- chroot /host sh -c 'chronyc activity' 2>/dev/null | awk '/sources online/ { print $1 }'); then
msg "${ORANGE}Error running oc debug in ${node}${NOCOLOR}"
else
if [ -n "${SOURCES}" ] && [ "${SOURCES}" -lt 1 ]; then
msg "${RED}Clock doesn't seem to be synced in ${node}${NOCOLOR}"
echo 1 >$tmperrorfile
fi
fi
) &
done
wait
if [ "$(cat $tmperrorfile)" -eq 1 ]; then
errors=$(("${errors}" + 1))
if [ ! -z "${ERRORFILE}" ]; then
echo $errors >${ERRORFILE}
fi
exit ${OCERROR}
else
exit ${OCOK}
fi
else
msg "Couldn't debug nodes, check permissions"
exit ${OCSKIP}
fi
exit ${OCUNKNOWN}