-
Notifications
You must be signed in to change notification settings - Fork 45
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
Implement Custom Bind Address for Port Forwarding #267
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #267 +/- ##
==========================================
- Coverage 94.72% 94.70% -0.03%
==========================================
Files 27 27
Lines 2768 2814 +46
==========================================
+ Hits 2622 2665 +43
- Misses 146 149 +3 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems like a good idea, thanks!
One of our core goals here is to make the API "feel" as close to kubectl
as possible. Here are a couple of examples of setting the explicit address taken from kubectl port-forward --help
.
# Listen on port 8888 on all addresses, forwarding to 5000 in the pod
kubectl port-forward --address 0.0.0.0 pod/mypod 8888:5000
# Listen on port 8888 on localhost and selected IP, forwarding to 5000 in the pod
kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8888:5000
Three things stand out to me after reading the help:
- The flag is
--address
so we should probably call the kwargaddress
instead ofbind_address
- You can specify multiple addresses, we should allow the same. Probably as an iterable rather than a comma-separated string though.
- By default
kubectl
only listens on the127.0.0.1
loopback address and you have to explicitly set0.0.0.0
to listen on all addresses. We should probably update our default to do the same.
A few other things need doing before we can merge:
- Can you update the
Service.portforward()
method too? - Can you add an example to the docstrings, similar to the one from
kubectl port-forward --help
? - Can you add a small test to ensure it is listening on the expected address?
Also, you seem to be new to GitHub, welcome! Your PR is well written. Two bits of advice for future PRs:
|
for more information, see https://pre-commit.ci
kr8s/_portforward.py
Outdated
for sock in server.sockets: | ||
if sock.family == socket.AF_INET: | ||
yield sock.getsockname()[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this works as expected any more because with multiple servers we will yield multiple times, which doesn't make sense for a context manager.
Once we have called start_serving
on all the servers we probably just need to yield the port number for the first server.
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great!
I appreciate you moving the examples around, but we are not quite there. If you could move the examples from docs/index.md
to docs/examples/pod_operations.md
that would be great. I like to keep the examples on the homepage/README pretty simple, then dive deeper into extra config options in the examples section.
Also if you could run the linter and make sure pre-commit is happy we should be good to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for continuing to iterate on this!
Co-authored-by: Jacob Tomlinson <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, this seems like a great solution. Thanks for diving in.
for more information, see https://pre-commit.ci
Thanks for bearing with me and iterating on this so much. It looks like things are good to merge now. |
Overview
This pull request introduces a new feature that allows users to specify a custom bind address for port forwarding within the
kr8s
project. This enhancement provides greater flexibility in network configurations and enhances usability for environments requiring specific binding settings.Changes
Impact
Tests
How to Test
kr8s
project.Your feedback and suggestions on this feature are greatly appreciated!