Skip to content

Commit

Permalink
NETOBSERV-1906 add nodeSelector (#101)
Browse files Browse the repository at this point in the history
* add nodeSelector

* lint
  • Loading branch information
jpinsonneau authored Dec 12, 2024
1 parent 01f00d0 commit 7a7d9a2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
1 change: 0 additions & 1 deletion res/flow-capture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ spec:
- name: var-run-ovs
mountPath: /var/run/openvswitch
mountPropagation: Bidirectional

volumes:
- name: bpf-kernel-debug
hostPath:
Expand Down
1 change: 0 additions & 1 deletion res/packet-capture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ spec:
- name: bpf-kernel-debug
mountPath: /sys/kernel/debug
mountPropagation: Bidirectional

volumes:
- name: bpf-kernel-debug
hostPath:
Expand Down
27 changes: 19 additions & 8 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ function common_usage {
echo " --max-bytes: maximum capture bytes (default: 50000000 = 50MB)"
echo " --copy: copy the output files locally (default: prompt)"
# filters
echo " --node-selector: capture on specific nodes (default: n/a)"
echo " --direction: filter direction (default: n/a)"
echo " --cidr: filter CIDR (default: 0.0.0.0/0)"
echo " --protocol: filter protocol (default: n/a)"
Expand Down Expand Up @@ -279,14 +280,19 @@ function edit_manifest() {
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_ACTION\").value|=\"$2\"" "$3"
;;
"filter_tcp_flags")
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_TCP_FLAGS\").value|=\"$2\"" "$3"
;;
"filter_pkt_drops")
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_DROPS\").value|=\"$2\"" "$3"
;;
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_TCP_FLAGS\").value|=\"$2\"" "$3"
;;
"filter_pkt_drops")
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_DROPS\").value|=\"$2\"" "$3"
;;
"log_level")
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"LOG_LEVEL\").value|=\"$2\"" "$3"
;;
"node_selector")
key=${2%:*}
val=${2#*:}
yq e --inplace ".spec.template.spec.nodeSelector.\"$key\" |= \"$val\"" "$3"
;;
esac
}

Expand All @@ -302,7 +308,6 @@ function check_args_and_apply() {
case "$key" in
--copy) # Copy or skip without prompt
if [[ "$value" == "true" || "$value" == "false" || "$value" == "prompt" ]]; then
echo "param: $key, param_value: $value"
copy="$value"
else
echo "invalid value for --copy"
Expand Down Expand Up @@ -455,15 +460,21 @@ function check_args_and_apply() {
fi
;;
--max-time) # Max time
echo "param: $key, param_value: $value"
maxTime=$value
filter=${filter/$key=$maxTime/}
;;
--max-bytes) # Max bytes
echo "param: $key, param_value: $value"
maxBytes=$value
filter=${filter/$key=$maxBytes/}
;;
--node-selector) # Node selector
if [[ $value == *":"* ]]; then
edit_manifest "node_selector" "$value" "$2"
else
echo "invalid value for --node-selector. Use --node-selector=key:val instead."
exit 1
fi
;;
*) # Invalid option
echo "Invalid option: $key" >&2
exit 1
Expand Down

0 comments on commit 7a7d9a2

Please sign in to comment.