@@ -51,7 +51,7 @@ manifest=""
5151
5252OUTPUT_PATH=" ./output"
5353YAML_OUTPUT_FILE=" capture.yml"
54- MANIFEST_OUTPUT_PATH=" tmp "
54+ MANIFEST_OUTPUT_PATH=$( mktemp -d )
5555FLOWS_MANIFEST_FILE=" flow-capture.yml"
5656PACKETS_MANIFEST_FILE=" packet-capture.yml"
5757METRICS_MANIFEST_FILE=" metric-capture.yml"
@@ -248,7 +248,7 @@ function getSubnets() {
248248 # get cluster-config-v1 Configmap to retreive machine networks
249249 installConfig=$( ${K8S_CLI_BIN} get configmap cluster-config-v1 -n kube-system -o custom-columns=" :data.install-config" )
250250 yaml=" ${MANIFEST_OUTPUT_PATH} /${CLUSTER_CONFIG} "
251- echo " $installConfig " > ${yaml}
251+ echo " $installConfig " > " ${yaml} "
252252
253253 machines=$( " $YQ_BIN " e -oj ' .networking.machineNetwork[] | select(has("cidr")).cidr' " $yaml " )
254254 if [ " ${# machines} " -gt 0 ]; then
@@ -258,7 +258,7 @@ function getSubnets() {
258258 # get OCP cluster Network to retreive pod / services / external networks
259259 networkConfig=$( ${K8S_CLI_BIN} get network cluster -o yaml)
260260 yaml=" ${MANIFEST_OUTPUT_PATH} /${NETWORK_CONFIG} "
261- echo " $networkConfig " > ${yaml}
261+ echo " $networkConfig " > " ${yaml} "
262262
263263 pods=$( " $YQ_BIN " e -oj ' .spec.clusterNetwork[] | select(has("cidr")).cidr' " $yaml " )
264264 if [ " ${# pods} " -gt 0 ]; then
@@ -354,32 +354,28 @@ function setup() {
354354 echo " creating service account"
355355 applyYAML " $saYAML "
356356
357- if [[ ! -d ${MANIFEST_OUTPUT_PATH} ]]; then
358- mkdir -p ${MANIFEST_OUTPUT_PATH} > /dev/null
359- fi
360-
361357 if [ " $command " = " flows" ]; then
362358 echo " creating collector service"
363359 applyYAML " $collectorServiceYAML "
364360 echo " creating flow-capture agents"
365361 manifest=" ${MANIFEST_OUTPUT_PATH} /${FLOWS_MANIFEST_FILE} "
366- echo " ${flowAgentYAML} " > ${manifest}
362+ echo " ${flowAgentYAML} " > " ${manifest} "
367363 setCollectorPipelineConfig " $manifest "
368364 check_args_and_apply
369365 elif [ " $command " = " packets" ]; then
370366 echo " creating collector service"
371367 applyYAML " $collectorServiceYAML "
372368 echo " creating packet-capture agents"
373369 manifest=" ${MANIFEST_OUTPUT_PATH} /${PACKETS_MANIFEST_FILE} "
374- echo " ${packetAgentYAML} " > ${manifest}
370+ echo " ${packetAgentYAML} " > " ${manifest} "
375371 setCollectorPipelineConfig " $manifest "
376372 check_args_and_apply
377373 elif [ " $command " = " metrics" ]; then
378374 echo " creating service monitor"
379375 applyYAML " $smYAML "
380376 echo " creating metric-capture agents:"
381377 manifest=" ${MANIFEST_OUTPUT_PATH} /${METRICS_MANIFEST_FILE} "
382- echo " ${metricAgentYAML} " > ${manifest}
378+ echo " ${metricAgentYAML} " > " ${manifest} "
383379 setMetricsPipelineConfig " $manifest "
384380 check_args_and_apply
385381 fi
@@ -445,6 +441,7 @@ function cleanup() {
445441 # Trap SIGHUP to prevent premature termination when PTY closes
446442 trap ' ' HUP
447443
444+ rm -rf " $MANIFEST_OUTPUT_PATH "
448445 if [[ " $runBackground " == " true" || " $skipCleanup " == " true" || " $outputYAML " == " true" ]]; then
449446 return
450447 fi
@@ -490,15 +487,15 @@ function copyFLPConfig() {
490487 jsonContent=$( " $YQ_BIN " e ' .spec.template.spec.containers[0].env[] | select(.name=="FLP_CONFIG").value' " $1 " )
491488 # json temp file location is set as soon as this function is called
492489 json=" ${MANIFEST_OUTPUT_PATH} /${CONFIG_JSON_TEMP} "
493- echo " $jsonContent " > ${json}
490+ echo " $jsonContent " > " ${json} "
494491}
495492
496493# get network enrich stage
497494function getNetworkEnrichStage() {
498495 enrichIndex=$( " $YQ_BIN " e -oj " .parameters[] | select(.name==\" enrich\" ) | path | .[-1]" " $json " )
499496 enrichContent=$( " $YQ_BIN " e -oj " .parameters[$enrichIndex ]" " $json " )
500497 enrichJson=" ${MANIFEST_OUTPUT_PATH} /enrich.json"
501- echo " $enrichContent " > ${enrichJson}
498+ echo " $enrichContent " > " ${enrichJson} "
502499}
503500
504501function overrideNetworkEnrichStage() {
@@ -511,7 +508,7 @@ function getPromStage() {
511508 promIndex=$( " $YQ_BIN " e -oj " .parameters[] | select(.name==\" prometheus\" ) | path | .[-1]" " $json " )
512509 promContent=$( " $YQ_BIN " e -oj " .parameters[$promIndex ]" " $json " )
513510 promJson=" ${MANIFEST_OUTPUT_PATH} /prom.json"
514- echo " $promContent " > ${promJson}
511+ echo " $promContent " > " ${promJson} "
515512}
516513
517514function overridePromStage() {
@@ -1177,5 +1174,5 @@ function check_args_and_apply() {
11771174 if [[ " $outputYAML " == " false" ]]; then
11781175 waitDaemonset
11791176 fi
1180- rm -rf ${MANIFEST_OUTPUT_PATH}
1177+ rm -rf " ${MANIFEST_OUTPUT_PATH} "
11811178}
0 commit comments