Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Get rid of socat for port forwarding#1470

Merged
fuweid merged 1 commit intocontainerd:masterfrom
aojea:gocat
May 9, 2020
Merged

Get rid of socat for port forwarding#1470
fuweid merged 1 commit intocontainerd:masterfrom
aojea:gocat

Conversation

@aojea
Copy link
Contributor

@aojea aojea commented May 6, 2020

use goroutines to copy the data from the stream to the TCP
connection, and viceversa, removing the socat dependency.

Quoting Lantao Liu, the logic is as follow:

When one side (either pod side or user side) of portforward
is closed, we should stop port forwarding.

When one side is closed, the io.Copy use that side as source will close,
but the io.Copy use that side as dest won't.

Fixes: #730

@k8s-ci-robot
Copy link

Hi @aojea. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@aojea aojea changed the title replace socat for port forwarding Get rid of socat for port forwarding May 6, 2020
@aojea
Copy link
Contributor Author

aojea commented May 6, 2020

xref kubernetes-sigs/kind#1560

@aojea
Copy link
Contributor Author

aojea commented May 6, 2020

@k8s-ci-robot k8s-ci-robot requested a review from Random-Liu May 6, 2020 10:17
@k8s-ci-robot
Copy link

@aojea: GitHub didn't allow me to request PR reviews from the following users: howardjohn.

Note that only containerd members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

/cc @benthelder @Random-Liu @howardjohn

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@aojea aojea force-pushed the gocat branch 3 times, most recently from 487af78 to 820c134 Compare May 6, 2020 12:17
@aojea aojea force-pushed the gocat branch 3 times, most recently from ea07c1b to 2175e78 Compare May 6, 2020 13:29
@BenTheElder
Copy link

cc @dims @mikebrow

@dims
Copy link
Member

dims commented May 7, 2020

in general looks good to me, i'd like to see if we can raise @Random-Liu to take a look.

@mikebrow
Copy link
Member

mikebrow commented May 7, 2020

/ok-to-test

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

see questions and comments

@dims
Copy link
Member

dims commented May 8, 2020

changed my mind. Let's wrap up Mike's comments and get this in to iterate. (no need to wait for Lantao)

@mikebrow
Copy link
Member

mikebrow commented May 8, 2020

sry each commit has to be signed :)

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

looking great.. just a couple small comments on err value and debug output..

use goroutines to copy the data from the stream to the TCP
connection, and viceversa, removing the socat dependency.

Quoting Lantao Liu, the logic is as follow:

When one side (either pod side or user side) of portforward
is closed, we should stop port forwarding.

When one side is closed, the io.Copy use that side as source will close,
but the io.Copy use that side as dest won't.

Signed-off-by: Antonio Ojea <antonio.ojea.garcia@gmail.com>
saschagrunert added a commit to saschagrunert/containerd-cri that referenced this pull request May 12, 2020
We encountered two failing end-to-end tests after the adoption of
containerd#1470 in
cri-o/cri-o#3749:

```
Summarizing 2 Failures:
[Fail] [sig-cli] Kubectl Port forwarding With a server listening on 0.0.0.0 that expects a client request [It] should support a client that connects,
sends DATA, and disconnects
test/e2e/kubectl/portforward.go:343

[Fail] [sig-cli] Kubectl Port forwarding With a server listening on localhost that expects a client request [It] should support a client that connects
, sends DATA, and disconnects
test/e2e/kubectl/portforward.go:343
```

Increasing the timeout to 1s fixes the issue.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 12, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 12, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 12, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 12, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 13, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 13, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
// TODO: hardcoded to tcp4 because localhost resolves to ::1 by default if the system has IPv6 enabled.
// Theoretically happy eyeballs will try IPv6 first and fallback to IPv4
// but resolving localhost doesn't seem to return and IPv4 address, thus failing the connection.
conn, err := net.Dial("tcp4", fmt.Sprintf("localhost:%d", port))
Copy link
Contributor

Choose a reason for hiding this comment

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

@aojea could we do something like this?

Suggested change
conn, err := net.Dial("tcp4", fmt.Sprintf("localhost:%d", port))
conn, err := net.Dial("tcp4", fmt.Sprintf("%s:%d", s.IP, port))

Copy link
Contributor Author

@aojea aojea May 13, 2020

Choose a reason for hiding this comment

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

I was just keeping the old behaviour because of my ignorance on how the ports are exposed inside the namespace.

I can explain at the network level the problem and why I think is forcing IPv4 here.
localhost, depending on some factors, may resolve to [::1] or 127.0.0.1, Long history short, commonly it resolves to [::1] if you are more interested in the whole history I explain it in this link https://gist.github.com/aojea/94f6f483173641647c731f582e52f0b0

But typically, the applications use to listen only 127.0.0.1 inside the container 🤷 , that's the part I'm missing.

If we are able to identify correctly the address that the app is listening, then is better using it, so this works for both IPv4 and IPv6, but I prefer having @mikebrow guidance here.

Copy link
Member

Choose a reason for hiding this comment

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

it's hardcoded localhost(or 127.0.0.1):random port for sec. reasons... or at least that's what the decision was way back when.

Any change here would likely need a kep that sets up streaming ip(s) and port(s) at the CRI request and/or response level.

saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 13, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 13, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 13, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 13, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 13, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 13, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 13, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 13, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 14, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 14, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 14, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
crosbymichael pushed a commit to crosbymichael/cri that referenced this pull request May 19, 2020
We encountered two failing end-to-end tests after the adoption of
containerd#1470 in
cri-o/cri-o#3749:

```
Summarizing 2 Failures:
[Fail] [sig-cli] Kubectl Port forwarding With a server listening on 0.0.0.0 that expects a client request [It] should support a client that connects,
sends DATA, and disconnects
test/e2e/kubectl/portforward.go:343

[Fail] [sig-cli] Kubectl Port forwarding With a server listening on localhost that expects a client request [It] should support a client that connects
, sends DATA, and disconnects
test/e2e/kubectl/portforward.go:343
```

Increasing the timeout to 1s fixes the issue.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
saschagrunert added a commit to openSUSE/cri-o that referenced this pull request May 20, 2020
This is the analogous implementation to
containerd/cri#1470 to remove the socat runtime
dependency from CRI-O.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
hdp617 added a commit to hdp617/kubernetes that referenced this pull request Mar 30, 2021
This is no longer true as of `containerd` v1.4.0 because [0] removes `socat` dependency for port-forwarding. For lower versions of `containerd`, the error message is descriptive i.e. `"socat": executable file not found in $PATH`.

[0] containerd/cri#1470
k8s-publishing-bot pushed a commit to kubernetes/kubectl that referenced this pull request Jun 2, 2021
This is no longer true as of `containerd` v1.4.0 because [0] removes `socat` dependency for port-forwarding. For lower versions of `containerd`, the error message is descriptive i.e. `"socat": executable file not found in $PATH`.

[0] containerd/cri#1470

Kubernetes-commit: 64fca6bda7d36b9cc1667aa317896b540d4dcf8c
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get rid of socat.

8 participants