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

move an apiserver helper function out of pkg/proxy #118680

Merged

Conversation

danwinship
Copy link
Contributor

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

pkg/proxy/util contains the functions IsProxyableIP and IsProxyableHostname, but they don't belong there because pkg/proxy/util is "utility functions for kube-proxy" not "utility functions that involve the concept of 'proxying' in any sense".

I moved them to k8s.io/apimachinery/pkg/util/net but maybe there's a better place. (The only callers of the functions are in pkg/registry/core/node/strategy.go and pkg/registry/core/pod/strategy.go.)

(Related cleanup: #118120)

Does this PR introduce a user-facing change?

NONE

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

jiahuif commented Jun 15, 2023

/assign @apelisse
Could you take a look at this refactor? Thank you!
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 15, 2023
@@ -258,27 +214,29 @@ func MapCIDRsByIPFamily(cidrStrings []string) map[v1.IPFamily][]string {
return ipFamilyMap
}

func getIPFamilyFromIP(ipStr string) (v1.IPFamily, error) {
// Returns the IP family of ipStr, or "" if ipStr can't be parsed as an IP
func getIPFamilyFromIP(ipStr string) v1.IPFamily {
Copy link
Member

Choose a reason for hiding this comment

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

Not a big fan of this change, but I guess it doesn't really matter in practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered having it return (v1.IPFamily, bool) but it seemed pointless since the second value is completely redundant with the first, and it's not an exported API...

@apelisse
Copy link
Member

/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 Jun 15, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 9d96d4a4e9a01a659c98534e6f34d9284bb5c422

@aojea
Copy link
Member

aojea commented Jun 29, 2023

/lgtm
/approve
/assign @thockin

Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

Blech on the resting place for this.

Do we really need this as a util function? If so, does it really need to be a public API (apimachinery is more public, while k/k is not considered public - we don't support importing it)?

Is this a place where "a little copy is better than a little dep" applies? Could we just copy this to the 2 users? Simplified a bit, it's pretty trivial.

func IsProxyableIP(ip string) bool {
	netIP := netutils.ParseIPSloppy(ip)
	if netIP == nil {
		return false
	}
	return ip.IsGlobalUnicast()
}

If we need a util func, why not k/k/pkg/util/net (or similar) ?

@@ -241,7 +240,7 @@ func ResourceLocation(getter ResourceGetter, connection client.ConnectionInfoGet
return nil, nil, err
}

if err := proxyutil.IsProxyableHostname(ctx, &net.Resolver{}, info.Hostname); err != nil {
if err := utilnet.IsProxyableHostname(ctx, &net.Resolver{}, info.Hostname); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

@thockin is right, if this is only used here we can make it local right?

@danwinship
Copy link
Contributor Author

IsProxyableIP is small, IsProxyableHostname is little bigger...

I don't think k/util is right for it; this isn't a generic utility. I can't explain why it checks exactly the things that it checks and doesn't check anything else. It's basically tailored to its two existing users, and may not be appropriate for anyone else. I put it in apimachinery because it belongs to the apiserver, but yeah, you're right, that's too public too.

yeah, maybe just inline it...

@thockin
Copy link
Member

thockin commented Jun 29, 2023

Note we have k/utils which is ostensibly supported and has stong API promises, and we have k/k/pkg/util which is a random mishmash of internal BS with no real guarantees, and we have apimachinery/.../util which has some API guarantees but is less generic than k/utils.

I could live with inlining or k/k/pkg/utils

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 30, 2023
@danwinship
Copy link
Contributor Author

danwinship commented Jun 30, 2023

Oh, oops, I missed that you had said k/k/pkg/util/net not k/utils/net.

The big problem with adding k/k/pkg/util/net is that we already have k8s.io/apimachinery/pkg/util/net and k8s.io/utils/net, and if we try to add another utilnet/netutil package then no one will ever be able to figure out which functions are where or what they should call their imports. 🙂

I went with inlining. This means we lose the explicit unit tests for those two functions, but once you inline IsProxyableIP it becomes clear that you don't really need a unit test, and the unit test for IsProxyableHostname was one of those tests where it's really testing the support code for the unit test more than it's testing the actual function itself...

Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

Like a breath of fresh air!

/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 Jun 30, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: e5ee618fb46fccfa21b183ff78201c50bb5513cf

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aojea, apelisse, danwinship, thockin

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 Jun 30, 2023
@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

4 similar comments
@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

These don't belong in pkg/proxy/util; they involve a completely
unrelated definition of proxying.

Since each is only used from one place, just inline them at the
callers.
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 1, 2023
@k8s-ci-robot k8s-ci-robot requested a review from thockin July 1, 2023 12:50
@danwinship
Copy link
Contributor Author

ugh, sorry, gofmt

@aojea
Copy link
Member

aojea commented Jul 3, 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 Jul 3, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 450b670a1c28358d88c312ffec7a5f09809e55af

@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@k8s-ci-robot k8s-ci-robot merged commit a8cc22f into kubernetes:master Jul 3, 2023
12 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Jul 3, 2023
@danwinship danwinship deleted the not-that-kind-of-proxying branch July 3, 2023 12:31
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/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. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. 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. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants