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

Test: use new intstr functions #117631

Merged
merged 1 commit into from
Aug 15, 2023

Conversation

skitt
Copy link
Member

@skitt skitt commented Apr 26, 2023

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

#116665 introduces intstr contructors from int32; this PR updates code to use them.

/hold pending #116665

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. 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. 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-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 26, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @skitt. Thanks for your PR.

I'm waiting for a kubernetes 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.

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 the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Apr 26, 2023
@k8s-ci-robot k8s-ci-robot added area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework area/test sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. sig/network Categorizes an issue or PR as relevant to SIG Network. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 26, 2023
@bart0sh bart0sh added this to Triage in SIG Node PR Triage Apr 26, 2023
@bart0sh
Copy link
Contributor

bart0sh commented Apr 27, 2023

/triage accepted
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed 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. labels Apr 27, 2023
@bart0sh bart0sh moved this from Triage to Needs Reviewer in SIG Node PR Triage Apr 27, 2023
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 5, 2023
This touches cases where FromInt() is used on numeric constants, or
values which are already int32s, or int variables which are defined
close by and can be changed to int32s with little impact.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
@skitt skitt force-pushed the intstr-fromint32-testing branch from d332970 to 3418cea Compare May 10, 2023 07:34
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 10, 2023
@k8s-ci-robot k8s-ci-robot requested a review from thockin May 10, 2023 07:34
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 10, 2023
@skitt skitt force-pushed the intstr-fromint32-testing branch from 3418cea to d332970 Compare May 13, 2023 12:04
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 13, 2023
@skitt skitt force-pushed the intstr-fromint32-testing branch from d332970 to 3418cea Compare May 13, 2023 12:07
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 13, 2023
@thockin
Copy link
Member

thockin commented Jul 11, 2023

Can you remind me why we didn't just change the original FromInt() to int32? It's not a public API.

@skitt
Copy link
Member Author

skitt commented Jul 12, 2023

Can you remind me why we didn't just change the original FromInt() to int32? It's not a public API.

I’m not sure it would have been tractable for me to convert everything in one PR (just from a review perspective; although at least in this PR most of the changes would have become unnecessary). It also turned out to be useful to keep the int version for a bunch of use-cases involving port numbers — getting that to be consistent is another battle...

@thockin
Copy link
Member

thockin commented Jul 12, 2023

It also turned out to be useful to keep the int version for a bunch of use-cases involving port numbers

I think it would be cleaner to call intstr.FromInt(int32(port)) that to have FromInt32() forever.

What about generics?

something like:

https://go.dev/play/p/noMl3HAd1h_z

Since it is internal, this seems legit to me.

@skitt
Copy link
Member Author

skitt commented Jul 12, 2023

Ah, digging into this some more I remember one of the concerns I had — the overflow check in https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr.go#L59 means that a plain FromInt() from a smaller type, used as FromInt(int32(foo)) for foo int would result in a change in behaviour (albeit extremely unlikely to cause problems in practice).

I like the generic approach to handle all smaller types, and I agree FromInt() is nicer to read than FromInt32() (but less explicit obviously).

@thockin
Copy link
Member

thockin commented Jul 12, 2023

This is an internal API - we can either change it and disallow anything larger than int32 via the type system or we can keep the (gross) range check, but that's really a vestigial artifact from pre-generic days.

@skitt
Copy link
Member Author

skitt commented Jul 13, 2023

I’ve done this as #119285, without using generics for two reasons — there are no users of FromInt() with types smaller than int32, and using a generic type means that all numeric constants need to be cast to one of the supported types.

@thockin
Copy link
Member

thockin commented Jul 14, 2023

using a generic type means that all numeric constants need to be cast to one of the supported types

How often do we need to use literals? If we use generics you need to cast literals and almost nothing else. If we don't use generics we have to cast almost everywhere, including literals. Why is it better to not use generics?

@skitt
Copy link
Member Author

skitt commented Jul 17, 2023

How often do we need to use literals? If we use generics you need to cast literals and almost nothing else. If we don't use generics we have to cast almost everywhere, including literals. Why is it better to not use generics?

105 times in the current code-base. (#119285 leaves 10 casts from non-literals.)

With the suggested generics,

type smallInt interface {
	int8 | int16 | int32
}

most current uses of non-literals need to be cast anyway (from int). We could use constraints.Integer or constraints.Signed to accept any integer type, relying on the existing comment that it’s up to callers to ensure that the given value fits in an int32; then no casts would ever be needed. That’s effectively what you’re suggesting in #119285 (comment) ;-).

(The code produced for generics isn’t great, see https://godbolt.org/z/WrK57rcP3, but that’s probably not worth worrying about here compared to the convenience factor.)

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.

Thanks!

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

LGTM label has been added.

Git tree hash: 49c40d31e22bc614db98ba6c3b361a1b65317766

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: skitt, 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 Jul 29, 2023
@k8s-ci-robot k8s-ci-robot merged commit 67c33fa into kubernetes:master Aug 15, 2023
18 of 19 checks passed
SIG Node PR Triage automation moved this from Needs Approver to Done Aug 15, 2023
@k8s-ci-robot k8s-ci-robot added this to the v1.29 milestone Aug 15, 2023
@skitt skitt deleted the intstr-fromint32-testing branch October 13, 2023 11:22
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/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework area/test 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. 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/apps Categorizes an issue or PR as relevant to SIG Apps. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. sig/network Categorizes an issue or PR as relevant to SIG Network. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/storage Categorizes an issue or PR as relevant to SIG Storage. 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. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants