Ensure portfoward's local_port
keyword follows kubectl
behavior
#506
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.
Closes #505
Currently setting
local_port=None
(the default behaviour) when port forwarding chooses a random high port. However this does not match the default behaviour ofkubectl
. As pointed out in #505 there are three different things thatlocal_port
can be set to inkubectl
.If it is completely omitted it will match the
remote_port
.# This binds remote port 80 to port 80 locally kubectl port-forward po/nginx 80
If it is left empty it will choose a random high port.
# This binds to a random port locally kubectl port-forward po/nginx :80
And finally if it is set then it will be explicitly set.
# This binds to port 8080 locally kubectl port-forward po/nginx 8080:80
This is a little trickier to implement in a Pythonic way because we usually use
None
or0
for choosing a random high port. To resolve this in this PR I've added a new optional union type that is either a literal string of"match"
or"auto"
or anint
. If the value is set toNone
it will follow the behaviour or"auto"
which provides backward compatibility for folks who may explicitly be setting the value toNone
.BREAKING: The default value has been changed to
"match"
to mimic the default behaviour ofkubectl
.So the
kr8s
Python API now follows thekubectl
behaviour:If it is completely omitted it will match the
remote_port
.If it is set to
"auto"
orNone
it will choose a random high port.And finally if it is set then it will be explicitly set.