Skip to content

Commit 805e1e5

Browse files
authored
add yaml option (#148)
1 parent b4cd5c4 commit 805e1e5

File tree

7 files changed

+498
-88
lines changed

7 files changed

+498
-88
lines changed

cmd/config.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,22 +1038,22 @@ filters:
10381038
name: Xlat Zone Id
10391039
component: number
10401040
- id: xlat_src_address
1041-
name: Xlat src address
1041+
name: Xlat source address
10421042
component: text
10431043
category: source
10441044
hint: Specify a single IP or range.
10451045
- id: xlat_dst_address
1046-
name: Xlat dst address
1046+
name: Xlat destination address
10471047
component: text
10481048
category: destination
10491049
hint: Specify a single IP or range.
10501050
- id: xlat_src_port
1051-
name: Xlat src port
1051+
name: Xlat source port
10521052
component: autocomplete
10531053
category: source
10541054
hint: Specify a single port number or name.
10551055
- id: xlat_dst_port
1056-
name: Xlat dst port
1056+
name: Xlat destination port
10571057
component: autocomplete
10581058
category: destination
10591059
hint: Specify a single port number or name.
@@ -1402,22 +1402,22 @@ fields:
14021402
description: packet translation zone id
14031403
- name: XlatSrcPort
14041404
type: number
1405-
description: packet translation src port
1405+
description: packet translation source port
14061406
- name: XlatDstPort
14071407
type: number
1408-
description: packet translation dst port
1408+
description: packet translation destination port
14091409
- name: XlatSrcAddr
14101410
type: string
1411-
description: packet translation src address
1411+
description: packet translation source address
14121412
- name: XlatDstAddr
14131413
type: string
1414-
description: packet translation dst address
1414+
description: packet translation destination address
14151415
- name: K8S_ClusterName
14161416
type: string
14171417
description: Cluster name or identifier
14181418
- name: _RecordType
14191419
type: string
1420-
description: "Type of record: 'flowLog' for regular flow logs, or 'newConnection', 'heartbeat', 'endConnection' for conversation tracking"
1420+
description: "Type of record: `flowLog` for regular flow logs, or `newConnection`, `heartbeat`, `endConnection` for conversation tracking"
14211421
- name: _HashId
14221422
type: string
14231423
description: In conversation tracking, the conversation identifier

commands/netobserv

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ if [ -z "${captureStarted+x}" ]; then captureStarted=false; fi
1313
if [ -z "${copy+x}" ]; then copy="prompt"; fi
1414
# run foreground by default
1515
if [ -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
1822
options=""
@@ -53,10 +57,17 @@ maxTime="5m"
5357
# max bytes (default: 50MB)
5458
maxBytes=50000000
5559

60+
# skip dependencies check for help or version
5661
if [[ ! "$*" =~ ^(.*)help|version(.*) ]]; then
5762
check_dependencies "$required_yq_version" "$supported_archs" "$required_bash_version"
5863
fi
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+
6071
case "$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
212237
elif [ "$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

Comments
 (0)