Skip to content

Commit

Permalink
get logs from only the running NMO pods
Browse files Browse the repository at this point in the history
Signed-off-by: oraz <[email protected]>
  • Loading branch information
razo7 committed Feb 24, 2022
1 parent 74e225b commit ca67b74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions must-gather/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ You can use the `oc adm must-gather` command to collect information about your c
With the node-maintenance-must-gather image you can collect manifests and logs related to node maintenance:
- Node objects
- Custom Resource Definition
- Node Maintenance Operator pod's logs
- Node Maintenance Operator pod's logs (dismiss drained pods)
- Custom Resources
- Cluster's resource (CPU, and Memory) usage
- Nodes' logs


To collect this data, you must specify the extra image using the `--image` option.
Example:
Expand Down
22 changes: 12 additions & 10 deletions must-gather/collection-scripts/gather
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# # Create a directory for must-gather
mkdir -p must-gather/operator-pod-logs/ must-gather/nodes-logs
# Create a directory for must-gather
mkdir -p must-gather/operator-pod-logs/

# Generate /must-gather/version file
DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
Expand All @@ -20,10 +20,10 @@ group_resources=()
# Get namespace of node-maintenance-operator - where it is installed
NMO_NAMESPACE=$(oc get subs -A --field-selector=metadata.name=node-maintenance-operator -o jsonpath='{.items[*].metadata.namespace}')

# Get NMO Information - nodes' object, CRD, pod's logs, CRs, cluster's resource usage, and nodes' logs
# Get NMO Information - nodes' object, CRD, pod's logs, CRs, cluster's resource usage.

# Get Nodes' names
NODES_NAMES=($(oc get nodes -o jsonpath='{.items[*].metadata.name}{"\n"}'))
# NODES_NAMES=($(oc get nodes -o jsonpath='{.items[*].metadata.name}{"\n"}'))

# Nodes' objects
group_resources+=(nodes)
Expand All @@ -32,8 +32,8 @@ group_resources+=(nodes)
NMO_CRD=$(oc get crds -o jsonpath='{range .items[*]}{"crd/"}{.metadata.name}{"\n"}{end}' | grep 'nodemaintenance.medik8s' | sed -z 's/\n/ /g')
named_resources+=(${NMO_CRD})

# NMO's POD name
NMO_POD=$(oc get pods -o jsonpath='{range .items[*]}{"pod/"}{.metadata.name}{"\n"}{end}' -n ${NMO_NAMESPACE} | grep 'node-maintenance')
# NMO's running POD name
NMO_PODS=($(oc get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' -n ${NMO_NAMESPACE} | grep 'node-maintenance'))

# Node Maintenance CRs
group_resources+=(nm)
Expand All @@ -43,13 +43,15 @@ oc adm inspect --dest-dir must-gather --all-namespaces "${named_resources[@]}"
group_resources_text=$(IFS=, ; echo "${group_resources[*]}")
oc adm inspect --dest-dir must-gather --all-namespaces "${group_resources_text}"

# Get pod's logs
echo "$(oc logs ${NMO_POD} -n ${NMO_NAMESPACE})" > must-gather/operator-pod-logs/${OPERATOR_NAME}
# Get pod's logs for only the running pods. Dismiss drained NMO pods
for NMO_POD_NAME in ${NMO_PODS[@]};
do if [ $(oc get pod ${NMO_POD_NAME} -n ${NMO_NAMESPACE} -o jsonpath='{.status.phase}') == "Running" ];
then oc logs ${NMO_POD_NAME} -n ${NMO_NAMESPACE} > must-gather/operator-pod-logs/${NMO_POD_NAME}; fi; done

# Get cluster's resource (CPU and Memory) usage
echo "$(oc adm top node --use-protocol-buffers)" > must-gather/cluster_resoruce_statistics
oc adm top node --use-protocol-buffers > must-gather/cluster_resoruce_statistics

# Get all journal logs from each Node (TODO: select particluar journal logs, e.g., crio )
for NODE in ${NODES_NAMES[@]}; do oc adm node-logs ${NODE} > must-gather/nodes-logs/${NODE}; done
# for NODE in ${NODES_NAMES[@]}; do oc adm node-logs ${NODE} > must-gather/nodes-logs/${NODE}; done

exit 0

0 comments on commit ca67b74

Please sign in to comment.