Skip to content

Conversation

devodev
Copy link
Contributor

@devodev devodev commented Oct 22, 2024

This will allow us to re-use the same high-level k8s client in Hubble and replace the current kubectl-based port-forwarding commands with a native implementation (CFP #34935, discussed in #35353, used in #35483).

I chose an arbitrary location but feel free to propose a different one and/or a package rename.
EDIT: after discussion, we landed on pkg/cli/k8s as a good compromise that avoids a package rename while making it clear it is meant to be used by CLIs.

Extract k8s package out of cilium-cli into pkg/cli/k8s

@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Oct 22, 2024
@github-actions github-actions bot added cilium-cli This PR contains changes related with cilium-cli kind/community-contribution This was a contribution made by a community member. labels Oct 22, 2024
@devodev devodev force-pushed the pr/devodev/extract-cilium-cli-k8s-client branch from 62c396c to cd078b9 Compare October 22, 2024 14:34
@devodev devodev marked this pull request as ready for review October 22, 2024 16:03
@devodev devodev requested review from a team as code owners October 22, 2024 16:03
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.

Feels pretty reasonable. I don't have a strong opinion on where to put the package, but other maintainers might.

@tommyp1ckles
Copy link
Contributor

tommyp1ckles commented Oct 22, 2024

One suggestion of where to put the common library might be under pkg/k8s/common? Thus keeping all the k8s related code in one place?

@devodev
Copy link
Contributor Author

devodev commented Oct 22, 2024

One suggestion of where to put the common library might be under pkg/k8s/common? Thus keeping all the k8s related code in one place?

That's fair. My first inclination was to put it under pkg/k8s but I wasn't sure how exactly, especially without clashing with the existing client generated package. I also fear pkg/k8s/common/k8s would be confusing ?

Any suggestion on a path/package rename ?

@tommyp1ckles
Copy link
Contributor

tommyp1ckles commented Oct 22, 2024

I also fear pkg/k8s/common/k8s would be confusing ?

yeah that would be a bit redundant.

One thing I'm wondering is the code in this library is that this code isn't supposed to be a general k8s client library used by the agent daemon, but rather is more specific to things like cilium/hubble cli.

Maybe k8s is just not a good package name for this anymore following the cli being moved to cilium/cilium?

Anyway I don't feel that strongly about this, so I'll approve for sig-k8s. Maybe one of the other reviewers will have some thoughts.

@devodev
Copy link
Contributor Author

devodev commented Oct 22, 2024

I also fear pkg/k8s/common/k8s would be confusing ?

yeah that would be a bit redundant.

One thing I'm wondering is the code in this library is that this code isn't supposed to be a general k8s client library used by the agent daemon, but rather is more specific to things like cilium/hubble cli.

Maybe k8s is just not a good package name for this anymore following the cli being moved to cilium/cilium?

Anyway I don't feel that strongly about this, so I'll approve for sig-k8s. Maybe one of the other reviewers will have some thoughts.

I agree that this package is more a high-level k8s-related helper client and therefore k8s is probably not the best name.
On the other hand, the refactor following a package rename will be much larger.

If someone else can propose a better alternative, I'd be happy to make the change. Otherwise we could wing it for now and revisit later if desired.

@devodev devodev force-pushed the pr/devodev/extract-cilium-cli-k8s-client branch from cd078b9 to 1da56e9 Compare October 22, 2024 19:35
Copy link
Member

@gandro gandro left a comment

Choose a reason for hiding this comment

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

Seems reasonable. One alternative name could be pkg/cli (for packages used by the CLIs) since pkg/common seems a bit overly generic

@devodev
Copy link
Contributor Author

devodev commented Oct 23, 2024

Seems reasonable. One alternative name could be pkg/cli (for packages used by the CLIs) since pkg/common seems a bit overly generic

I like it. Let me update the PR to reflect the change to use: pkg/cli/k8s as the new location.

Signed-off-by: Alexandre Barone <abalexandrebarone@gmail.com>
@devodev devodev force-pushed the pr/devodev/extract-cilium-cli-k8s-client branch from 1da56e9 to 900b35a Compare October 23, 2024 14:01
@devodev devodev changed the title Extract k8s package out of cilium-cli into pkg/common/k8s Extract k8s package out of cilium-cli into pkg/cli/k8s Oct 23, 2024
@squeed
Copy link
Contributor

squeed commented Oct 25, 2024

I'm not completely convinced yet. The cilium-cli client still is pretty well coupled to cilium-cli --

  • no API stability guarantees
  • embedded names, e.g. FieldManager in ApplyGeneric
  • a separate Helm driver

Plus it's all a bit heavyweight.

If the goal is a functional port-forwarding implementation, then let's extract that, and have it take a k8s.ClientSet instead.

@devodev
Copy link
Contributor Author

devodev commented Oct 25, 2024

I'm not completely convinced yet. The cilium-cli client still is pretty well coupled to cilium-cli --

  • no API stability guarantees
  • embedded names, e.g. FieldManager in ApplyGeneric
  • a separate Helm driver

Plus it's all a bit heavyweight.

If the goal is a functional port-forwarding implementation, then let's extract that, and have it take a k8s.ClientSet instead.

I think that's fair @squeed.

In the following branch I moved the port-forwarding logic that already exists on the client into a new PortForwarder type under pkg/k8s, and re-used it in the cilium-cli client and hubble: https://github.com/cilium/cilium/compare/main...devodev:pr/devodev/hubble-auto-port-forward-native3?expand=1

Let me know what you think. If this is more inline with what you had in mind, and others agree, I can move on into rebasing the other PR and closing this one.

Thanks for the review!

@ldelossa ldelossa removed their request for review October 29, 2024 14:03
@devodev devodev closed this Oct 29, 2024
@devodev
Copy link
Contributor Author

devodev commented Oct 29, 2024

Closing in favour of introducing a new PortForwarder type that takes in a Kubernetes clientset.
Will update the linked PR shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cilium-cli This PR contains changes related with cilium-cli dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. kind/community-contribution This was a contribution made by a community member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants