Skip to content

Conversation

devodev
Copy link
Contributor

@devodev devodev commented Oct 11, 2024

Description

hubble: Implement automatic port-forwarding capability (opt-in)

Adds new server flag (and friends): --auto-port-forward that launches a kubectl port-forward process.

Re-use same worflow as cilium hubble port-forward as intial impl and consider re-placing both with native k8s client tcp port-forwarding in a subsequent change.

Fixes: #34935

Release Notes

TODO

Checklist

Please ensure your pull request adheres to the following guidelines:

  • For first time contributors, read Submitting a pull request
  • All code is covered by unit and/or runtime tests where feasible.
  • All commits contain a well written commit description including a title,
    description and a Fixes: #XXX line if the commit addresses a particular
    GitHub issue.
  • If your commit description contains a Fixes: <commit-id> tag, then
    please add the commit author[s] as reviewer[s] to this issue.
  • All commits are signed off. See the section Developer’s Certificate of Origin
  • Provide a title or release-note blurb suitable for the release notes.
  • Are you a user of Cilium? Please add yourself to the Users doc
  • Thanks for contributing!

@maintainer-s-little-helper
Copy link

Commit fdf4a7c does not match "(?m)^Signed-off-by:".

Please follow instructions provided in https://docs.cilium.io/en/stable/contributing/development/contributing_guide/#developer-s-certificate-of-origin

@maintainer-s-little-helper maintainer-s-little-helper bot added dont-merge/needs-sign-off The author needs to add signoff to their commits before merge. dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. labels Oct 11, 2024
@github-actions github-actions bot added hubble-cli PRs or GitHub issues related with hubble-cli hubble-cli-exclusive Only changes hubble-cli files. kind/community-contribution This was a contribution made by a community member. labels Oct 11, 2024
Signed-off-by: Alexandre Barone <abalexandrebarone@gmail.com>
@devodev devodev force-pushed the pr/devodev/hubble-auto-port-forward branch from fdf4a7c to c3e3d3b Compare October 11, 2024 17:19
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-sign-off The author needs to add signoff to their commits before merge. label Oct 11, 2024
…-forwarding

Signed-off-by: Alexandre Barone <abalexandrebarone@gmail.com>
…d impl supporting port-forwarding

Signed-off-by: Alexandre Barone <abalexandrebarone@gmail.com>
@devodev devodev force-pushed the pr/devodev/hubble-auto-port-forward branch from c3e3d3b to 92c7129 Compare October 11, 2024 18:01
"github.com/cilium/cilium/pkg/safeio"
)

// Slim version of: https://github.com/cilium/cilium/tree/v1.17.0-pre.1/cilium-cli/k8s/client.go
Copy link
Contributor

Choose a reason for hiding this comment

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

Can refactor the Cilium CLI and Hubble CLI to share common code for the port-forwarding and service retrieval? Then in a follow up PR we can switch both to "native" port-forwarding instead of exec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That works yes. Looking through the repo, seems cilium/pkg/hubble would be a good place to put this common logic (something like func RelayPortForward(...)), and have a small k8sclient interface for GetService there, so each client can use its own k8s client (I don't think we could re-use the same client as cilium-cli without tying ourselves to cilium-isms/helm configs/etc).

While at it, I could also update UIPortForward in hubble to re-use that as well instead of hardcoding port 80.

wdyt ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. ideally we could share the implementation for getting services, and eventually the implementation for ProxyTCP. I think it probably isn't a big deal, most of the logic in cilium-cli/k8s looks like it isn't too specific to Cilium CLI. There is quite a bit of logic we aren't going to use, but I don't think that's too big of a deal, the same is true for client-go in general. The question is how much work is it going to be to move that package somewhere else, and where to move it. Maybe we can get input from @kaworu or @rolinh on this.

Additionally, it seems like a good portion of Cilium CLI is already using "native" (non-exec) based port forwarding, it's just cilium port-forward that isn't using it, funnily enough. Sysdump uses native port-forward for a bunch of stuff already it looks like. So we could actually even switch to native port-forwarding for this initial PR I think without it being a big deal.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also @michi-covalent maybe you know about sharing the k8s related code between cilium CLI and Hubble CLI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback. I would not be against doing that work in this PR if we are comfortable with that. As you mentioned, it depends if we want to tackle moving the k8s client outside cilium-cli. It could also be its own PR if we want this to be self-contained.

Let's see what others think, and in the meantime, I'll take a look at the work needed to move the k8s client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opened a PR to extract the k8s client package out of cilium-cli: #35482

and opened a PR that uses native port-forwarding in both hubble and cilium-cli: #35483

I think it turned out pretty well, let's follow-up there :)

@kaworu kaworu added the release-note/minor This PR changes functionality that users may find relevant to operating Cilium. label Oct 14, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Oct 14, 2024
@devodev devodev changed the title WIP: Add option for automatic port-forwarding in Hubble CLI WIP: Add support for automatic port-forwarding in Hubble CLI Oct 21, 2024
@devodev devodev changed the title WIP: Add support for automatic port-forwarding in Hubble CLI WIP: Add support for automatic port-forwarding in Hubble CLI (kubectl) Oct 21, 2024
@devodev devodev closed this Oct 22, 2024
@devodev
Copy link
Contributor Author

devodev commented Oct 22, 2024

Lets follow-up in this alternative PR where I implemented this using native port-forwarding instead: #35483

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hubble-cli PRs or GitHub issues related with hubble-cli hubble-cli-exclusive Only changes hubble-cli files. kind/community-contribution This was a contribution made by a community member. release-note/minor This PR changes functionality that users may find relevant to operating Cilium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CFP: Automatically port-forward Hubble CLI
3 participants