Skip to content

Commit

Permalink
Fetch the raw results in parallel
Browse files Browse the repository at this point in the history
Move the commands extracting the raw-results to a function and run it in
the background.
We also wait for them all to be finished, to ensure the script doesn't
terminate while a pod is still extracting raw results.
  • Loading branch information
yuumasato committed Jul 29, 2024
1 parent cc6d36b commit 26dfdc1
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions utils/must-gather/gather_compliance
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ do
done
done

NAMESPACE="openshift-compliance"
SCANS=$(${BIN} get scans -n ${NAMESPACE} -o jsonpath="{.items[*].metadata.name}")
RAW_RESULTS_DIR=${LOGS_DIR}/${NAMESPACE}/raw-results/
EXTRACT_PODS_DIR=${RAW_RESULTS_DIR}/extract-pods/
mkdir -p ${EXTRACT_PODS_DIR}
for SCAN in ${SCANS[@]}
do
function extract_raw_results(){
SCAN=$1
mkdir ${RAW_RESULTS_DIR}/${SCAN}
CLAIMNAME=$(${BIN} get pvc -n ${NAMESPACE} ${SCAN} -ojsonpath='{.metadata.name}')
# The EXTRACT_POD_NAME needs to match the pod name in fetch-raw-results-pod-template.yaml
Expand All @@ -36,7 +31,19 @@ do
${BIN} wait -n ${NAMESPACE} --for=condition=Ready pod/${EXTRACT_POD_NAME}
${BIN} cp -n ${NAMESPACE} ${EXTRACT_POD_NAME}:/scan-results ${RAW_RESULTS_DIR}/${SCAN}
${BIN} delete pod -n ${NAMESPACE} ${EXTRACT_POD_NAME}
}

NAMESPACE="openshift-compliance"
SCANS=$(${BIN} get scans -n ${NAMESPACE} -o jsonpath="{.items[*].metadata.name}")
RAW_RESULTS_DIR=${LOGS_DIR}/${NAMESPACE}/raw-results/
EXTRACT_PODS_DIR=${RAW_RESULTS_DIR}/extract-pods/
mkdir -p ${EXTRACT_PODS_DIR}
for SCAN in ${SCANS[@]}
do
extract_raw_results ${SCAN} &
done
# Let's wait for all raw-results to be extracted
wait

# Pod logs, describes
NAMESPACES=(openshift-compliance)
Expand Down

0 comments on commit 26dfdc1

Please sign in to comment.