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

✨ Introduce structured keys in pkg/cache #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MikeSpreitzer
Copy link

Summary

Did you know that a controller's workqueue contains any value, not necessarily a string? This PR adds a structured alternative to the common encoded string, relieving queue consumers from the complexity of coping with parsing errors. It is also a useful datatype in many other places.

Related issue(s)

Fixes #

@MikeSpreitzer MikeSpreitzer requested review from p0lyn0mial and removed request for davidfestal and stevekuznetsov March 21, 2023 19:31
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 21, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign sttts for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@MikeSpreitzer
Copy link
Author

/cc @vincepri

@openshift-ci openshift-ci bot requested a review from vincepri March 21, 2023 19:55
@MikeSpreitzer
Copy link
Author

@ezrasilvera

Copy link
Contributor

@stevekuznetsov stevekuznetsov left a comment

Choose a reason for hiding this comment

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

This is something we had some informal conversations about a couple years ago, the comments in the Kubernetes codebase seem to suggest that a) there was some thought to making this structured in the past and b) there were also concerns about allocations. It might be good to see if e.g. David Eads or Jordan Liggitt have in their memory some conversations on this topic. Certainly OK to add this as an opt-in option for controller authors, but if there are no real concerns with the approach it might be nice to get it to be the default, too.

// structured keys for API objects which implement meta.Interface.
// This is the structured alternative to MetaClusterNamespaceKeyFunc;
// putting such an object reference in a queue means that no parsing errors are possible downstream.
func ObjMetaClusterNamespaceKey(obj interface{}) (Key, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the convention is to call this a KeyFunc

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I never understood why the names of these functions have to end in "Func" while all the other functions do not require that. The more common use of the suffix "Func" is in the name of a type, not a function.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree! I only point it out since it might make it clearer for consumers that are used to that convention.

pkg/cache/keyfunc.go Show resolved Hide resolved
@MikeSpreitzer
Copy link
Author

MikeSpreitzer commented Mar 22, 2023

I am not sure I follow the concern about allocations. I am assuming that both boxing a string as an any and boxing a Key as an any require 1 allocation. Avoiding construction of the composite encoded string saves at least 1 allocation. I am assuming that function parameters and variables of type Key do not imply heap allocations.

I think this PR is written in such a way that it does introduce an "opt in".

@stevekuznetsov
Copy link
Contributor

I'm not entirely clear on the allocation concerns but I think it was moreso the allocation for the Key{} as opposed to the string, not the boxing - but in any case if it's opt-in, I don't think it matters much. This PR LGTM - @sttts any thoughts?

@MikeSpreitzer
Copy link
Author

The upstream version of this is kubernetes/kubernetes#116869

@xrstf
Copy link
Contributor

xrstf commented Jun 12, 2023

Closing & re-opening the PR to trigger the new CI setup. Please do not be alarmed :)

@xrstf xrstf closed this Jun 12, 2023
@xrstf xrstf reopened this Jun 12, 2023
@kcp-ci-bot kcp-ci-bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jun 12, 2023
@kcp-ci-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign sttts for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@kcp-ci-bot kcp-ci-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 12, 2023
@kcp-ci-bot
Copy link
Contributor

@MikeSpreitzer: 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-apimachinery-lint f0b0334 link true /test pull-apimachinery-lint

Full PR test history

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has signed the DCO. 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.

4 participants