Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[minor] Add --extra-namespaces support to must-gather #592

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions image/cli/mascli/functions/must_gather
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Collection Options (Optional):
--no-pod-logs Skip collection of pod logs, greatly speeds up must-gather collection time when pod logs are not required
--mas-instance-ids Collects the data for the specifed MAS instances, if not specified will collect for all MAS instances on the cluster
--secret-data Collects also the content of the secrets
--extra-namespaces Collects data for additional namespaces, like ibm-common-services or db2u, must be separated by a coma

Artifactory Upload (Optional):
--artifactory-token ${COLOR_YELLOW}ARTIFACTORY_TOKEN${TEXT_RESET} Provide a token for Artifactory to automatically upload the file to ARTIFACTORY_UPLOAD_DIR
Expand All @@ -37,6 +38,7 @@ function mustgather() {
POD_LOGS=true
SECRET_DATA=false
MG_DIR=/tmp/must-gather
EXTRA_NAMESPACES=""

# If a /must-gather directory exists, default to that as the output directory instead
if [[ -d "/must-gather" ]]; then
Expand All @@ -61,6 +63,9 @@ function mustgather() {
--mas-instance-ids)
MAS_INSTANCE_IDS=$1; shift
;;
--extra-namespaces)
EXTRA_NAMESPACES=$1; shift
;;
--secret-data)
SECRET_DATA=true
;;
Expand Down Expand Up @@ -160,6 +165,25 @@ function mustgather() {
$MG_SCRIPT_DIR/mg-collect-mongoce $MONGOCE_NAMESPACE $OUTPUT_DIR
done

if [[ "$EXTRA_NAMESPACES" != "" ]]
then
for EXTRA_NAMESPACE in $(echo $EXTRA_NAMESPACES | tr "," " ")
do
echo_h2 "${EXTRA_NAMESPACE}"
# Generic Kubernetes must-gather
if [[ "$SUMMARY_ONLY" == false ]]
then
$MG_SCRIPT_DIR/mg-collect-extra-namespace $EXTRA_NAMESPACE $OUTPUT_DIR
$MG_SCRIPT_DIR/mg-collect-pods $EXTRA_NAMESPACE $POD_LOGS $OUTPUT_DIR/resources
for RESOURCE in configmaps services routes pvc deployments statefulsets jobs operatorconditions clusterserviceversions installplans subscriptions serviceaccounts roles rolebindings
do
$MG_SCRIPT_DIR/mg-collect-resources -n $EXTRA_NAMESPACE -r $RESOURCE -d $OUTPUT_DIR/resources
done
$MG_SCRIPT_DIR/mg-collect-secrets -n $EXTRA_NAMESPACE -r $RESOURCE -d $OUTPUT_DIR/resources -s $SECRET_DATA
fi
done
fi

if [[ -z $MAS_INSTANCE_IDS ]]
then
# Find MAS instances
Expand Down
22 changes: 22 additions & 0 deletions image/cli/mascli/must-gather/mg-collect-extra-namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

NAMESPACE=$1
OUTPUT_DIR=$2

# Get a list of custom resources that are provided by IBM

RESOURCES=$(oc get -n $NAMESPACE $(oc get crd -o=custom-columns=NAME:.metadata.name | grep ibm | tr '\n' ',' | rev |cut -c2- | rev ) -o jsonpath='{ .items[*].kind}' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')

# Collect Custom Resources
# -----------------------------------------------------------------------------

for RESOURCE in ${RESOURCES[@]}; do

$DIR/mg-collect-resources -n $NAMESPACE -r $RESOURCE -d $OUTPUT_DIR/resources

done

exit 0
2 changes: 1 addition & 1 deletion image/cli/mascli/must-gather/mg-collect-mas-add
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
NAMESPACE=$1
OUTPUT_DIR=$2

RESOURCES=$(oc get -n NAMESPACE $(oc get crd -o=custom-columns=NAME:.metadata.name | grep ibm | tr '\n' ',' | rev |cut -c2- | rev ) -o jsonpath='{ .items[*].kind}' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')
RESOURCES=$(oc get -n $NAMESPACE $(oc get crd -o=custom-columns=NAME:.metadata.name | grep ibm | tr '\n' ',' | rev |cut -c2- | rev ) -o jsonpath='{ .items[*].kind}' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')

# Collect Custom Resources
# -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion image/cli/mascli/must-gather/mg-collect-mas-assist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
NAMESPACE=$1
OUTPUT_DIR=$2

RESOURCES=$(oc get -n NAMESPACE $(oc get crd -o=custom-columns=NAME:.metadata.name | grep ibm | tr '\n' ',' | rev |cut -c2- | rev ) -o jsonpath='{ .items[*].kind}' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')
RESOURCES=$(oc get -n $NAMESPACE $(oc get crd -o=custom-columns=NAME:.metadata.name | grep ibm | tr '\n' ',' | rev |cut -c2- | rev ) -o jsonpath='{ .items[*].kind}' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')

# Collect Custom Resources
# -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion image/cli/mascli/must-gather/mg-collect-mas-monitor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
NAMESPACE=$1
OUTPUT_DIR=$2

RESOURCES=$(oc get -n NAMESPACE $(oc get crd -o=custom-columns=NAME:.metadata.name | grep ibm | tr '\n' ',' | rev |cut -c2- | rev ) -o jsonpath='{ .items[*].kind}' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')
RESOURCES=$(oc get -n $NAMESPACE $(oc get crd -o=custom-columns=NAME:.metadata.name | grep ibm | tr '\n' ',' | rev |cut -c2- | rev ) -o jsonpath='{ .items[*].kind}' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')

# Collect Custom Resources
# -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion image/cli/mascli/must-gather/mg-collect-mas-optimizer
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
NAMESPACE=$1
OUTPUT_DIR=$2

RESOURCES=$(oc get -n NAMESPACE $(oc get crd -o=custom-columns=NAME:.metadata.name | grep ibm | tr '\n' ',' | rev |cut -c2- | rev ) -o jsonpath='{ .items[*].kind}' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')
RESOURCES=$(oc get -n $NAMESPACE $(oc get crd -o=custom-columns=NAME:.metadata.name | grep ibm | tr '\n' ',' | rev |cut -c2- | rev ) -o jsonpath='{ .items[*].kind}' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')

# Collect Custom Resources
# -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion image/cli/mascli/must-gather/mg-collect-mas-predict
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
NAMESPACE=$1
OUTPUT_DIR=$2

RESOURCES=$(oc get -n NAMESPACE $(oc get crd -o=custom-columns=NAME:.metadata.name | grep ibm | tr '\n' ',' | rev |cut -c2- | rev ) -o jsonpath='{ .items[*].kind}' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')
RESOURCES=$(oc get -n $NAMESPACE $(oc get crd -o=custom-columns=NAME:.metadata.name | grep ibm | tr '\n' ',' | rev |cut -c2- | rev ) -o jsonpath='{ .items[*].kind}' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')

# Collect Custom Resources
# -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
NAMESPACE=$1
OUTPUT_DIR=$2

RESOURCES=$(oc get -n NAMESPACE $(oc get crd -o=custom-columns=NAME:.metadata.name | grep ibm | tr '\n' ',' | rev |cut -c2- | rev ) -o jsonpath='{ .items[*].kind}' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')
RESOURCES=$(oc get -n $NAMESPACE $(oc get crd -o=custom-columns=NAME:.metadata.name | grep ibm | tr '\n' ',' | rev |cut -c2- | rev ) -o jsonpath='{ .items[*].kind}' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')

# Collect Custom Resources
# -----------------------------------------------------------------------------
Expand Down