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

merge duplicated linux/windows kube-proxy setup code #118017

Merged
merged 2 commits into from May 25, 2023

Conversation

danwinship
Copy link
Contributor

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

There is currently a lot of duplicated code between the linux (iptables/ipvs) and windows (winkernel) kube-proxy setup. This extracts it out to the shared code, along with a bit of other platform-related refactoring.

extracted from #117436

Does this PR introduce a user-facing change?

NONE

/sig network

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. sig/network Categorizes an issue or PR as relevant to SIG Network. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels May 15, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot k8s-ci-robot added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/ipvs area/kube-proxy approved Indicates a PR has been approved by an approver from all required OWNERS files. labels May 15, 2023
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 15, 2023
@danwinship
Copy link
Contributor Author

Hm... initial push failed CI because replacing server_others.go with server_linux.go broke the kube-proxy build on OS X, which is surprising given that we don't build kube-proxy on OS X. I "fixed" this, but I feel like this is a build system bug, and I'm wondering if maybe I should just remove the server_others.goserver_linux.go renaming until it's fixed...

@aojea
Copy link
Member

aojea commented May 15, 2023

Hm... initial push failed CI because replacing server_others.go with server_linux.go broke the kube-proxy build on OS X, which is surprising given that we don't build kube-proxy on OS X.

@BenTheElder may have more historical context, or @dims

@dims
Copy link
Member

dims commented May 15, 2023

For a few tools like verify-typecheck.sh it's easier to at least build these things even if we don't ship them

@BenTheElder
Copy link
Member

BenTheElder commented May 15, 2023

For a few tools like verify-typecheck.sh it's easier to at least build these things even if we don't ship them

IIRC verify-typecheck.sh is setting both GOOS and GOARCH to target the platforms we build for, it shouldn't need to build this for mac.

I have no idea why we'd build kube-proxy for mac, we aren't in releases?

It is nice to have code compile in IDEs and run tests, but if it's calling out to OS specific stuff then that doesn't help a lot.

I would guess we just refactored to add windows support and added !windows where linux was more appropriate.

@humblec
Copy link
Contributor

humblec commented May 16, 2023

I have no idea why we'd build kube-proxy for mac, we aren't in releases?

@BenTheElder don't we have kube-proxy for Mac in downloads (https://kubernetes.io/releases/download/#container-images)? if it was the thing you were mentioning above.

@BenTheElder
Copy link
Member

@BenTheElder don't we have kube-proxy for Mac in downloads (https://kubernetes.io/releases/download/#container-images)? if it was the thing you were mentioning above.

Er no? What would a Mac container image look like?

The kube-proxy image in the release notes is only for Linux, not even Windows.
https://explore.ggcr.dev/?image=registry.k8s.io%2Fkube-proxy%3Av1.27.1

We have Linux and Windows binaries for some node components.
We have Linux only for server components (kube-apiserver etc.)
And for macOS we have kubectl and kubectl plugins AFAIK:

$ gsutil ls gs://kubernetes-release/release/v1.27.0/bin/darwin/amd64
gs://kubernetes-release/release/v1.27.0/bin/darwin/amd64/kubectl
gs://kubernetes-release/release/v1.27.0/bin/darwin/amd64/kubectl-convert
gs://kubernetes-release/release/v1.27.0/bin/darwin/amd64/kubectl-convert.cert
gs://kubernetes-release/release/v1.27.0/bin/darwin/amd64/kubectl-convert.sha256
gs://kubernetes-release/release/v1.27.0/bin/darwin/amd64/kubectl-convert.sha512
gs://kubernetes-release/release/v1.27.0/bin/darwin/amd64/kubectl-convert.sig
gs://kubernetes-release/release/v1.27.0/bin/darwin/amd64/kubectl.cert
gs://kubernetes-release/release/v1.27.0/bin/darwin/amd64/kubectl.sha256
gs://kubernetes-release/release/v1.27.0/bin/darwin/amd64/kubectl.sha512
gs://kubernetes-release/release/v1.27.0/bin/darwin/amd64/kubectl.si

@uablrek
Copy link
Contributor

uablrek commented May 16, 2023

I don't understand what's wrong in;

kubernetes > ./hack/update-gofmt.sh
go version go1.20.4 linux/amd64
error: size of cmd/kube-proxy/app/server_others.go changed during reading (from 1311 to 1310 bytes)

@humblec
Copy link
Contributor

humblec commented May 16, 2023

The kube-proxy image in the release notes is only for Linux, not even Windows. https://explore.ggcr.dev/?image=registry.k8s.io%2Fkube-proxy%3Av1.27.1

We have Linux and Windows binaries for some node components. We have Linux only for server components (kube-apiserver etc.) And for macOS we have kubectl and kubectl plugins AFAIK:

hmmm..looks like above is correct assumption. we can see windows binaries of kube-proxy available @https://www.downloadkubernetes.com though, not sure why those are missing in release notes.

