forked from RHsyseng/openshift-checks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmtu
48 lines (47 loc) · 3.18 KB
/
mtu
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
45
46
47
48
#!/usr/bin/env bash
if oc auth can-i get network/cluster > /dev/null 2>&1; then
network_type=$(oc get network/cluster -ojson | jq -r .status.networkType)
if [[ $network_type != "OVNKubernetes" ]]; then
msg "MTU checks not supported yet for clusters using $network_type"
else
# If the crd doesn't exist it will return 0 if you are cluster-admin as you have permissions to get *
# So it is needed to 'get' the object as well to verify it does exist
if oc auth can-i get nodenetworkstates.nmstate.io -A > /dev/null 2>&1 && oc get nodenetworkstates.nmstate.io -o jsonpath='{.items[*].metadata.name}' > /dev/null 2>&1; then
# We need to split the next command using spaces, hence, using standard IFS
OLDIFS=$IFS
IFS=$' \t\n'
for nns in $(oc get nodenetworkstates.nmstate.io -o jsonpath='{.items[*].metadata.name}'); do
NNS=$(oc get nodenetworkstates.nmstate.io "${nns}" -o json 2> /dev/null)
BREXMTU=$(echo "${NNS}" | jq '.status.currentState.interfaces[] | select(.name == "br-ex" and .type == "ovs-interface") | .mtu')
BREXPHYSINT=$(echo "${NNS}" | jq -r '.status.currentState.interfaces[] | select(.name == "br-ex" and .type == "ovs-bridge") | .bridge.port[] | select(.name != "br-ex") | .name')
PHYSINTMTU=$(echo "${NNS}" | jq ".status.currentState.interfaces[] | select(.name == \"${BREXPHYSINT}\") | .mtu")
OVNK8SMP0MTU=$(echo "${NNS}" | jq '.status.currentState.interfaces[] | select(.name == "ovn-k8s-mp0") | .mtu')
msg "${nns} => br-ex:${BREXMTU}, ${BREXPHYSINT}:${PHYSINTMTU}, ovn-k8s-mp0:${OVNK8SMP0MTU}"
done
IFS=${OLDIFS}
else
if oc auth can-i debug node -A > /dev/null 2>&1 && oc auth can-i get nodes > /dev/null 2>&1; then
msg "Collecting MTUs... (${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
# Get all the information in a single debug to avoid rescheduling unneeded pods
# then convert the output into an array for easily consumption
# shellcheck disable=2016
mapfile -t MTUS < <( oc debug --image="${OCDEBUGIMAGE}" "${node}" -- chroot /host sh -c 'export EXTBR="br-ex"; export OVNBR="ovn-k8s-mp0"; export BMINTERFACE=$(ovs-vsctl list-ports "${EXTBR}" | grep -v patch) ; echo "${BMINTERFACE}"; nmcli -g GENERAL.MTU dev show "${BMINTERFACE}"; nmcli -g GENERAL.MTU dev show "${EXTBR}"; nmcli -g GENERAL.MTU dev show "${OVNBR}"' 2> /dev/null )
# If the array is empty, something has happened
if [ ${#MTUS[@]} -eq 0 ]; then
msg "${YELLOW}Couldn't get MTU settings in ${node}${NOCOLOR}"
else
# MTUS[0] = Baremetal interface name
# MTUS[1] = Baremetal interface MTU
# MTUS[2] = br-ex MTU
# MTUS[3] = ovn-k8s-mp0 MTU
msg "${node} => br-ex:${MTUS[2]}, ${MTUS[0]}:${MTUS[1]}, ovn-k8s-mp0: ${MTUS[3]}"
fi
done
fi
fi
fi
else
msg "Couldn't debug nodes, check permissions"
fi