-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathlocks
executable file
·35 lines (32 loc) · 1.33 KB
/
locks
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
#!/usr/bin/env bash
# description: List all pods with locks on each node
ORIG_IFS=$IFS
IFS=$(echo -en "\n\b")
SCRIPT64=$(cat ./scripts/locks.sh | base64 -w 0)
[ -z ${UTILSFILE} ] && source $(echo "$(dirname ${0})/../utils")
if oc auth can-i debug node >/dev/null 2>&1; then
msg "Checking for locks by pod, per node (${BLUE}using oc debug, it can take a while${NOCOLOR})"
fw_errors=0
# 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
ocdebugorwait # Pause for no OC debug running
# shellcheck disable=SC1083
if ! FILE_LOCKS=$(oc debug --image="${OCDEBUGIMAGE}" "${node}" -- chroot /host sh -c "echo $SCRIPT64 | base64 -d > /tmp/locks.sh; chmod 755 /tmp/locks.sh; /tmp/locks.sh; rm -f /tmp/locks.sh"); then
msg "${ORANGE}Error running oc debug in ${node}${NOCOLOR}"
else
if [ -n "${FILE_LOCKS}" ]; then
msg "File locks found on ${RED}${node}${NOCOLOR}"
for line in ${FILE_LOCKS}; do
echo $line
done
else
msg "Couldn't check for locks on ${node}"
fi
fi
done
exit ${OCINFO}
else
msg "Couldn't debug nodes, check permissions"
exit ${OCSKIP}
fi
exit ${OCUNKNOWN}