[v1.16] hubble: fix flowfilter flag parsing allowing only one filter #38794
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes the flag parsing of
hubble-export-allowlist
andhubble-export-denylist
that currently only considers one JSON object from the Helm chartallowList
anddenyList
options.Details
The parsing logic for the Hubble flowfilter flags does not exhaust the JSON decoder, resulting in only the first filter to be considered.
Using the following Helm values:
Which will be used generate the cilium configmap:
It seems we assume that the flag parsing done by viper when using stringSlice will return a list of JSON objects, but it actually returns one string with all JSON objects joined with a comma. Adding a log statement confirms the latter:
The JSON decoder is able to decode the first object, and on the next iteration would error out on the comma which it does not understand when outside an object, but since we don't continue iterating after the first result, no errors are raised, and consequently we also silently ignore the remaining objects.
To fix, join with an empty separator and wrap the decoding in a for loop to ensure we exhaust the content of the reader passed in the decoder.
This has already been fixed in 1.17+ following the migration of the exporter codebase to a hive cell and using a different flag parsing method.
Testing
Add a log statement when building the filter list and notice that Hubble only parses the first filter it sees:
Then apply the fix described above and confirm we see both filters in the filter list: