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
Generify lister-gen #121574
Generify lister-gen #121574
Conversation
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 Once the patch is verified, the new status will be reflected by the 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find this abusive AT ALL. I think this is exactly what generics are good for, and anything that reduces the LOC count of generated code is a win.
I'd love to see us explore a "v2" client which really leans into generics (even at the user-facing API) and uses less code generation. These codegen tools are crusty and hard to maintain and even harder to change (hence why my go-workspaces work has stalled).
resource schema.GroupResource | ||
} | ||
|
||
// Namespace wraps a lister and namespace for a given type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment and code don't match (type name)
Yes, I’ve been looking at two approaches, generifying the static client (without changing the external interface), and building a new client more along the lines of the dynamic client but using generics to produce concrete types instead of Go’s duck-typing means that clients can layer their own generic abstractions on top of K8s, e.g. submariner-io/admiral#756, but it would be nice to have a common layer everyone can use — and in a place where current limitations can be addressed (see the |
/ok-to-test |
/triage accepted |
013aa14
to
1acab76
Compare
I’ve updated the PR to address the linting issues, and also to leave |
1acab76
to
fdb4bc5
Compare
If this were broken into commits with "real work" and "regenerated code" it would help review. Who is the right approver for this? I love the idea, but I am not deeply familiar with this area |
LGTM label has been added. Git tree hash: dbbc5d6c9985e5c91887118dd54e6499fcff5267
|
583a6f9
to
f3e903b
Compare
/unhold |
/retest-required |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm picking nits now.
|
||
// NamespacedResourceIndexer wraps an indexer, resource, and namespace for a given type. | ||
// This is intended for use by listers (generated by lister-gen) only. | ||
type NamespacedResourceIndexer[T runtime.Object] struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea:
Why not just have 1 type:
ResourceIndexer[T runtime.Object] struct {
indexer cache.Indexer
resource schema.GroupResource
namespace string // empty for non-namespaced types
}
and then just test l.namespace
for empty. One code path, one type. Two
constructors functions (New
and NewNamespaced
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I had tried that and run into issues, but apparently not; I’ve updated the PR to use a single type.
f3e903b
to
b1c9544
Compare
/retest-required |
0900b01
to
3ba8de7
Compare
Signed-off-by: Stephen Kitt <skitt@redhat.com>
This adds a generic implementation of a lister, and uses it to replace the template code in generated listers. The corresponding templates are no longer used and are removed. Listers are reduced to their interfaces (non-namespaced and namespaced if appropriate), their specific structs, and their constructors. All method implementations are provided by the generic implementation. The dedicated interface is preserved so that each lister can have its own set of methods (e.g. the method returning the namespaced lister if appropriate), and the dedicated struct is preserved to allow expansions to be defined where necessary. The external interface is unchanged and doesn't expose generics. Signed-off-by: Stephen Kitt <skitt@redhat.com>
Signed-off-by: Stephen Kitt <skitt@redhat.com>
In particular, document that ListAllByNamespace delegates to ListAll if no namespace is specified. Signed-off-by: Stephen Kitt <skitt@redhat.com>
3ba8de7
to
54e8993
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
/lgtm
/approve
LGTM label has been added. Git tree hash: b6224f7179f65c79182ad89dcb2b461e7c371df6
|
[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 |
@skitt: The following test failed, say
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. |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
This adds a generic implementation of a lister, and uses it to replace the template code in generated listers. The corresponding templates are no longer used and are removed.
Listers are reduced to their interfaces (non-namespaced and namespaced if appropriate), their specific structs, and their constructors. All method implementations are provided by the generic implementation. The dedicated interface is preserved so that each lister can have its own set of methods (e.g. the method returning the namespaced lister if appropriate), and the dedicated struct is preserved to allow expansions to be defined where necessary.
The external interface is unchanged and doesn't expose generics.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
The core of this change is https://github.com/kubernetes/kubernetes/pull/121574/files#diff-8b2fc7ac28a79479e5ffb0b072f0b5d1b308ff4cb29daa3ae0657e23d200ac46 and https://github.com/kubernetes/kubernetes/pull/121574/files#diff-08b8fe190a6fe29b3cb7708a75aa9e7256459c4f7d941854d76eae79862ff56f — the rest of the change is generated code.
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: