@@ -13,6 +13,10 @@ if [ -z "${captureStarted+x}" ]; then captureStarted=false; fi
1313if [ -z " ${copy+x} " ]; then copy=" prompt" ; fi
1414# run foreground by default
1515if [ -z " ${runBackground+x} " ]; then runBackground=" false" ; fi
16+ # output as yaml only
17+ if [ -z " ${outputYAML+x} " ]; then outputYAML=" false" ; fi
18+ # formated date for file names
19+ if [ -z " ${dateName+x} " ]; then dateName=" $( date +" %Y_%m_%d_%I_%M" ) " ; fi
1620
1721# options such as filters, background etc
1822options=" "
@@ -53,10 +57,17 @@ maxTime="5m"
5357# max bytes (default: 50MB)
5458maxBytes=50000000
5559
60+ # skip dependencies check for help or version
5661if [[ ! " $* " =~ ^(.* )help| version(.* ) ]]; then
5762 check_dependencies " $required_yq_version " " $supported_archs " " $required_bash_version "
5863fi
5964
65+ # detect output yaml option before running the script to avoid any apply
66+ if [[ " $* " =~ ^(.* )yaml= true| (yaml$)| (yaml )(.* ) ]]; then
67+ echo " Output YAMLs without applying..."
68+ outputYAML=" true"
69+ fi
70+
6071case " $1 " in
6172* help)
6273 help
@@ -178,21 +189,35 @@ if [[ "$command" == "flows" || "$command" == "packets" ]]; then
178189 # prepare commands & args
179190 runCommand=" sleep infinity"
180191 execCommand=" /network-observability-cli get-$command ${optionStr: +" --options" " ${optionStr} " } --loglevel $logLevel --maxtime $maxTime --maxbytes $maxBytes "
181- if [[ " $runBackground " == " true" ]]; then
182- runCommand=" $execCommand & $runCommand "
192+ if [[ " $runBackground " == " true" || " $outputYAML " == " true " ]]; then
193+ runCommand=" bash -c \" $execCommand && $runCommand \" "
183194 execCommand=" "
184195 fi
196+ cmd=" ${K8S_CLI_BIN} run -n $namespace collector \\
197+ --image=$img --image-pull-policy='Always' --restart='Never' \\
198+ --overrides='{\" spec\" : {\" serviceAccount\" : \" netobserv-cli\" }}' \\
199+ --command -- $runCommand "
185200
186- echo " Running network-observability-cli get-$command ... "
187- ${K8S_CLI_BIN} run \
188- -n $namespace \
189- collector \
190- --image=$img --image-pull-policy=' Always' \
191- --overrides=' { "spec": { "serviceAccount": "netobserv-cli" } }' \
192- --restart=' Never' \
193- --command -- $runCommand
201+ if [[ " $outputYAML " == " true" ]]; then
202+ echo " Check the generated YAML file in output folder."
203+ echo
204+ echo " You can create $command agents by executing:"
205+ echo " ${K8S_CLI_BIN} apply -f ./output/${command} _capture_${dateName} .yml"
206+ echo
207+ echo " Then create the collector using:"
208+ echo -e " $cmd "
209+ echo
210+ echo " And follow its progression with:"
211+ echo " ${K8S_CLI_BIN} logs collector -n $namespace -f"
212+ echo
213+ exit 0
214+ fi
215+
216+ echo " Running network-observability-cli get-$cmd ... "
217+ eval " $cmd "
194218
195219 ${K8S_CLI_BIN} wait \
220+ --timeout 60s \
196221 -n $namespace \
197222 --for=condition=Ready pod/collector || exit 1
198223
@@ -210,6 +235,16 @@ if [[ "$command" == "flows" || "$command" == "packets" ]]; then
210235 echo " - '${K8S_CLI_BIN} netobserv cleanup' to remove the netobserv components"
211236 fi
212237elif [ " $command " = " metrics" ]; then
238+ if [[ " $outputYAML " == " true" ]]; then
239+ echo " Check the generated YAML file in output folder."
240+ echo
241+ echo " You can create metrics agents by executing:"
242+ echo " ${K8S_CLI_BIN} apply -f ./output/${command} _capture_${dateName} .yml"
243+ echo
244+ echo " Then open your OCP Console and search for netobserv-cli dashboard"
245+ echo
246+ exit 0
247+ fi
213248 runBackground=" true"
214249 echo " Metrics capture started."
215250 consoleURL=" $( oc whoami --show-console) "
0 commit comments