Skip to content

Add generics policy for kubernetes #6693

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

Merged
merged 1 commit into from
Aug 2, 2022

Conversation

BenTheElder
Copy link
Member

as discussed in the last SIG Architecture meeting

Which issue(s) this PR fixes:

cc @dims @johnbelamaric

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 7, 2022
@k8s-ci-robot k8s-ci-robot added the sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. label Jun 7, 2022
@BenTheElder BenTheElder force-pushed the add-generics-draft branch from c74b1ee to 374ad75 Compare June 9, 2022 18:15
Consider if proposed generics pull requests improve maintainability and readability.

The current generics implementation is known to have some performance issues
depending on usage: consider requesting benchmarks before / after the changes.
Copy link
Member Author

Choose a reason for hiding this comment

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

added

@BenTheElder BenTheElder changed the title [WIP] add generics policy draft add generics policy draft Jun 9, 2022
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 9, 2022
@dims
Copy link
Member

dims commented Jun 9, 2022

/assign @johnbelamaric @derekwaynecarr
/approve
/lgtm
/hold for additional reviewers

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 9, 2022
@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jun 9, 2022
@BenTheElder BenTheElder force-pushed the add-generics-draft branch from 374ad75 to 1553956 Compare June 9, 2022 18:18
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 9, 2022
@dims
Copy link
Member

dims commented Jun 9, 2022

/retitle Add generics policy for kubernetes

@k8s-ci-robot k8s-ci-robot changed the title add generics policy draft Add generics policy for kubernetes Jun 9, 2022
Copy link
Member

@liggitt liggitt left a comment

Choose a reason for hiding this comment

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

looks like a good starting point, had a couple questions


Generics may be used in Kubernetes starting in v1.25

Avoid generics when writing bug fixes until v1.24 is [out of support][version-support], to ease
Copy link
Member

Choose a reason for hiding this comment

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

+1 to this guidance

in case we ran into other issues and needed to roll back to unblock the release.
Now that v1.24.0 is out, use of generics should be unrestricted.

# Generics Policy
Copy link
Member

Choose a reason for hiding this comment

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

should we have guidance for use of generics in our libraries consumed by multiple branches of kubernetes, like k8s.io/utils, k8s.io/kube-openapi, etc? xref discussion in kubernetes/utils#243 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

Great point, we only discussed this from the staging library angle previously.

We should add a note similar to the bug fixes guidance, but as a hard requirement, I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

I rewrote this a bit to position limitations until v1.24 is out of support and address this point.

Copy link
Member

@liggitt liggitt Jul 29, 2022

Choose a reason for hiding this comment

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

looks fine as a starting point. we could maybe relax the guidance to allow use of generics in those repos in ways that would still support go1.17 (go-version conditional files, etc), but I'm not familiar with how possible/fiddly that is... we'd want to be really confident in the implications before doing so, I guess

Copy link
Member Author

Choose a reason for hiding this comment

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

Even if technically possible (I think so with build tags?) I don’t think we want to allow this versus waiting a few more releases just because it’s very similar to starting to support multiple branches of these libraries from a support perspective and we don’t do that today in any I can think of.

- Consider if proposed generics pull requests improve maintainability and readability.

- The current generics implementation is known to have some performance issues
depending on usage: consider requesting benchmarks before / after the changes.
Copy link
Member

Choose a reason for hiding this comment

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

are there any links to the known perf issues to give hints to where generics might not be appropriate yet?

Copy link
Member Author

@BenTheElder BenTheElder Jul 29, 2022

Choose a reason for hiding this comment

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

I didn't want to put information into this doc that would become out of date as go improves and measuring > "knowing", but in the initial go1.18 implementation at least generics are only partially monomorphized by GCShape and have an additional indirection at runtime for the method dictionaries.

So they pretty universally cost more, but that may still be justified by type safety and maintainability if you can keep it out of hot paths => avoid developer pain from code generation.

https://github.com/golang/proposal/blob/master/design/generics-implementation-dictionaries-go1.18.md

https://planetscale.com/blog/generics-can-make-your-go-code-slower

I'd like to think a suitable usage for now looks like:
https://github.com/kubernetes-sigs/oci-proxy/blob/f60b1fc751c6a65225aee8f9363d32cb8e0aa54b/pkg/net/cidrs/triemap.go
(not in hotpath, still typesafe, used internally)

Copy link
Member

Choose a reason for hiding this comment

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

I didn't want to put information into this doc that would become out of date as go improves and measuring > "knowing"

fair enough

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 29, 2022
@liggitt
Copy link
Member

liggitt commented Jul 29, 2022

lgtm

@thockin
Copy link
Member

thockin commented Jul 29, 2022

I like it!

In Kubernetes v1.24 we shipped Go 1.18 (which adds support for generics)
rather late in the release cycle, so we temporarily prohibited using generics
in case we ran into other issues and needed to roll back to unblock the release.
Now that v1.24.0 is out, use of generics should be unrestricted.
Copy link
Member Author

Choose a reason for hiding this comment

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

nit: this says "[...] use of generics should be unrestricted" but then below we now say "Generics may be used in Kubernetes starting in v1.25, with the following restrictions applying only until v1.24 is [out of support]"

may simply change this to "[...] use of generics should be allowed."

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

as discussed in the last SIG Architecture meeting
@dims
Copy link
Member

dims commented Aug 2, 2022

/approve
/lgtm

/hold cancel

Let's merge and iterate if needed

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Aug 2, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: BenTheElder, dims

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 merged commit 692d830 into kubernetes:master Aug 2, 2022
@BenTheElder BenTheElder deleted the add-generics-draft branch August 2, 2022 19:19
@dims
Copy link
Member

dims commented Aug 16, 2022

saving some urls here for later :)

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. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants