Skip to content

OCPBUGS-148312: Fix space-separated CLI flag parsing for filter options - #627

Open
Durgesh-Bendale wants to merge 1 commit into
netobserv:mainfrom
Durgesh-Bendale:fix/ocpbugs-148312-space-separated-flags
Open

Durgesh-Bendale wants to merge 1 commit into
netobserv:mainfrom
Durgesh-Bendale:fix/ocpbugs-148312-space-separated-flags

Conversation

@Durgesh-Bendale

@Durgesh-Bendale Durgesh-Bendale commented Nov 30, 2026 •

Copy link
Copy Markdown

Summary

  • Accept space-separated flag syntax (e.g. --protocol TCP) the same as equals form (--protocol=TCP) by normalizing value-required options before parse_args.
  • Boolean/bare flags such as --drops and --background are unchanged.
  • Fixes: https://issues.redhat.com/browse/OCPBUGS-148312

Root cause

parse_args only splits each argv token on =. With --protocol TCP, TCP is a separate token and is rejected as an invalid option. The collector optionStr path had the same tokenization issue.

Changes

  • Add VALUE_REQUIRED_FLAGS, is_value_required_flag, and normalize_options in scripts/functions.sh.
  • Update parse_args to call normalize_options first.

Test plan

  • ./build/oc-netobserv packets --protocol TCP --port 8080 --yaml → filter_protocol=TCP, options protocol=TCP|port=8080|yaml
  • ./build/oc-netobserv packets --protocol=TCP --port=8080 --yaml still works
  • ./build/oc-netobserv flows --protocol UDP --port 53 --yaml works (space form)
  • ./build/oc-netobserv flows --protocol=UDP --port=53 --yaml still works
  • Invalid protocol (e.g. --protocol FOO) still rejected
  • make oc-commands embeds fix in build/oc-netobserv

Notes

Normalize --key value into --key=value for value-required flags before
parse_args so oc netobserv accepts both syntaxes. Fixes OCPBUGS-148312.

Co-authored-by: Cursor <cursoragent@cursor.com>
@openshift-merge-bot

Copy link
Copy Markdown

Pipeline controller notification

This PR uses the pipeline controller for second-stage tests. Selection and triggering follow the repository configuration.

Use /test ? to list jobs and /pipeline help for commands.

@openshift-ci

openshift-ci Bot commented Nov 30, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign oliviercazade for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci

openshift-ci Bot commented Nov 30, 2026

Copy link
Copy Markdown

Hi @Durgesh-Bendale. Thanks for your PR.

I'm waiting for a netobserv member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@Durgesh-Bendale

Copy link
Copy Markdown
Author

Verification Results

Verified the fix by testing the --protocol flag with both space separated and = syntax.

Before the changes:

# ./build/oc-netobserv packets --protocol TCP --port 8080 --yaml
echo "exit=$?"
Output YAMLs without applying...
invalid value for --protocol
Invalid option: TCP
exit=0
# ./build/oc-netobserv packets --protocol=TCP --port=8080 --yaml
echo "exit=$?"
Output YAMLs without applying...
opt: filter_protocol, value: TCP
opt: filter_port, value: 8080
'yq' version v4.45.1
'bash' version v5.1.8
Setting up... 
creating netobserv-cli namespace
creating service account
creating collector service
creating packet-capture agents
Check the generated YAML file in output folder.

You can create packets agents by executing:
 oc apply -f ./output/packets_capture_2026_11_30_02_44.yml

Then create the collector using:
 oc run -n netobserv-cli collector \
    --image=quay.io/root/network-observability-cli:main --image-pull-policy='Always'      --overrides='{"spec":{"serviceAccount": "netobserv-cli"}}' \
    --command -- bash -c "/network-observability-cli get-packets --options \"protocol=TCP|port=8080|yaml\" --loglevel info --maxtime 5m --namespace netobserv-cli --maxbytes 50000000 && sleep infinity"

And follow its progression with:
 oc logs collector -n netobserv-cli -f

After the changes:

Tested with space separated syntax:

#  ./build/oc-netobserv packets --protocol TCP --port 8080 --yaml
Output YAMLs without applying...
opt: filter_protocol, value: TCP
opt: filter_port, value: 8080
'yq' version v4.45.1
'bash' version v5.1.8
Setting up... 
creating netobserv-cli namespace
creating service account
creating collector service
creating packet-capture agents
Check the generated YAML file in output folder.

You can create packets agents by executing:
 oc apply -f ./output/packets_capture_2026_11_30_03_04.yml

Then create the collector using:
 oc run -n netobserv-cli collector \
    --image=quay.io/root/network-observability-cli:main --image-pull-policy='Always'      --overrides='{"spec":{"serviceAccount": "netobserv-cli"}}' \
    --command -- bash -c "/network-observability-cli get-packets --options \"protocol=TCP|port=8080|yaml\" --loglevel info --maxtime 5m --namespace netobserv-cli --maxbytes 50000000 && sleep infinity"

And follow its progression with:
 oc logs collector -n netobserv-cli -f
 # ./build/oc-netobserv packets --protocol=TCP --port=8080 --yaml
Output YAMLs without applying...
opt: filter_protocol, value: TCP
opt: filter_port, value: 8080
'yq' version v4.45.1
'bash' version v5.1.8
Setting up... 
creating netobserv-cli namespace
creating service account
creating collector service
creating packet-capture agents
Check the generated YAML file in output folder.

You can create packets agents by executing:
 oc apply -f ./output/packets_capture_2026_11_30_03_04.yml

Then create the collector using:
 oc run -n netobserv-cli collector \
    --image=quay.io/root/network-observability-cli:main --image-pull-policy='Always'      --overrides='{"spec":{"serviceAccount": "netobserv-cli"}}' \
    --command -- bash -c "/network-observability-cli get-packets --options \"protocol=TCP|port=8080|yaml\" --loglevel info --maxtime 5m --namespace netobserv-cli --maxbytes 50000000 && sleep infinity"

And follow its progression with:
 oc logs collector -n netobserv-cli -f

@Durgesh-Bendale

Copy link
Copy Markdown
Author

/Verified by me

@openshift-ci-robot

Copy link
Copy Markdown
Collaborator

@Durgesh-Bendale: Jira verification commands are restricted to collaborators for this repo.

Details

In response to this:

/Verified by me

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@Durgesh-Bendale Durgesh-Bendale changed the title Fix space-separated CLI flag parsing for filter options OCPBUGS-148312: Fix space-separated CLI flag parsing for filter options Nov 30, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Collaborator

@Durgesh-Bendale: This pull request references Jira Issue OCPBUGS-148312, which is invalid:

  • expected the bug to target the "5.2.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Summary

  • Accept space-separated flag syntax (e.g. --protocol TCP) the same as equals form (--protocol=TCP) by normalizing value-required options before parse_args.
  • Boolean/bare flags such as --drops and --background are unchanged.
  • Fixes: https://issues.redhat.com/browse/OCPBUGS-148312

Root cause

parse_args only splits each argv token on =. With --protocol TCP, TCP is a separate token and is rejected as an invalid option. The collector optionStr path had the same tokenization issue.

Changes

  • Add VALUE_REQUIRED_FLAGS, is_value_required_flag, and normalize_options in scripts/functions.sh.
  • Update parse_args to call normalize_options first.

Test plan

  • ./build/oc-netobserv packets --protocol TCP --port 8080 --yaml → filter_protocol=TCP, options protocol=TCP|port=8080|yaml
  • ./build/oc-netobserv packets --protocol=TCP --port=8080 --yaml still works
  • ./build/oc-netobserv flows --protocol UDP --port 53 --yaml works (space form)
  • ./build/oc-netobserv flows --protocol=UDP --port=53 --yaml still works
  • Invalid protocol (e.g. --protocol FOO) still rejected
  • make oc-commands embeds fix in build/oc-netobserv

Notes

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@jotak jotak added the needs-review Tells that the PR needs a review label Nov 30, 2026
@jotak

jotak commented Dec 4, 2026

Copy link
Copy Markdown
Member

cc @jpinsonneau
Since #605 removes the whole bash script, is it worth doing? It depends if we expect the refactoring to land in 2.1. @jpinsonneau , thoughts?

@jpinsonneau

Copy link
Copy Markdown
Member

cc @jpinsonneau Since #605 removes the whole bash script, is it worth doing? It depends if we expect the refactoring to land in 2.1. @jpinsonneau , thoughts?

yes it's mentionned in the PR description. Depending on when we merge #605 we can integrate that first or rework it after 😸 I'm fine with both approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants