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

Workqueue: Add generic versions that are properly typed #124263

Merged
merged 2 commits into from
Apr 24, 2024

Conversation

alvaroaleman
Copy link
Member

@alvaroaleman alvaroaleman commented Apr 10, 2024

This change adds a generic version of the various workqueue types while
retaining compatibility for the existing exported symbols and constructors.
The generic variants are prefixed with Typed and the existing ones are
marked as deprecated to nudge people to transition without breaking
them.

The first commit is the changes in the workqueue itself, the second changes the Customresource Discovery Controller to use a typed queue in order to demonstrate it.

/sig api-machinery
/kind cleanup

What type of PR is this?

What this PR does / why we need it:

Which issue(s) this PR fixes:

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 sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Apr 10, 2024
@k8s-ci-robot
Copy link
Contributor

Please note that we're already in Test Freeze for the release-1.30 branch. This means every merged PR will be automatically fast-forwarded via the periodic ci-fast-forward job to the release branch of the upcoming v1.30.0 release.

Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Wed Apr 10 19:46:29 UTC 2024.

@k8s-ci-robot k8s-ci-robot added 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. 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. area/apiserver area/cloudprovider area/kubelet sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. 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. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 10, 2024
@alvaroaleman alvaroaleman force-pushed the typed branch 3 times, most recently from 838640f to cf9fd42 Compare April 11, 2024 00:05
@alculquicondor
Copy link
Member

Was this discussed with SIG API machinery?

While I would like to see this change, it's highly disruptive to ecosystem controllers which use the client libraries, significantly increasing the cost of upgrading them.

@alvaroaleman
Copy link
Member Author

While I would like to see this change, it's highly disruptive to ecosystem controllers which use the client libraries, significantly increasing the cost of upgrading them.

Adding the generic type you want for your workqueue in the typedef and constructor is highly disruptive? It took me about two hours to do this for all of k/k. Additionally, if you use something like controller-runtime, you won't have to do anything.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 12, 2024
@alvaroaleman alvaroaleman changed the title Use generics in the workqueue Workqueue: Add generic versions that are properly typed Apr 12, 2024
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Apr 12, 2024

@alvaroaleman: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-e2e-autoscaling-hpa-cpu cf9fd42 link false /test pull-kubernetes-e2e-autoscaling-hpa-cpu

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@alculquicondor
Copy link
Member

The last similar thing we did was the introduction of typed pointer functions kubernetes/utils#283

As you can see, we created an alternate package. That could allow us to keep shorter function names. Although I'm not sure what an alternative name could be.

}

// DefaultControllerRateLimiter is a no-arg constructor for a default rate limiter for a workqueue. It has
// both overall and per-item rate limiting. The overall is a token bucket and the per-item is exponential
//
// Deprecated: Use DefaultTypedControllerRateLimiter instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

do we also deprecate RateLimiter? Why this symbol, but not many others in this change? (am just curious, no strong opinions. My gut feeling is that many of these are super-wide spread in the ecosystem).

Copy link
Member Author

Choose a reason for hiding this comment

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

Just that I missed it. If there are no objections I would like to deprecate all the untyped variants. It will not cause any build failures, but if ppl use linters they will nudge them to start using the typed variants.

func New() *Type {
return NewWithConfig(QueueConfig{
Name: "",
})
}

// NewTyped constructs a new work queue (see the package comment).
func NewTyped[T comparable]() *TypedType[T] {
Copy link
Contributor

Choose a reason for hiding this comment

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

TypedType is stuttering and looks kind of funny. Maybe just Typed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed it

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 19, 2024
@alvaroaleman
Copy link
Member Author

Rebased to incorporate #123347
It would be great if we could manage to get something like this merged before the next release in order to avoid publishing the non-generic Queue that was introduced in that change

ShutDown()
ShutDownWithDrain()
ShuttingDown() bool
}

// Queue is the underlying storage for items. The functions below are always
// called from the same goroutine.
type Queue interface {
type Queue[T comparable] interface {
Copy link
Member

Choose a reason for hiding this comment

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

Why does this struct not have the Typed approach? i.e.

type Queue TypedQueue[any]

type TypedQueue[T comparable] interface {

Copy link
Member Author

Choose a reason for hiding this comment

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

Because this got merged yesterday only and I went by the assumption that it is okay to break the interface, given that it has no users in k/k and is not in any released version: #123347

}

// DefaultQueue is a slice based FIFO queue.
func DefaultQueue() Queue {
return new(queue)
func DefaultQueue[T comparable]() Queue[T] {
Copy link
Member

Choose a reason for hiding this comment

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

Does this also need the Typed approach?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same as the above

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 19, 2024
This change adds a generic version of the various workqueue types while
retaining compatibility for the existing exported symbols and constructors.
The generic variants are prefixed with `Typed` and the existing ones are
marked as deprecated to nudge people to transition without breaking
them.
@sttts
Copy link
Contributor

sttts commented Apr 24, 2024

Did another pass. Looks good. From Slack I figure that everybody is on-board with the direction.

/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 Apr 24, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 3fa3ba435076b43d22c4fc0d0f67cb61b7301bca

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, sttts

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 Apr 24, 2024
@k8s-ci-robot k8s-ci-robot merged commit b3f5c57 into kubernetes:master Apr 24, 2024
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.31 milestone Apr 24, 2024
@alvaroaleman alvaroaleman deleted the typed branch April 26, 2024 07:39
mergenci added a commit to mergenci/upjet that referenced this pull request Jan 8, 2025
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/apiserver area/cloudprovider area/kubelet 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/apps Categorizes an issue or PR as relevant to SIG Apps. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. 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. 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.

8 participants