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

port-forward listen on address #46517

Merged
merged 1 commit into from
Oct 9, 2018

Conversation

goblain
Copy link
Contributor

@goblain goblain commented May 26, 2017

What this PR does / why we need it:

Implements #43962 proposal. Adds --address flag to port-forward command that allows listening on addresses other then localhost, so that port-forward can ie. be opened to consumers other then residing in local host like running in docker or different machine/vm

Which issue this PR fixes:

fixes #43962, fixes #36152, fixes #29678

Release note:

allows selecting non-localhost addresses to listen on with port-forward

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 26, 2017
@k8s-github-robot k8s-github-robot added kind/old-docs size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge DEPRECATED. Indicates that a PR should not merge. Label can only be manually applied/removed. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels May 26, 2017
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 15, 2017
@mengqiy
Copy link
Member

mengqiy commented Jul 1, 2017

@goblain Are you still working on this? If so, please rebase. I can help review this.

@mengqiy
Copy link
Member

mengqiy commented Jul 1, 2017

/assign

@k8s-github-robot k8s-github-robot removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. kind/old-docs labels Jul 26, 2017
@goblain goblain force-pushed the cli-port-forward-listen branch 2 times, most recently from d90d95c to 93d7a96 Compare August 1, 2017 08:53
@goblain
Copy link
Contributor Author

goblain commented Aug 1, 2017

@mengqiy please take a look at this

@mengqiy
Copy link
Member

mengqiy commented Aug 1, 2017

/ok-to-test
@goblain Thanks for contributing.
Can you add some test please?

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 1, 2017
@goblain goblain force-pushed the cli-port-forward-listen branch 4 times, most recently from 66f0c8c to 187b337 Compare August 3, 2017 06:17
@mengqiy
Copy link
Member

mengqiy commented Aug 3, 2017

/retest

1 similar comment
@mengqiy
Copy link
Member

mengqiy commented Aug 4, 2017

/retest

@mengqiy
Copy link
Member

mengqiy commented Aug 16, 2017

@goblain Any update on the failing test?

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 24, 2017
@goblain
Copy link
Contributor Author

goblain commented Oct 8, 2018

rebased yet again

@dims @mengqiy @liggitt @soltysh chances to get final review and approval / merge before another rebase is required ? :)

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 9, 2018
Copy link
Member

@dixudx dixudx left a comment

Choose a reason for hiding this comment

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

Actually I was wondering whether we could use 10.19.21.23:8888:5000 to indicate port 8888 open on 10.19.21.23 and forward to 5000 in the pod.

@@ -50,6 +50,7 @@ type PortForwardOptions struct {
RESTClient *restclient.RESTClient
Config *restclient.Config
PodClient corev1client.PodsGetter
Address []string
Copy link
Member

Choose a reason for hiding this comment

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

s/Address/Addresses

Copy link
Member

Choose a reason for hiding this comment

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

LocalAddresses?

Copy link
Member

Choose a reason for hiding this comment

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

(but see my suggestion to only serve one local address)

@@ -113,6 +120,7 @@ func NewCmdPortForward(f cmdutil.Factory, streams genericclioptions.IOStreams) *
},
}
cmdutil.AddPodRunningTimeoutFlag(cmd, defaultPodPortForwardWaitTimeout)
cmd.Flags().StringSliceVar(&opts.Address, "address", []string{"localhost"}, "Addresses to listen on (comma separated)")
Copy link
Member

Choose a reason for hiding this comment

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

I suggest "local-addresses"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

address was selected as it's the same as for ie. kubectl proxy, so makes sense to stay coherent

var addresses []listenAddress
parsed := make(map[string]listenAddress)
for _, address := range addressesToParse {
if address == "localhost" {
Copy link
Member

Choose a reason for hiding this comment

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

This looks wrong. I think you need to resolve the name rather than hard coding this stuff.

Copy link
Member

Choose a reason for hiding this comment

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

Likely you should attempt resolving any name that isn't an IP address.

func New(dialer httpstream.Dialer, ports []string, stopChan <-chan struct{}, readyChan chan struct{}, out, errOut io.Writer) (*PortForwarder, error) {
return NewOnAddresses(dialer, []string{"localhost"}, ports, stopChan, readyChan, out, errOut)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps explicitly say 127.0.0.1 & ::1 here, then you can remove the special case in the parse function?

Copy link
Member

Choose a reason for hiding this comment

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

In a followup, I think we should do this after confirm that the address exists, if possible.

return NewOnAddresses(dialer, []string{"localhost"}, ports, stopChan, readyChan, out, errOut)
}

// NewOnAddresses creates a new PortForwarder with custom listen addresses.
Copy link
Member

Choose a reason for hiding this comment

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

Document that addresses must all be valid IPv4 or IPv6 addresses, no hostnames?

@lavalamp
Copy link
Member

lavalamp commented Oct 9, 2018

/approve

I think other changes can be made in a followup.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: goblain, lavalamp, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 9, 2018
@k8s-ci-robot k8s-ci-robot merged commit 830e09c into kubernetes:master Oct 9, 2018
@vladimirvivien
Copy link
Member

Wow. This is awesome.

@Dimagog
Copy link

Dimagog commented Oct 13, 2018

This is great!
Where can I find Windows binary with this change?
I need it badly and all my attempts to build kubectl myself fail with:

E:\Go\home\src\k8s.io\kubernetes\pkg\features\kube_features.go:458:23: cannot use "k8s.io/apiextensions-apiserver/pkg/features".CustomResourceValidation (type "k8s.io/apiextensions-apiserver/vendor/k8s.
io/apiserver/pkg/util/feature".Feature) as type "k8s.io/apiserver/pkg/util/feature".Feature in map key
E:\Go\home\src\k8s.io\kubernetes\pkg\features\kube_features.go:459:23: cannot use "k8s.io/apiextensions-apiserver/pkg/features".CustomResourceSubresources (type "k8s.io/apiextensions-apiserver/vendor/k8
s.io/apiserver/pkg/util/feature".Feature) as type "k8s.io/apiserver/pkg/util/feature".Feature in map key

@mengqiy
Copy link
Member

mengqiy commented Oct 16, 2018

@Dimagog
Copy link

Dimagog commented Oct 16, 2018

@mengqiy Yes, latest binary from below has the --address switch, thanks!
https://storage.googleapis.com/kubernetes-release/release/v1.13.0-alpha.1/bin/windows/amd64/kubectl.exe

k8s-ci-robot added a commit that referenced this pull request Dec 27, 2018
…elease-1.12

Partial cherry-pick of #46517 to fix flaky e2e skew tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet