@@ -111,13 +111,28 @@ exit_if_not_openshift() {
111111 fi
112112}
113113
114+ get_subscription_namespace () {
115+ local namespace1=" openshift-operators"
116+ local namespace2=" openshift-gitops-operator"
117+ if [[ " $( oc get subs openshift-gitops-operator -n ${namespace1} ) " ]]; then
118+ SUBS_NS=" $namespace1 "
119+ elif [[ " $( oc get subs openshift-gitops-operator -n ${namespace2} ) " ]]; then
120+ SUBS_NS=" $namespace2 "
121+ else
122+ mkdir -p " $GITOPS_DIR "
123+ echo " Error: get_subscription_namespace - No GitOps Operator subscription found, please check your cluster configuration." > " $GITOPS_DIR " /must-gather-script-errors.yaml 2>&1
124+ fi
125+
126+ export SUBS_NS
127+ }
128+
114129get_namespaces () {
115130 local namespaces
116131 local default=" openshift-gitops"
117132 local clusterScopedInstances
118- clusterScopedInstances=$( oc get subs openshift-gitops-operator -n openshift-operators -o json | jq ' .spec.config.env[]?|select(.name=="ARGOCD_CLUSTER_CONFIG_NAMESPACES").value' | tr -d ' ",' )
119- disableDefaultArgoCDInstanceValue=$( oc get subs openshift-gitops-operator -n openshift-operators -o json | jq ' .spec.config.env[]?|select(.name=="DISABLE_DEFAULT_ARGOCD_INSTANCE").value' )
120- if [[ " $( oc get subs openshift-gitops-operator -n openshift-operators -o jsonpath=' {.spec.config.env}' ) " == " " ]]; then
133+ clusterScopedInstances=$( oc get subs openshift-gitops-operator -n " ${SUBS_NS} " -o json | jq ' .spec.config.env[]?|select(.name=="ARGOCD_CLUSTER_CONFIG_NAMESPACES").value' | tr -d ' ",' )
134+ disableDefaultArgoCDInstanceValue=$( oc get subs openshift-gitops-operator -n " ${SUBS_NS} " -o json | jq ' .spec.config.env[]?|select(.name=="DISABLE_DEFAULT_ARGOCD_INSTANCE").value' )
135+ if [[ " $( oc get subs openshift-gitops-operator -n " ${SUBS_NS} " -o jsonpath=' {.spec.config.env}' ) " == " " ]]; then
121136 namespaces=" ${default} "
122137 elif [[ " ${clusterScopedInstances} " != " " ]]; then
123138 if [[ " ${disableDefaultArgoCDInstanceValue} " == " true" ]]; then
@@ -266,6 +281,9 @@ function main() {
266281 echo " * Checking if the current cluster is an OpenShift cluster..."
267282 exit_if_not_openshift
268283
284+ echo " * Checking if the GitOps Operator is installed..."
285+ get_subscription_namespace
286+
269287 echo " * Checking for GitOps Namespaces..."
270288 get_namespaces
271289
@@ -278,9 +296,9 @@ function main() {
278296 oc -n openshift-gitops get " ${csv_name} " -o jsonpath=' {.spec.displayName}{"\n"}{.spec.version}' > " $GITOPS_DIR /version.txt"
279297
280298 echo " * Getting GitOps Operator Subscription..."
281- run_and_log " oc get subs openshift-gitops-operator -n openshift-operators -o yaml" " $GITOPS_DIR /subscription.yaml"
282- run_and_log " oc get subs openshift-gitops-operator -n openshift-operators -o json" " $GITOPS_DIR /subscription.json"
283- run_and_log " oc get subs openshift-gitops-operator -n openshift-operators " " $GITOPS_DIR /subscription.txt"
299+ run_and_log " oc get subs openshift-gitops-operator -n ${SUBS_NS} -o yaml" " $GITOPS_DIR /subscription.yaml"
300+ run_and_log " oc get subs openshift-gitops-operator -n ${SUBS_NS} -o json" " $GITOPS_DIR /subscription.json"
301+ run_and_log " oc get subs openshift-gitops-operator -n ${SUBS_NS} " " $GITOPS_DIR /subscription.txt"
284302
285303 for namespace in ${NAMESPACES} ; do
286304 RESOURCES_DIR=" ${GITOPS_DIR} /namespace_${namespace} _resources"
@@ -393,9 +411,9 @@ function main() {
393411 echo " * Getting GitOps CRDs from all Namespaces..."
394412 CRD_DIR=" ${GITOPS_DIR} /crds"
395413 create_directory " ${CRD_DIR} "
396- run_and_log " oc get crds -l operators.coreos.com/openshift-gitops-operator.openshift-operators " " ${CRD_DIR} /crds.txt"
397- run_and_log " oc get crds -l operators.coreos.com/openshift-gitops-operator.openshift-operators -o yaml" " ${CRD_DIR} /crds.yaml"
398- run_and_log " oc get crds -l operators.coreos.com/openshift-gitops-operator.openshift-operators -o json" " ${CRD_DIR} /crds.json"
414+ run_and_log " oc get crds -l operators.coreos.com/openshift-gitops-operator.${SUBS_NS} " " ${CRD_DIR} /crds.txt"
415+ run_and_log " oc get crds -l operators.coreos.com/openshift-gitops-operator.${SUBS_NS} -o yaml" " ${CRD_DIR} /crds.yaml"
416+ run_and_log " oc get crds -l operators.coreos.com/openshift-gitops-operator.${SUBS_NS} -o json" " ${CRD_DIR} /crds.json"
399417
400418 echo
401419 echo " Done! Thank you for using the GitOps must-gather tool :)"
0 commit comments