From ca5a3fccdc0d07f75c40d950ae6054cb1bbdc3b7 Mon Sep 17 00:00:00 2001 From: Derek Whatley Date: Tue, 23 Mar 2021 16:00:09 -0400 Subject: [PATCH 1/9] Add jq to Dockerfile for parsing MigPlans --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b8df6cb..6f88ff7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ FROM quay.io/openshift/origin-must-gather:4.5 as builder FROM registry.access.redhat.com/ubi8-minimal:latest RUN echo -ne "[centos-8-appstream]\nname = CentOS 8 (RPMs) - AppStream\nbaseurl = http://mirror.centos.org/centos-8/8/AppStream/x86_64/os/\nenabled = 1\ngpgcheck = 0" > /etc/yum.repos.d/centos.repo -RUN microdnf -y install rsync tar gzip graphviz findutils +RUN microdnf -y install rsync tar gzip graphviz findutils jq COPY --from=gobuilder /opt/app-root/src/go/bin/pprof /usr/bin/pprof COPY --from=builder /usr/bin/oc /usr/bin/oc From f58e298b0340b7ef9c486a35044318498250ba6b Mon Sep 17 00:00:00 2001 From: Derek Whatley Date: Tue, 23 Mar 2021 16:31:06 -0400 Subject: [PATCH 2/9] Gather YAML for registry route/svc, PV, StorageClasses for clusters --- collection-scripts/gather | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/collection-scripts/gather b/collection-scripts/gather index 95a632d..2734eef 100755 --- a/collection-scripts/gather +++ b/collection-scripts/gather @@ -47,6 +47,16 @@ for localns in $(/usr/bin/oc get migrationcontrollers.migration.openshift.io --a /usr/bin/oc adm inspect --dest-dir must-gather/clusters/${cluster} --all-namespaces ns/${ns} & done + # Collect PV and StorageClass info for cluster + echo "[cluster=${cluster}] Running oc adm inspect storageclasses,persistentvolumes" + usr/bin/oc adm inspect --dest-dir must-gather/clusters/${cluster} storageclasses,persistentvolumes & + + # Collect Route and Service info needed to troubleshoot direct image migration connection + for ns in default openshift-image-registry; do + echo "[cluster=${cluster}][namespace=${ns}] Running oc adm inspect route,service" + /usr/bin/oc adm inspect --dest-dir must-gather/clusters/${cluster} -n ${ns} route,service & + done + # Collect the migration and velero CRs echo "[cluster=${cluster}] Gathering MTC and Velero CRs for namespaces [${namespaces[@]}]" /usr/bin/gather_crs ${cluster} ${namespaces} & From f5dc371e3a632a22721ba1f1e93ad7b5b8253398 Mon Sep 17 00:00:00 2001 From: Derek Whatley Date: Tue, 23 Mar 2021 18:14:19 -0400 Subject: [PATCH 3/9] Update --- Dockerfile | 2 +- collection-scripts/gather | 20 +++++ collection-scripts/gather_migrated_namespaces | 76 +++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100755 collection-scripts/gather_migrated_namespaces diff --git a/Dockerfile b/Dockerfile index 6f88ff7..625c05e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ FROM quay.io/openshift/origin-must-gather:4.5 as builder FROM registry.access.redhat.com/ubi8-minimal:latest RUN echo -ne "[centos-8-appstream]\nname = CentOS 8 (RPMs) - AppStream\nbaseurl = http://mirror.centos.org/centos-8/8/AppStream/x86_64/os/\nenabled = 1\ngpgcheck = 0" > /etc/yum.repos.d/centos.repo -RUN microdnf -y install rsync tar gzip graphviz findutils jq +RUN microdnf -y install rsync tar gzip graphviz findutils jq grep COPY --from=gobuilder /opt/app-root/src/go/bin/pprof /usr/bin/pprof COPY --from=builder /usr/bin/oc /usr/bin/oc diff --git a/collection-scripts/gather b/collection-scripts/gather index 2734eef..0564ded 100755 --- a/collection-scripts/gather +++ b/collection-scripts/gather @@ -16,6 +16,13 @@ for localns in $(/usr/bin/oc get migrationcontrollers.migration.openshift.io --a done echo "Will collect debug info from migclusters [${clusters[@]}]" + # Find the latest migration, plan, and associated namespaces so we can gather additional info from those + set -x + latest_migration=$(oc -n ${localns} get migmigration -o json | jq -r '.items|=sort_by(.metadata.creationTimestamp)' | jq -r '.items[-1].metadata.name') + latest_migration_plan=$(oc -n ${localns} get migmigration ${latest_migration} -o jsonpath={.spec.migPlanRef.name}) + latest_migration_namespaces=$(oc -n ${localns} get migplan ${latest_migration_plan} -o json | jq -r '.spec.namespaces[]') + latest_migration_clusters=$(oc -n ${localns} get migplan ${latest_migration_plan} -o json | jq -r '.spec.destMigClusterRef.name, .spec.srcMigClusterRef.name') + # Iterate over all connected non-host OpenShift clusters for cluster in ${clusters[@]}; do unset KUBECONFIG @@ -41,6 +48,19 @@ for localns in $(/usr/bin/oc get migrationcontrollers.migration.openshift.io --a namespaces+=(${ns}) done + # Check if this cluster has a migrated namespace we want to oc adm inspect + if echo $latest_migration_clusters | grep -o "\b${cluster}\b" > /dev/null; then + echo "[cluster=${cluster}] FOUND within latest_migration_clusters=${latest_migration_clusters}" + for ns in ${latest_migration_namespaces}; do + echo "[cluster=${cluster}][namespace=${ns}][migration=${latest_migration}][plan=${latest_migration_plan}] Running oc adm inspect on namespace that is part of latest migration and plan" + mkdir -p must-gather/clusters/${cluster}/migrated-namespaces + /usr/bin/oc adm inspect --dest-dir must-gather/clusters/${cluster}/migrated-namespaces ns/${ns} & + done + else + echo "[cluster=${cluster}] NOT FOUND within latest_migration_clusters=${latest_migration_clusters}" + fi + + # Collect all resources in MTC namespaces with must-gather for ns in ${namespaces[@]}; do echo "[cluster=${cluster}][namespace=${ns}] Running oc adm inspect" diff --git a/collection-scripts/gather_migrated_namespaces b/collection-scripts/gather_migrated_namespaces new file mode 100755 index 0000000..dfc0f81 --- /dev/null +++ b/collection-scripts/gather_migrated_namespaces @@ -0,0 +1,76 @@ +#!/bin/bash + +unset KUBECONFIG +for localns in $(/usr/bin/oc get migrationcontrollers.migration.openshift.io --all-namespaces --no-headers | awk '{print $1}'); do + clusters=() + clusters+=(host) + # get all migclusters + for c in $(oc -n ${localns} get migclusters -o custom-columns=name:.metadata.name --no-headers); do + # only take non-host cluster + if [ $(oc -n ${localns} get migcluster ${c} -o go-template='{{ .spec.isHostCluster }}') == "false" ]; then + clusters+=(${c}) + fi + done + echo "Will collect debug info from migclusters [${clusters[@]}]" + + # Find the latest migration, plan, and associated namespaces so we can gather additional info from those + latest_migration=$(oc -n ${localns} get migmigration -o json | jq -r '.items|=sort_by(.metadata.creationTimestamp)' | jq -r '.items[-1].metadata.name') + latest_migration_plan=$(oc -n ${localns} get migmigration ${latest_migration} -o jsonpath={.spec.migPlanRef.name}) + latest_migration_namespaces=$(oc -n ${localns} get migplan ${latest_migration_plan} -o json | jq -r '.spec.namespaces[]') + latest_migration_clusters=$(oc -n ${localns} get migplan ${latest_migration_plan} -o json | jq -r '.spec.destMigClusterRef.name, .spec.srcMigClusterRef.name') + + # Iterate over all connected non-host OpenShift clusters + for cluster in ${clusters[@]}; do + unset KUBECONFIG + if [ ${cluster} != "host" ]; then + echo "[cluster=${cluster}] Performing token login" + token=$(oc get -n $(oc get -n ${localns} migcluster ${cluster} -o go-template='{{ .spec.serviceAccountSecretRef.namespace }}') secret $(oc get -n ${localns} migcluster ${cluster} -o go-template='{{ .spec.serviceAccountSecretRef.name }}') -o go-template='{{ .data.saToken }}' | base64 -d) + url=$(oc get -n ${localns} migcluster ${cluster} -o go-template='{{ .spec.url }}') + export KUBECONFIG=/tmp/kubeconfig + oc login --insecure-skip-tls-verify=true --token=${token} $url + if [ "$?" != "0" ]; then + object_collection_path="/must-gather/clusters/${cluster}/" + mkdir -p ${object_collection_path} + echo "Login to migcluster ${cluster} unsuccessful." > "${object_collection_path}/login_error.txt" + continue + fi + fi + + # Build list of namespaces where MTC is installed + namespaces=() + for ns in $(/usr/bin/oc get migrationcontrollers.migration.openshift.io --all-namespaces --no-headers | awk '{print $1}') + do + echo "[cluster=${cluster}][namespace=${ns}] Detected MTC installation" + namespaces+=(${ns}) + done + + # Check if this cluster has a migrated namespace we want to oc adm inspect + if echo $latest_migration_clusters | grep -o "\b${cluster}\b" > /dev/null; then + echo "[cluster=${cluster}] FOUND within latest_migration_clusters=${latest_migration_clusters}" + for ns in ${latest_migration_namespaces}; do + echo "[cluster=${cluster}][namespace=${ns}][migration=${latest_migration}][plan=${latest_migration_plan}] Running oc adm inspect on namespace that is part of latest migration and plan" + mkdir -p must-gather/clusters/${cluster}/migrated-namespaces + /usr/bin/oc adm inspect --dest-dir must-gather/clusters/${cluster}/migrated-namespaces ns/${ns} & + done + else + echo "[cluster=${cluster}] NOT FOUND within latest_migration_clusters=${latest_migration_clusters}" + fi + done + + echo "Waiting for background gather tasks to finish" + wait +done + +# Tar all must-gather artifacts for faster transmission +echo "Tarring must-gather artifacts..." +archive_path="/must-gather-archive" +mkdir -p ${archive_path} +tar -zcf ${archive_path}/must-gather.tar.gz /must-gather/ +rm -rf /must-gather/* +mv ${archive_path}/must-gather.tar.gz /must-gather/ +rmdir ${archive_path} +echo "Created /must-gather/must-gather.tar.gz" + + +echo "Waiting for copy phase..." +exit 0 From aff73ac4f8ec79b7fa946ba09d865c45e11a6ad9 Mon Sep 17 00:00:00 2001 From: Derek Whatley Date: Tue, 23 Mar 2021 18:15:30 -0400 Subject: [PATCH 4/9] Remove migrated-namespace collection from main gather --- collection-scripts/gather | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/collection-scripts/gather b/collection-scripts/gather index 0564ded..2734eef 100755 --- a/collection-scripts/gather +++ b/collection-scripts/gather @@ -16,13 +16,6 @@ for localns in $(/usr/bin/oc get migrationcontrollers.migration.openshift.io --a done echo "Will collect debug info from migclusters [${clusters[@]}]" - # Find the latest migration, plan, and associated namespaces so we can gather additional info from those - set -x - latest_migration=$(oc -n ${localns} get migmigration -o json | jq -r '.items|=sort_by(.metadata.creationTimestamp)' | jq -r '.items[-1].metadata.name') - latest_migration_plan=$(oc -n ${localns} get migmigration ${latest_migration} -o jsonpath={.spec.migPlanRef.name}) - latest_migration_namespaces=$(oc -n ${localns} get migplan ${latest_migration_plan} -o json | jq -r '.spec.namespaces[]') - latest_migration_clusters=$(oc -n ${localns} get migplan ${latest_migration_plan} -o json | jq -r '.spec.destMigClusterRef.name, .spec.srcMigClusterRef.name') - # Iterate over all connected non-host OpenShift clusters for cluster in ${clusters[@]}; do unset KUBECONFIG @@ -48,19 +41,6 @@ for localns in $(/usr/bin/oc get migrationcontrollers.migration.openshift.io --a namespaces+=(${ns}) done - # Check if this cluster has a migrated namespace we want to oc adm inspect - if echo $latest_migration_clusters | grep -o "\b${cluster}\b" > /dev/null; then - echo "[cluster=${cluster}] FOUND within latest_migration_clusters=${latest_migration_clusters}" - for ns in ${latest_migration_namespaces}; do - echo "[cluster=${cluster}][namespace=${ns}][migration=${latest_migration}][plan=${latest_migration_plan}] Running oc adm inspect on namespace that is part of latest migration and plan" - mkdir -p must-gather/clusters/${cluster}/migrated-namespaces - /usr/bin/oc adm inspect --dest-dir must-gather/clusters/${cluster}/migrated-namespaces ns/${ns} & - done - else - echo "[cluster=${cluster}] NOT FOUND within latest_migration_clusters=${latest_migration_clusters}" - fi - - # Collect all resources in MTC namespaces with must-gather for ns in ${namespaces[@]}; do echo "[cluster=${cluster}][namespace=${ns}] Running oc adm inspect" From cd9c64b7ace09b09685174a3847b957b759e428b Mon Sep 17 00:00:00 2001 From: Derek Whatley Date: Tue, 23 Mar 2021 18:20:52 -0400 Subject: [PATCH 5/9] Update README --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bae43ba..2f93ecc 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ The command above will create a local directory with a dump of the MTC state. You will get a dump of: - All namespaces where a MTC toolset is installed, including pod logs -- All velero.io and migration.openshift.io resources located in those namespaces +- All velero.io and migration.openshift.io resources located in MTC namespaces +- StorageClasses and PersistentVolume YAML +- Routes and Service YAML from the `default` and `openshift-image-registry` namespaces - Prometheus metrics **Essential-only gather** @@ -27,6 +29,15 @@ Differences from full gather: oc adm must-gather --image=quay.io/konveyor/must-gather:latest -- /usr/bin/gather_24h_essential ``` +**Migrated namespace gather** + +Troubleshooting a migration often requires looking at resource YAML in migrated namespaces. +You can easily gather the content of the namespaces from the most recent migration attempt with this command. +``` +# Gathers content of namespaces migrated during latest MigMigration +oc adm must-gather --image=quay.io/djwhatle/must-gather:latest -- /usr/bin/gather_migrated_namespaces +``` + #### Preview metrics on local Prometheus server Get Prometheus metrics data directory dump (last day, might take a while): From 7e9c0555e0327a1cc560660ee491d5ca95f9f747 Mon Sep 17 00:00:00 2001 From: Derek Whatley Date: Tue, 23 Mar 2021 18:22:23 -0400 Subject: [PATCH 6/9] Update README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2f93ecc..e9dfd82 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ The command above will create a local directory with a dump of the MTC state. You will get a dump of: - All namespaces where a MTC toolset is installed, including pod logs - All velero.io and migration.openshift.io resources located in MTC namespaces -- StorageClasses and PersistentVolume YAML -- Routes and Service YAML from the `default` and `openshift-image-registry` namespaces +- StorageClasse and PersistentVolume resources +- Route and Service resources from the `default` and `openshift-image-registry` namespaces - Prometheus metrics **Essential-only gather** @@ -24,7 +24,7 @@ You will get a dump of: Differences from full gather: - Logs are only gathered from specified time window - Skips collection of prometheus metrics, pprof. Removes duplicate logs from payload. -``` +```sh # Essential gather (available time windows: [1h, 6h, 24h, 72h, all]) oc adm must-gather --image=quay.io/konveyor/must-gather:latest -- /usr/bin/gather_24h_essential ``` @@ -33,7 +33,7 @@ oc adm must-gather --image=quay.io/konveyor/must-gather:latest -- /usr/bin/gathe Troubleshooting a migration often requires looking at resource YAML in migrated namespaces. You can easily gather the content of the namespaces from the most recent migration attempt with this command. -``` +```sh # Gathers content of namespaces migrated during latest MigMigration oc adm must-gather --image=quay.io/djwhatle/must-gather:latest -- /usr/bin/gather_migrated_namespaces ``` From e38008394939c838f97760c011f2b98e6824d0b2 Mon Sep 17 00:00:00 2001 From: Derek Whatley Date: Tue, 23 Mar 2021 18:25:00 -0400 Subject: [PATCH 7/9] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9dfd82..4a9d3f5 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Troubleshooting a migration often requires looking at resource YAML in migrated You can easily gather the content of the namespaces from the most recent migration attempt with this command. ```sh # Gathers content of namespaces migrated during latest MigMigration -oc adm must-gather --image=quay.io/djwhatle/must-gather:latest -- /usr/bin/gather_migrated_namespaces +oc adm must-gather --image=quay.io/konveyor/must-gather:latest -- /usr/bin/gather_migrated_namespaces ``` #### Preview metrics on local Prometheus server From 5ee727b767eb2ac8fd228dff2891313086bc6d2a Mon Sep 17 00:00:00 2001 From: Derek Whatley Date: Wed, 24 Mar 2021 12:45:09 -0400 Subject: [PATCH 8/9] Consolidate migrated-namespaces to single gather --- README.md | 12 +-- collection-scripts/gather | 28 +++++++ collection-scripts/gather_migrated_namespaces | 76 ------------------- 3 files changed, 30 insertions(+), 86 deletions(-) delete mode 100755 collection-scripts/gather_migrated_namespaces diff --git a/README.md b/README.md index 4a9d3f5..3fb94b9 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,9 @@ The command above will create a local directory with a dump of the MTC state. You will get a dump of: - All namespaces where a MTC toolset is installed, including pod logs - All velero.io and migration.openshift.io resources located in MTC namespaces -- StorageClasse and PersistentVolume resources +- StorageClasses and PersistentVolume resources - Route and Service resources from the `default` and `openshift-image-registry` namespaces +- All resources from namespaces migrated in the most recent migration attempt, with the exception of Secrets - Prometheus metrics **Essential-only gather** @@ -29,15 +30,6 @@ Differences from full gather: oc adm must-gather --image=quay.io/konveyor/must-gather:latest -- /usr/bin/gather_24h_essential ``` -**Migrated namespace gather** - -Troubleshooting a migration often requires looking at resource YAML in migrated namespaces. -You can easily gather the content of the namespaces from the most recent migration attempt with this command. -```sh -# Gathers content of namespaces migrated during latest MigMigration -oc adm must-gather --image=quay.io/konveyor/must-gather:latest -- /usr/bin/gather_migrated_namespaces -``` - #### Preview metrics on local Prometheus server Get Prometheus metrics data directory dump (last day, might take a while): diff --git a/collection-scripts/gather b/collection-scripts/gather index 2734eef..ab36c4b 100755 --- a/collection-scripts/gather +++ b/collection-scripts/gather @@ -16,6 +16,12 @@ for localns in $(/usr/bin/oc get migrationcontrollers.migration.openshift.io --a done echo "Will collect debug info from migclusters [${clusters[@]}]" + # Find the latest migration, plan, and associated namespaces so we can gather additional info from those + latest_migration=$(oc -n ${localns} get migmigration -o json | jq -r '.items|=sort_by(.metadata.creationTimestamp)' | jq -r '.items[-1].metadata.name') + latest_migration_plan=$(oc -n ${localns} get migmigration ${latest_migration} -o jsonpath={.spec.migPlanRef.name}) + latest_migration_namespaces=$(oc -n ${localns} get migplan ${latest_migration_plan} -o json | jq -r '.spec.namespaces[]') + latest_migration_clusters=$(oc -n ${localns} get migplan ${latest_migration_plan} -o json | jq -r '.spec.destMigClusterRef.name, .spec.srcMigClusterRef.name') + # Iterate over all connected non-host OpenShift clusters for cluster in ${clusters[@]}; do unset KUBECONFIG @@ -41,6 +47,18 @@ for localns in $(/usr/bin/oc get migrationcontrollers.migration.openshift.io --a namespaces+=(${ns}) done + # Check if this cluster has a migrated namespace we want to oc adm inspect + if echo $latest_migration_clusters | grep -o "\b${cluster}\b" > /dev/null; then + echo "[cluster=${cluster}] Found within latest_migration_clusters=${latest_migration_clusters}" + for ns in ${latest_migration_namespaces}; do + echo "[cluster=${cluster}][namespace=${ns}][migration=${latest_migration}][plan=${latest_migration_plan}] Running oc adm inspect on namespace that is part of latest migration and plan" + mkdir -p must-gather/clusters/${cluster}/migrated-namespaces + /usr/bin/oc adm inspect --dest-dir must-gather/clusters/${cluster}/migrated-namespaces ns/${ns} & + done + else + echo "[cluster=${cluster}] Not found within latest_migration_clusters=${latest_migration_clusters}" + fi + # Collect all resources in MTC namespaces with must-gather for ns in ${namespaces[@]}; do echo "[cluster=${cluster}][namespace=${ns}] Running oc adm inspect" @@ -94,6 +112,16 @@ else find /must-gather/clusters/*/namespaces/*/pods/ -name '*.log' -delete fi +# Wipe secrets from migrated-namespaces data +echo "Scrubbing secrets collected from migrated namespaces" +find must-gather/clusters/*/migrated-namespaces/namespaces/*/*/ -name *secrets.yaml* -delete + +# Shorten logs from migrated-namespaces to last 100 lines +echo "Shortening logs collected from migrated namespaces to last 100 lines" +for logfile in $(find must-gather/clusters/*/migrated-namespaces/namespaces/*/*/ -name *.log); do + tail -100 "${logfile}" > tmp.log && mv tmp.log "${logfile}" +done + # Tar all must-gather artifacts for faster transmission echo "Tarring must-gather artifacts..." archive_path="/must-gather-archive" diff --git a/collection-scripts/gather_migrated_namespaces b/collection-scripts/gather_migrated_namespaces deleted file mode 100755 index dfc0f81..0000000 --- a/collection-scripts/gather_migrated_namespaces +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash - -unset KUBECONFIG -for localns in $(/usr/bin/oc get migrationcontrollers.migration.openshift.io --all-namespaces --no-headers | awk '{print $1}'); do - clusters=() - clusters+=(host) - # get all migclusters - for c in $(oc -n ${localns} get migclusters -o custom-columns=name:.metadata.name --no-headers); do - # only take non-host cluster - if [ $(oc -n ${localns} get migcluster ${c} -o go-template='{{ .spec.isHostCluster }}') == "false" ]; then - clusters+=(${c}) - fi - done - echo "Will collect debug info from migclusters [${clusters[@]}]" - - # Find the latest migration, plan, and associated namespaces so we can gather additional info from those - latest_migration=$(oc -n ${localns} get migmigration -o json | jq -r '.items|=sort_by(.metadata.creationTimestamp)' | jq -r '.items[-1].metadata.name') - latest_migration_plan=$(oc -n ${localns} get migmigration ${latest_migration} -o jsonpath={.spec.migPlanRef.name}) - latest_migration_namespaces=$(oc -n ${localns} get migplan ${latest_migration_plan} -o json | jq -r '.spec.namespaces[]') - latest_migration_clusters=$(oc -n ${localns} get migplan ${latest_migration_plan} -o json | jq -r '.spec.destMigClusterRef.name, .spec.srcMigClusterRef.name') - - # Iterate over all connected non-host OpenShift clusters - for cluster in ${clusters[@]}; do - unset KUBECONFIG - if [ ${cluster} != "host" ]; then - echo "[cluster=${cluster}] Performing token login" - token=$(oc get -n $(oc get -n ${localns} migcluster ${cluster} -o go-template='{{ .spec.serviceAccountSecretRef.namespace }}') secret $(oc get -n ${localns} migcluster ${cluster} -o go-template='{{ .spec.serviceAccountSecretRef.name }}') -o go-template='{{ .data.saToken }}' | base64 -d) - url=$(oc get -n ${localns} migcluster ${cluster} -o go-template='{{ .spec.url }}') - export KUBECONFIG=/tmp/kubeconfig - oc login --insecure-skip-tls-verify=true --token=${token} $url - if [ "$?" != "0" ]; then - object_collection_path="/must-gather/clusters/${cluster}/" - mkdir -p ${object_collection_path} - echo "Login to migcluster ${cluster} unsuccessful." > "${object_collection_path}/login_error.txt" - continue - fi - fi - - # Build list of namespaces where MTC is installed - namespaces=() - for ns in $(/usr/bin/oc get migrationcontrollers.migration.openshift.io --all-namespaces --no-headers | awk '{print $1}') - do - echo "[cluster=${cluster}][namespace=${ns}] Detected MTC installation" - namespaces+=(${ns}) - done - - # Check if this cluster has a migrated namespace we want to oc adm inspect - if echo $latest_migration_clusters | grep -o "\b${cluster}\b" > /dev/null; then - echo "[cluster=${cluster}] FOUND within latest_migration_clusters=${latest_migration_clusters}" - for ns in ${latest_migration_namespaces}; do - echo "[cluster=${cluster}][namespace=${ns}][migration=${latest_migration}][plan=${latest_migration_plan}] Running oc adm inspect on namespace that is part of latest migration and plan" - mkdir -p must-gather/clusters/${cluster}/migrated-namespaces - /usr/bin/oc adm inspect --dest-dir must-gather/clusters/${cluster}/migrated-namespaces ns/${ns} & - done - else - echo "[cluster=${cluster}] NOT FOUND within latest_migration_clusters=${latest_migration_clusters}" - fi - done - - echo "Waiting for background gather tasks to finish" - wait -done - -# Tar all must-gather artifacts for faster transmission -echo "Tarring must-gather artifacts..." -archive_path="/must-gather-archive" -mkdir -p ${archive_path} -tar -zcf ${archive_path}/must-gather.tar.gz /must-gather/ -rm -rf /must-gather/* -mv ${archive_path}/must-gather.tar.gz /must-gather/ -rmdir ${archive_path} -echo "Created /must-gather/must-gather.tar.gz" - - -echo "Waiting for copy phase..." -exit 0 From 6e8cc97d26ad8ec02c18eabe3bc1c8f267977d8e Mon Sep 17 00:00:00 2001 From: Derek Whatley Date: Thu, 1 Apr 2021 17:53:39 -0400 Subject: [PATCH 9/9] Update gather to always gather migrated-ns content --- collection-scripts/gather | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/collection-scripts/gather b/collection-scripts/gather index ab36c4b..1e1a22b 100755 --- a/collection-scripts/gather +++ b/collection-scripts/gather @@ -48,16 +48,11 @@ for localns in $(/usr/bin/oc get migrationcontrollers.migration.openshift.io --a done # Check if this cluster has a migrated namespace we want to oc adm inspect - if echo $latest_migration_clusters | grep -o "\b${cluster}\b" > /dev/null; then - echo "[cluster=${cluster}] Found within latest_migration_clusters=${latest_migration_clusters}" - for ns in ${latest_migration_namespaces}; do - echo "[cluster=${cluster}][namespace=${ns}][migration=${latest_migration}][plan=${latest_migration_plan}] Running oc adm inspect on namespace that is part of latest migration and plan" - mkdir -p must-gather/clusters/${cluster}/migrated-namespaces - /usr/bin/oc adm inspect --dest-dir must-gather/clusters/${cluster}/migrated-namespaces ns/${ns} & - done - else - echo "[cluster=${cluster}] Not found within latest_migration_clusters=${latest_migration_clusters}" - fi + for ns in ${latest_migration_namespaces}; do + echo "[cluster=${cluster}][namespace=${ns}][migration=${latest_migration}][plan=${latest_migration_plan}] Running oc adm inspect on namespace that is part of latest migration and plan" + mkdir -p must-gather/clusters/${cluster}/migrated-namespaces + /usr/bin/oc adm inspect --dest-dir must-gather/clusters/${cluster}/migrated-namespaces ns/${ns} & + done # Collect all resources in MTC namespaces with must-gather for ns in ${namespaces[@]}; do