Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make --namespace flag more intuitive and allow both --namespace and --pod flag #1279

Merged
merged 2 commits into from
Nov 21, 2023

Conversation

glrf
Copy link
Contributor

@glrf glrf commented Oct 31, 2023

This PR essentially implements @kaworu's proposal in #359 (comment) .

This means instead of treating the --namespace flag as an alias for filtering for any pod in the namespace, we now treat the --namespace flag as a modifier for the --pod and --service flag. We also try to catch namespace inconsistencies in flags and fail early.

There where a few edgecases that were not considered in the initial proposal:

  • If we provide multiple namespace and/or pods/services we build the crossproduct of the provided values.

    For example hubble observe -n foo -n bar --pod buzz will return any flows from or to pods in namespace foo or bar named buzz

  • If we don't provide any pod or service flags, i.e. hubble observe -n foo, we use the old behaviour of filtering for any pods in that namespace.

  • We don't allow mixing --namespace and --to-pod or similar as it isn't clear what should happen in that case.

  • We return an error if the namespace and the pod and/or service flags request flows from different namespace, as it is not clear what for example hubble observe -n foo --pod bar/buzz --pod blub should do.

This PR also doesn't implement the proposed --all-namespaces flag, as it requires server side changes. Will add this separately.

This technically introduces a breaking change. We no longer allow using both --namespace and --from-service or --to-service.
Before this change hubble observe --namespace foo --to-service buzz/bar showed flows flows that either start at a pod in namespace foo and go to service bar in namespace buzz, or come from anywhere and go to service buzz/bar and a pod in namespace foo (which does not show any flows as long as foo != buzz)

If you want to replicate the old behavior you can use hubble observe --pod foo/ --to-service buzz/bar

closes #359

@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label PR is blocked until the release note is set label Oct 31, 2023
@glrf glrf marked this pull request as ready for review November 1, 2023 08:20
@glrf glrf requested a review from a team as a code owner November 1, 2023 08:20
@glrf glrf requested review from chancez and removed request for a team November 1, 2023 08:20
@kaworu kaworu self-requested a review November 1, 2023 14:04
Copy link
Contributor

@chancez chancez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM. The tests seem thorough and make sense to me, which is the biggest part IMO.

Copy link
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work @glrf 🎉 Left a couple of comments but overall LGTM!

cmd/observe/flows_filter.go Outdated Show resolved Hide resolved
cmd/observe/flows_filter.go Outdated Show resolved Hide resolved
cmd/observe/flows_filter.go Outdated Show resolved Hide resolved
@kaworu kaworu added ⌨️ area/cli Impacts the command line interface of any command in the repository. 🌟 kind/feature This introduces new functionality. release-note/minor This PR introduces functionality that users may find relevant to operating Hubble. labels Nov 3, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot added ready-to-merge This PR has passed all tests and received consensus from code owners to merge. and removed dont-merge/needs-release-note-label PR is blocked until the release note is set labels Nov 3, 2023
@glrf glrf force-pushed the feat/improve-ns-flag branch from 7462354 to d4e8731 Compare November 6, 2023 08:49
@glrf glrf requested a review from kaworu November 6, 2023 09:14
@aditighag aditighag removed the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Nov 6, 2023
@aditighag
Copy link
Member

Removing the ready-to-merge label, as @kaworu's review is still pending.

@glrf glrf force-pushed the feat/improve-ns-flag branch from d4e8731 to 55e17a4 Compare November 9, 2023 07:20
@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Nov 9, 2023
Copy link
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @glrf patch LGTM but the commit message still reference the namespace label change that was dropped

  • We also treate --label k8s:io.kubernetes.pod.namespace=foo as a
    namespace flag

cmd/observe/flows_filter.go Show resolved Hide resolved
@maintainer-s-little-helper maintainer-s-little-helper bot removed ready-to-merge This PR has passed all tests and received consensus from code owners to merge. labels Nov 9, 2023
@glrf glrf force-pushed the feat/improve-ns-flag branch 3 times, most recently from 1003570 to 0005970 Compare November 10, 2023 12:41
@kaworu kaworu added breaking-change Breaks compatibility with previous versions :basecamp: needs-rebase This PR needs to be rebased because it has merge conflicts. labels Nov 14, 2023
Instead of treating the `--namespace` flag as an alias for filtering for
any pod in the namespace, we now treat the `--namespace` flag as a
modifier for the `--pod` and `--service` flag.

This means `hubble observe --namespace foo --pod bar` will filter for
flows from or to pod `bar` in namespace `foo`, instead of filtering for
flows to or from pod `bar` in the namespace `default` and `foo` (which
never resulted in any flows)

There are a few edgecases:
* If we provide multiple namespace and/or pods/services we build the
  crossproduct of the provided values.
* If we don't provide any pod or service flags, i.e. `hubble observe -n
  foo`, we use the old behaviour of filtering for any pods in that
  namespace.
* We don't allow mixing `--namespace` and `--to-pod` or similar as it
  isn't clear what should happen in that case.

Signed-off-by: Fabian Fischer <[email protected]>
@glrf glrf force-pushed the feat/improve-ns-flag branch 2 times, most recently from c0b2a2e to 6bb1479 Compare November 20, 2023 10:57
We catch some common mistakes when querying for namespaces.

* We return an error if the pod and service flags request different
  namespaces, as this will never yield any flows.
* We return an error if the namespace and the pod and/or service flags
  request flow from different namespace, as it is not clear what for
  example `hubble observe -n foo --pod bar/buzz --pod blub` should do.

Signed-off-by: Fabian Fischer <[email protected]>
@glrf glrf force-pushed the feat/improve-ns-flag branch from 6bb1479 to 071b371 Compare November 20, 2023 10:58
Copy link
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Nov 21, 2023
@kaworu kaworu removed the :basecamp: needs-rebase This PR needs to be rebased because it has merge conflicts. label Nov 21, 2023
@kaworu kaworu merged commit 0cce17a into cilium:main Nov 21, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⌨️ area/cli Impacts the command line interface of any command in the repository. breaking-change Breaks compatibility with previous versions 🌟 kind/feature This introduces new functionality. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/minor This PR introduces functionality that users may find relevant to operating Hubble.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--namespace is incompatible with --pod
4 participants