Skip to content

Commit

Permalink
Collect nmstate resources when operator is installed
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Stäbler <cstabler@redhat.com>
  • Loading branch information
creydr committed Mar 16, 2022
1 parent bb7c3b4 commit 5cf76c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions collection-scripts/gather
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,8 @@ oc adm inspect --dest-dir must-gather --rotated-pod-logs "${group_resources_text
# Gather metallb logs
/usr/bin/gather_metallb_logs

# Gather NMState logs
/usr/bin/gather_nmstate_logs

# force disk flush to ensure that all data gathered is accessible in the copy container
sync
28 changes: 28 additions & 0 deletions collection-scripts/gather_nmstate_logs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
BASE_COLLECTION_PATH="must-gather"
NMSTATE_NS="$(oc get subs -A -o template --template '{{range .items}}{{if eq .spec.name "kubernetes-nmstate-operator"}}{{.metadata.namespace}}{{end}}{{end}}')"
NMSTATE_API_GROUP="nmstate.io"

if [ -z "${NMSTATE_NS}" ]; then
echo "INFO: NMState not detected. Skipping."
exit 0
fi

function get_nmstate_cr() {
declare -a NMSTATE_CRDS=("nmstates" "nodenetworkconfigurationenactments" "nodenetworkconfigurationpolicies" "nodenetworkstates")
for NMSTATE_CRD in "${NMSTATE_CRDS[@]}"; do
CR_PATH="${BASE_COLLECTION_PATH}/cluster-scoped-resources/${NMSTATE_API_GROUP}/${NMSTATE_CRD}"
mkdir -p ${CR_PATH}

for CR_NAME in $(oc get ${NMSTATE_CRD} -ojsonpath='{.items[*].metadata.name}'); do
oc get ${NMSTATE_CRD} ${CR_NAME} -o yaml > "${CR_PATH}/${CR_NAME}.yaml"
done
done
}

oc adm inspect --dest-dir must-gather "ns/${NMSTATE_NS}"

get_nmstate_cr

# force disk flush to ensure that all data gathered is accessible in the copy container
sync

0 comments on commit 5cf76c5

Please sign in to comment.