Skip to content

Commit f8b55e4

Browse files
committed
fix(gather_gitops.sh): Unquote process substitutions delivering lists
Signed-off-by: Oliver Gondža <ogondza@gmail.com>
1 parent 5286512 commit f8b55e4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

gather_gitops.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#!/usr/bin/env bash
22

33
set -eu -o pipefail
4+
trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
45

56
LOGS_DIR="/must-gather"
67

78
mkdir -p ${LOGS_DIR}
89

910
GITOPS_CURRENT_CSV=$(oc get subscription.operators.coreos.com --ignore-not-found -A -o json | jq '.items[] | select(.metadata.name=="openshift-gitops-operator") | .status.currentCSV' -r)
11+
readarray -t NON_ARGO_CRDS < <(oc get csv --ignore-not-found "$GITOPS_CURRENT_CSV" -o json | jq '.spec.customresourcedefinitions.owned[] | select(.name | contains("argoproj.io") | not) | " " + .name' -rj)
1012

1113
# Gathering cluster version all the crd related to operators.coreos.com and argoproj.io
1214
echo "gather_gitops:$LINENO] inspecting crd, clusterversion .." | tee -a ${LOGS_DIR}/gather_gitops.log
1315
# Getting non.existent.crd is a hack to avoid getting all available crds in the cluster in case there are no owned resources that do not contain "argoproj.io"
14-
oc adm inspect --dest-dir=${LOGS_DIR} "$(oc get crd -o name | grep -Ei "argoproj.io|operators.coreos.com")" "$(oc get crd non.existent.crd --ignore-not-found "$(oc get csv --ignore-not-found "$GITOPS_CURRENT_CSV" -o json | jq '.spec.customresourcedefinitions.owned[] | select(.name | contains("argoproj.io") | not) | " " + .name' -rj)" -o name)" clusterversion/version > /dev/null
16+
oc adm inspect --dest-dir=${LOGS_DIR} $(oc get crd -o name | grep -Ei "argoproj.io|operators.coreos.com") $(oc get crd non.existent.crd --ignore-not-found "${NON_ARGO_CRDS[@]}" -o name) clusterversion/version > /dev/null
1517

1618
# Gathering all namespaced custom resources across the cluster that contains "argoproj.io" related custom resources
1719
oc get crd -o json | jq -r '.items[] | select((.spec.group | contains ("argoproj.io")) and .spec.scope=="Namespaced") | .spec.group + " " + .metadata.name + " " + .spec.names.plural' |
@@ -26,7 +28,7 @@ done
2628

2729
# Gathering all namespaced custom resources across the cluster that are owned by gitops-operator but do not contain "argoproj.io" related customer resources
2830
# Getting "non.existent.crd" is a hack to be sure that the output is a list of items even if it only contains zero or a single item
29-
oc get crd --ignore-not-found non.existent.crd "$(oc get csv --ignore-not-found "$GITOPS_CURRENT_CSV" -o json | jq '.spec.customresourcedefinitions.owned[] | select(.name | contains("argoproj.io") | not) | " " + .name' -rj)" -o json | jq -r '.items[] | select((.spec.group | contains ("argoproj.io")) and .spec.scope=="Namespaced") | .spec.group + " " + .metadata.name + " " + .spec.names.plural' |
31+
oc get crd --ignore-not-found non.existent.crd "${NON_ARGO_CRDS[@]}" -o json | jq -r '.items[] | select((.spec.group | contains ("argoproj.io")) and .spec.scope=="Namespaced") | .spec.group + " " + .metadata.name + " " + .spec.names.plural' |
3032
while read -r API_GROUP APIRESOURCE API_PLURAL_NAME; do
3133
echo "gather_gitops:$LINENO] collecting ${APIRESOURCE} .." | tee -a ${LOGS_DIR}/gather_gitops.log
3234
NAMESPACES=$(oc get "${APIRESOURCE}" --all-namespaces=true --ignore-not-found -o jsonpath='{range .items[*]}{@.metadata.namespace}{"\n"}{end}' | uniq)
@@ -46,7 +48,7 @@ done
4648