@danwinship
Copy link
Contributor Author

danwinship commented May 16, 2023

Sorry, I didn't provide a ton of context on the build stuff because I didn't mean for this bug to turn into a discussion of that (see #118020 instead). But to clarify since different people seem to be missing different parts of the context;

  1. hack/lib/golang.sh has a bunch of variables that control which things get built on which platforms. On OS X, we intentionally only build kubectl and e2e.test (more or less). This is not a bug.

  2. Prior to this PR, the Windows kube-proxy backend was handled by cmd/kube-proxy/app/server_windows.go and the Linux-specific backends (iptables/ipvs) were handled by cmd/kube-proxy/app/server_others.go. And in fact, although our normal build processes do not build kube-proxy on OS X, it actually was possible to "make WHAT=cmd/kube-proxy" by hand on OS X, and you'd end up with a copy of the Linux kube-proxy which you could run on OS X and it would immediately error out because it couldn't find an "iptables" binary.

  3. Given that it doesn't make sense to build a Linux-specific kube-proxy backend on non-Linux platforms, I decided to redo the file names and build tags to clarify that the iptables and ipvs kube-proxy backends were only for "linux", not for "others"/"!windows".

  4. Surprisingly, given point 1, making the change in point 3 caused verify-typecheck to fail on OS X, because verify-typecheck was trying to build kube-proxy, and kube-proxy now had missing symbols on any platform except linux and windows. (EDIT: This isn't about GOOS/GOARCH, it's about what directories verify-typecheck chooses to try to build in.)

  5. (For now, I fixed point 4 by adding back a stub server_others.go file so that now you can build and run kube-proxy on OS X and it will immediately error out with a message about not supporting this platform.)

@BenTheElder
Copy link
Member

I don't know who is depending on this, but for reference @ 3588d09 (current master)

$ git rev-parse HEAD
3588d091ff3549b50e9c993b12b169b4caeb105f

$ uname
Darwin

$ go build -o ./kubelet ./cmd/kubelet

$ ./kubelet
E0516 11:13:54.187405   69372 run.go:74] "command failed" err="failed to construct kubelet dependencies: mkdir /var/lib/kubelet: permission denied"

$ go build -o ./kube-proxy ./cmd/kube-proxy

$ ./kube-proxy
I0516 11:17:04.538852   69859 server.go:233] "Warning, all flags other than --config, --write-config-to, and --cleanup are deprecated, please begin using a config file ASAP"
I0516 11:17:04.539004   69859 server_others.go:75] "Using iptables proxy"
I0516 11:17:04.539251   69859 server.go:531] "Neither kubeconfig file nor master URL was specified, falling back to in-cluster config"
E0516 11:17:04.539272   69859 server.go:484] "Error running ProxyServer" err="unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined"
E0516 11:17:04.539290   69859 run.go:74] "command failed" err="unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined"

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 22, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danwinship

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

@danwinship
Copy link
Contributor Author

I "fixed" this, but I feel like this is a build system bug, and I'm wondering if maybe I should just remove the server_others.goserver_linux.go renaming until it's fixed...

(done)

Move the Linux-specific conntrack setup code into a new
"platformSetup" rather than trying to fit it into the generic setup
code.

Also move metrics registration there.
@aojea
Copy link
Member

aojea commented May 24, 2023

Unexpected final error while getting *v1.Pod: etcdserver: request timed out
At one point, however, the function did return successfully.

weird failures

/test pull-kubernetes-e2e-kind-ipv6

@@ -329,7 +328,6 @@ func newProxyServer(
if err != nil {
return nil, fmt.Errorf("unable to create proxier: %v", err)
}
proxymetrics.RegisterMetrics()
Copy link
Member

Choose a reason for hiding this comment

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

this was kind of weird, no? initializing in two different places instead doing just in one, maybe a copy paste thing

@@ -319,7 +322,7 @@ func (o *Options) Run() error {
return cleanupAndExit()
}

proxyServer, err := NewProxyServer(o)
Copy link
Member

Choose a reason for hiding this comment

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

I hope nobody is importing this

@aojea
Copy link
Member

aojea commented May 25, 2023

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 25, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 151d8ac0e7f0e6bcba0e8a8165d657ad8dc2e284

NodeRef *v1.ObjectReference
HealthzServer healthcheck.ProxierHealthUpdater
Hostname string
Copy link
Member

Choose a reason for hiding this comment

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

this could be internal variables

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean hostname rather than Hostname? yeah, the whole struct is wrong that way

Copy link
Member

Choose a reason for hiding this comment

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

yep yep

@k8s-ci-robot k8s-ci-robot merged commit d8e9a7b into kubernetes:master May 25, 2023
13 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone May 25, 2023
@danwinship danwinship deleted the kube-proxy-platform branch May 26, 2023 12:38
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/ipvs area/kube-proxy cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/network Categorizes an issue or PR as relevant to SIG Network. 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.

None yet

7 participants