From 26dfdc18f4244b3b2e6f8ee0afc7c4b3700da2da Mon Sep 17 00:00:00 2001 From: Watson Sato Date: Mon, 29 Jul 2024 15:06:43 +0200 Subject: [PATCH] Fetch the raw results in parallel 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. --- utils/must-gather/gather_compliance | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/utils/must-gather/gather_compliance b/utils/must-gather/gather_compliance index e661f0bd5..c7d2b6d2f 100755 --- a/utils/must-gather/gather_compliance +++ b/utils/must-gather/gather_compliance @@ -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 @@ -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)