4749
# Gathering all cluster-scoped custom resources across the cluster that are owned by gitops-operator but do not contain "argoproj.io"
4850
# Getting "non.existent.crd" is a hack to be sure that the output is a list of items even if it only contains zero or a single item
49-
oc get crd --ignore-not-found non.existent.crd "$(oc get csv --ignore-not-found "$GITOPS_CURRENT_CSV" -o json | jq '.spec.customresourcedefinitions.owned[] | select(.name | contains("argoproj.io") | not) | " " + .name' -rj)" -o json | jq -r '.items[] | select((.spec.group | contains ("argoproj.io")) and .spec.scope=="Namespaced") | .spec.group + " " + .metadata.name + " " + .spec.names.plural' |
51+
oc get crd --ignore-not-found non.existent.crd "${NON_ARGO_CRDS[@]}" -o json | jq -r '.items[] | select((.spec.group | contains ("argoproj.io")) and .spec.scope=="Namespaced") | .spec.group + " " + .metadata.name + " " + .spec.names.plural' |
5052
while read -r API_GROUP APIRESOURCE API_PLURAL_NAME; do
5153
mkdir -p "${LOGS_DIR}/cluster-scoped-resources/${API_GROUP}"
5254
echo "gather_gitops:$LINENO] collecting ${APIRESOURCE} .." | tee -a ${LOGS_DIR}/gather_gitops.log
@@ -55,13 +57,13 @@ done
5557

5658
# Inspecting namespace reported in ARGOCD_CLUSTER_CONFIG_NAMESPACES, openshift-gitops and openshift-gitops-operator, and namespaces containing ArgoCD instances
5759
echo "gather_gitops:$LINENO] inspecting \$ARGOCD_CLUSTER_CONFIG_NAMESPACES, openshift-gitops and openshift-gitops-operator namespaces and namespaces containing ArgoCD instances .." | tee -a ${LOGS_DIR}/gather_gitops.log
58-
oc get ns --ignore-not-found "$(oc get subs -A --ignore-not-found -o json | jq '.items[] | select(.metadata.name=="openshift-gitops-operator") | .spec.config.env[]?|select(.name=="ARGOCD_CLUSTER_CONFIG_NAMESPACES")| " " + .value | sub(","; " ")' -rj)" "$(oc get ArgoCD,Rollout,RolloutManager -A -o json | jq '.items[] | " " + .metadata.namespace' -rj)" openshift-gitops openshift-gitops-operator -o json \
60+
oc get ns --ignore-not-found $(oc get subs -A --ignore-not-found -o json | jq '.items[] | select(.metadata.name=="openshift-gitops-operator") | .spec.config.env[]?|select(.name=="ARGOCD_CLUSTER_CONFIG_NAMESPACES")| " " + .value | sub(","; " ")' -rj) $(oc get ArgoCD,Rollout,RolloutManager -A -o json | jq '.items[] | " " + .metadata.namespace' -rj) openshift-gitops openshift-gitops-operator -o json \
5961
| jq '.items | unique |.[] | .metadata.name' -r |
6062
while read -r NAMESPACE; do
6163
echo "gather_gitops:$LINENO] inspecting namespace $NAMESPACE .." | tee -a ${LOGS_DIR}/gather_gitops.log
6264
oc adm inspect --dest-dir=${LOGS_DIR} "ns/$NAMESPACE" > /dev/null
6365
echo "gather_gitops:$LINENO] inspecting csv,sub,ip for namespace $NAMESPACE .." | tee -a ${LOGS_DIR}/gather_gitops.log
64-
oc adm inspect --dest-dir=${LOGS_DIR} "$(oc get --ignore-not-found clusterserviceversions.operators.coreos.com,installplans.operators.coreos.com,subscriptions.operators.coreos.com -o name -n "$NAMESPACE")" -n "$NAMESPACE" &> /dev/null \
66+
oc adm inspect --dest-dir=${LOGS_DIR} $(oc get --ignore-not-found clusterserviceversions.operators.coreos.com,installplans.operators.coreos.com,subscriptions.operators.coreos.com -o name -n "$NAMESPACE") -n "$NAMESPACE" &> /dev/null \
6567
|| echo "gather_gitops:$LINENO] no csv,sub,ip found in namespace $NAMESPACE .." | tee -a ${LOGS_DIR}/gather_gitops.log
6668
done
6769

0 commit comments

Comments
 (0)