Skip to content

Commit 5af377d

Browse files
qbarrandmresvanis
andauthored
Collect objects for both KMM and KMM-Hub (kubernetes-sigs#363)
Add the -u option to collect Hub objects. Default to the `openshit-operators` namespace. Simplify the collection logic. Co-authored-by: Michail Resvanis <[email protected]> Co-authored-by: Michail Resvanis <[email protected]>
1 parent be35d90 commit 5af377d

File tree

1 file changed

+61
-40
lines changed

1 file changed

+61
-40
lines changed

must-gather/gather

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,76 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

3-
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
4-
OUTPUT_DIR="${OUTPUT_DIR:-must-gather/${TIMESTAMP}}"
3+
OUTPUT_DIR="${OUTPUT_DIR:-must-gather/$(date +%Y%m%d_%H%M%S)}"
4+
readonly OUTPUT_DIR
55

6-
NS="${NS:-kmm-operator-system}"
6+
HUB=false
7+
NS=openshift-operators
78

8-
mkdir -p "$OUTPUT_DIR"
9-
10-
for resource in $(oc get all -n "$NS" --no-headers | awk '{print $1}'); do
11-
type=$(echo "$resource" | cut -d'/' -f1 )
12-
name=$(echo "$resource" | cut -d'/' -f2 )
9+
readonly COMMON_KINDS='clusterrolebindings,configmaps,events,pods,secrets,roles,rolebindings,serviceaccounts'
10+
readonly BUILD_KINDS="${COMMON_KINDS},builds,jobs.batch"
1311

14-
echo "Inspecting ${resource}"
15-
oc adm inspect -n "$NS" "$resource" --dest-dir="$OUTPUT_DIR/inspect"
12+
collect_common() {
13+
echo "Collecting common objects"
1614

17-
echo "Collecting information for ${resource}"
18-
describeFile="${OUTPUT_DIR}/${type}_${name}.yaml"
19-
oc -n "$NS" describe "$resource" > "$describeFile"
20-
done
15+
oc adm inspect clusterversions.config.openshift.io/version --dest-dir="$OUTPUT_DIR/inspect"
16+
oc adm inspect crd,images --dest-dir="$OUTPUT_DIR/inspect"
2117

22-
echo "Collecting logs from 'deployment/kmm-operator-controller-manager'"
23-
oc -n "$NS" logs "deployment/kmm-operator-controller-manager" > "${OUTPUT_DIR}/kmm-operator-controller-manager.log"
18+
oc adm inspect \
19+
-n "$NS" \
20+
"${COMMON_KINDS},deployment.apps,services" \
21+
--dest-dir="$OUTPUT_DIR/inspect"
2422

25-
echo "Inspecting modules.kmm.sigs.x-k8s.io in all the namespaces"
26-
oc adm inspect -A crd/modules.kmm.sigs.x-k8s.io --dest-dir="$OUTPUT_DIR/inspect"
23+
oc adm inspect imagestreams -n openshift driver-toolkit --dest-dir="$OUTPUT_DIR/inspect"
24+
}
2725

28-
echo "Inspecting all Modules in all namespaces"
29-
oc adm inspect -A modules.kmm.sigs.x-k8s.io --dest-dir="$OUTPUT_DIR/inspect"
26+
collect() {
27+
echo "Collecting KMM objects and logs"
3028

31-
namespaces=$(oc get daemonset -A -l kmm.node.kubernetes.io/module.name --no-headers -o custom-columns="NS:.metadata.namespace")
32-
IFS=" " read -r -a namespaces <<< "$(echo "${namespaces[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')"
33-
for ns in "${namespaces[@]}"; do
34-
echo "Inspecting DaemonSet in '${ns}' namespace"
35-
oc adm inspect -n "$ns" daemonset.apps --dest-dir="$OUTPUT_DIR/inspect"
29+
oc adm inspect modules,preflightvalidations,preflightvalidationsocp -A --dest-dir="$OUTPUT_DIR/inspect"
30+
oc adm inspect clusterclaims --dest-dir="$OUTPUT_DIR/inspect"
3631

37-
echo "Inspecting RBAC for DaemonSets in '${ns}' namespace"
38-
for sa in $(oc get daemonset -n "${ns}" -l kmm.node.kubernetes.io/module.name --no-headers -o custom-columns="SA:.spec.template.spec.serviceAccountName"); do
39-
oc adm inspect -n "${ns}" serviceaccounts "${sa}" --dest-dir="${OUTPUT_DIR}/inspect"
32+
oc -n "$NS" logs "deployment/kmm-operator-controller-manager" > "${OUTPUT_DIR}/kmm-operator-controller-manager.log"
4033

41-
rbac=$(oc get rolebinding,clusterrolebinding -n simple-kmod \
42-
-o jsonpath="{range .items[?(@.subjects[0].name=='${sa}')]}{.kind}{' '}{.metadata.name}{'\n'}{.roleRef.kind}{' '}{.roleRef.name}{'\n'}{end}")
34+
namespaces=$(oc get daemonset -A -l kmm.node.kubernetes.io/module.name --no-headers -o custom-columns="NS:.metadata.namespace")
35+
IFS=" " read -r -a namespaces <<< "$(echo "${namespaces[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')"
36+
for ns in "${namespaces[@]}"; do
37+
echo "Collecting data in namespace ${ns}"
4338

44-
echo "${rbac}" | while read -r line; do
45-
resourceType="$(echo "${line}" | cut -d' ' -f1)"
46-
name="$(echo "${line}" | cut -d' ' -f2)"
47-
oc adm inspect -n "${ns}" "${resourceType}" "${name}" --dest-dir="${OUTPUT_DIR}/inspect"
48-
done
39+
oc adm inspect -n "$ns" "daemonset.apps,${BUILD_KINDS}" --dest-dir="$OUTPUT_DIR/inspect"
4940
done
50-
done
41+
}
42+
43+
collect_hub() {
44+
echo "Collecting KMM-Hub objects and logs"
45+
46+
oc adm inspect managedclustermodules,managedclusters --dest-dir="$OUTPUT_DIR/inspect"
47+
oc adm inspect manifestworks -A --dest-dir="$OUTPUT_DIR/inspect"
48+
oc adm inspect "${BUILD_KINDS}" -A --dest-dir="$OUTPUT_DIR/inspect"
5149

52-
for ns in $(oc get job -A -l kmm.node.kubernetes.io/module.name --no-headers -o custom-columns="NS:.metadata.namespace"); do
53-
echo "Inspecting job in '${ns}' namespace"
54-
oc adm inspect -n "$ns" job.batch --dest-dir="$OUTPUT_DIR/inspect"
50+
oc -n "$NS" logs "deployment.apps/kmm-operator-hub-controller-manager" > "${OUTPUT_DIR}/kmm-operator-hub-controller-manager.log"
51+
}
52+
53+
while getopts "hn:u" arg; do
54+
case $arg in
55+
n)
56+
NS="${OPTARG}"
57+
;;
58+
u)
59+
HUB=true
60+
;;
61+
h | *) # Display help.
62+
echo 'Usage: gather [ -n NAMESPACE ] [ -u ]'
63+
exit 0
64+
;;
65+
esac
5566
done
67+
68+
mkdir -p "$OUTPUT_DIR"
69+
70+
collect_common
71+
72+
if [ $HUB == true ]; then
73+
collect_hub
74+
else
75+
collect
76+
fi

0 commit comments

Comments
 (0)