|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | 3 | set -eu -o pipefail |
| 4 | +trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR |
4 | 5 |
|
5 | 6 | LOGS_DIR="/must-gather" |
6 | 7 |
|
7 | 8 | mkdir -p ${LOGS_DIR} |
8 | 9 |
|
9 | 10 | 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) |
10 | 12 |
|
11 | 13 | # Gathering cluster version all the crd related to operators.coreos.com and argoproj.io |
12 | 14 | echo "gather_gitops:$LINENO] inspecting crd, clusterversion .." | tee -a ${LOGS_DIR}/gather_gitops.log |
13 | 15 | # 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 |
15 | 17 |
|
16 | 18 | # Gathering all namespaced custom resources across the cluster that contains "argoproj.io" related custom resources |
17 | 19 | 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 | 28 |
|
27 | 29 | # Gathering all namespaced custom resources across the cluster that are owned by gitops-operator but do not contain "argoproj.io" related customer resources |
28 | 30 | # 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' | |
30 | 32 | while read -r API_GROUP APIRESOURCE API_PLURAL_NAME; do |
31 | 33 | echo "gather_gitops:$LINENO] collecting ${APIRESOURCE} .." | tee -a ${LOGS_DIR}/gather_gitops.log |
32 | 34 | NAMESPACES=$(oc get "${APIRESOURCE}" --all-namespaces=true --ignore-not-found -o jsonpath='{range .items[*]}{@.metadata.namespace}{"\n"}{end}' | uniq) |
|
46 | 48 |
|
47 | 49 | # Gathering all cluster-scoped custom resources across the cluster that are owned by gitops-operator but do not contain "argoproj.io" |
48 | 50 | # 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' | |
50 | 52 | while read -r API_GROUP APIRESOURCE API_PLURAL_NAME; do |
51 | 53 | mkdir -p "${LOGS_DIR}/cluster-scoped-resources/${API_GROUP}" |
52 | 54 | echo "gather_gitops:$LINENO] collecting ${APIRESOURCE} .." | tee -a ${LOGS_DIR}/gather_gitops.log |
|
55 | 57 |
|
56 | 58 | # Inspecting namespace reported in ARGOCD_CLUSTER_CONFIG_NAMESPACES, openshift-gitops and openshift-gitops-operator, and namespaces containing ArgoCD instances |
57 | 59 | 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 \ |
59 | 61 | | jq '.items | unique |.[] | .metadata.name' -r | |
60 | 62 | while read -r NAMESPACE; do |
61 | 63 | echo "gather_gitops:$LINENO] inspecting namespace $NAMESPACE .." | tee -a ${LOGS_DIR}/gather_gitops.log |
62 | 64 | oc adm inspect --dest-dir=${LOGS_DIR} "ns/$NAMESPACE" > /dev/null |
63 | 65 | 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 \ |
65 | 67 | || echo "gather_gitops:$LINENO] no csv,sub,ip found in namespace $NAMESPACE .." | tee -a ${LOGS_DIR}/gather_gitops.log |
66 | 68 | done |
67 | 69 |
|
|
0 commit comments