Skip to content

Conversation

@pohly
Copy link
Contributor

@pohly pohly commented Dec 4, 2020

What type of PR is this?
/kind feature

What this PR does / why we need it:

By running the mock driver in proxy mode with the csi.sock made
available via another listening endpoint it becomes possible to run
the actual driver code elsewhere, for example embedded inside an
e2e.test binary.

The second endpoint can be a TCP port that can be reached from outside
of a Kubernetes cluster, either via a service or port-forwarding.

The same can be done with "socat UNIX-LISTEN:/csi/csi.sock,fork
TCP-LISTEN:9000,reuseport", but the implementation inside the mock
driver has some advantages compared to that:

  • the same image as for normal mock driver testing can be used
  • the mock driver keeps the second listen socket open at all times,
    so a client connecting to it doesn't get "connection refused"
    errors, which happens while socat hasn't forked to accept
    such a connection

Special notes for your reviewer:

A corresponding change to Kubernetes is here: kubernetes-csi/node-driver-registrar#124

Does this PR introduce a user-facing change?:

mock driver: optionally proxy connections instead of handling them directly

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 4, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pohly

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

The pull request process is described here

Details 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 4, 2020
@msau42
Copy link
Collaborator

msau42 commented Jan 27, 2021

/assign @jsafrane @tsmetana

@k8s-ci-robot
Copy link
Contributor

@msau42: GitHub didn't allow me to assign the following users: tsmetana.

Note that only kubernetes-csi members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

Details

In response to this:

/assign @jsafrane @tsmetana

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.

@pohly
Copy link
Contributor Author

pohly commented Jan 29, 2021

We discussed a bit whether this functionality is needed and if so, where it should be implemented: kubernetes/kubernetes#97069 (comment)

limitations under the License.
*/

// Package proxy makes it possible to forward a listening socket in
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: is it necessary to repeat the documentation in a test file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, that wasn't intentional. Will remove it.

klog.V(5).Infof("proxy endpoint %s closed, shutting down", endpoint1)
return
}
go func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It took me a while to understand how this work. A separate goroutine for s2 is started to start accepting on s1 as soon as possible. OK, it looks working (a comment would be nice).

At the same time, the comment above says that kernel is accepting connections on listening sockets. Therefore, can the proxy call accept(s2) here, without a goroutine? Kernel will keep incoming connection on s1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way it is now we collect connections from s1 as quickly as they come in and only rely on the kernel for s2. But it is indeed asymmetric and harder to understand. I'll try with a simpler approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The unnecessary complex approach also had a race condition: conn1 might change between the two accepts.

By running the mock driver in proxy mode with the csi.sock made
available via another *listening* endpoint it becomes possible to run
the actual driver code elsewhere, for example embedded inside an
e2e.test binary.

The second endpoint can be a TCP port that can be reached from outside
of a Kubernetes cluster, either via a service or port-forwarding.

The same can be done with "socat UNIX-LISTEN:/csi/csi.sock,fork
TCP-LISTEN:9000,reuseport", but the implementation inside the mock
driver has some advantages compared to that:
- the same image as for normal mock driver testing can be used
- the mock driver keeps the second listen socket open at all times,
  so a client connecting to it doesn't get "connection refused"
  errors, which happens while socat hasn't forked to accept
  such a connection
@pohly
Copy link
Contributor Author

pohly commented Feb 4, 2021

@jsafrane: I've pushed the simplified proxy code, fixed the proxy_test.go comment and modified log levels slightly: when run at -v3, all we'll get from the container is the "proxy established a new connection between ..." message.

gRPC message logging will come from the embedded mock driver inside the e2e.test binary and the other sidecars (in particular, node-driver-registrar).

@pohly
Copy link
Contributor Author

pohly commented Feb 4, 2021

I've verified that the e2e.test still works with this: tests are still running, but it worked fine so far.

@jsafrane
Copy link
Contributor

jsafrane commented Feb 9, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 9, 2021
@k8s-ci-robot k8s-ci-robot merged commit 20d5af0 into kubernetes-csi:master Feb 9, 2021
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. 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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants