@@ -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
@@ -442,6 +438,7 @@ function deleteNamespace() {
442438}
443439
444440function cleanup() {
441+ rm -rf " $MANIFEST_OUTPUT_PATH "
445442 if [[ " $runBackground " == " true" || " $skipCleanup " == " true" || " $outputYAML " == " true" ]]; then
446443 return
447444 fi
@@ -487,15 +484,15 @@ function copyFLPConfig() {
487484 jsonContent=$( " $YQ_BIN " e ' .spec.template.spec.containers[0].env[] | select(.name=="FLP_CONFIG").value' " $1 " )
488485 # json temp file location is set as soon as this function is called
489486 json=" ${MANIFEST_OUTPUT_PATH} /${CONFIG_JSON_TEMP} "
490- echo " $jsonContent " > ${json}
487+ echo " $jsonContent " > " ${json} "
491488}
492489
493490# get network enrich stage
494491function getNetworkEnrichStage() {
495492 enrichIndex=$( " $YQ_BIN " e -oj " .parameters[] | select(.name==\" enrich\" ) | path | .[-1]" " $json " )
496493 enrichContent=$( " $YQ_BIN " e -oj " .parameters[$enrichIndex ]" " $json " )
497494 enrichJson=" ${MANIFEST_OUTPUT_PATH} /enrich.json"
498- echo " $enrichContent " > ${enrichJson}
495+ echo " $enrichContent " > " ${enrichJson} "
499496}
500497
501498function overrideNetworkEnrichStage() {
@@ -508,7 +505,7 @@ function getPromStage() {
508505 promIndex=$( " $YQ_BIN " e -oj " .parameters[] | select(.name==\" prometheus\" ) | path | .[-1]" " $json " )
509506 promContent=$( " $YQ_BIN " e -oj " .parameters[$promIndex ]" " $json " )
510507 promJson=" ${MANIFEST_OUTPUT_PATH} /prom.json"
511- echo " $promContent " > ${promJson}
508+ echo " $promContent " > " ${promJson} "
512509}
513510
514511function overridePromStage() {
@@ -1154,5 +1151,5 @@ function check_args_and_apply() {
11541151 if [[ " $outputYAML " == " false" ]]; then
11551152 waitDaemonset
11561153 fi
1157- rm -rf ${MANIFEST_OUTPUT_PATH}
1154+ rm -rf " ${MANIFEST_OUTPUT_PATH} "
11581155}
0 commit comments