-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
✨ Add TransformFuncByObject Option for Informer Cache #1805
✨ Add TransformFuncByObject Option for Informer Cache #1805
Conversation
Welcome @alexzielenski! |
Hi @alexzielenski. Thanks for your PR. I'm waiting for a kubernetes-sigs 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. |
@alexzielenski Thanks. This is the first time I have seen kubernetes/kubernetes#107507 , it is awesome that we can reduce the cache size with Also this might have to wait for k8s v1.24 release to avoid alpha dependency in go.mod. |
reviving this PR now that 1.24 is being release |
f4b425a
to
603031f
Compare
603031f
to
b897b2f
Compare
@FillZpp What do you think of the new interface example usage below? It is a bit different from what we talked about on slack, because I still want to give control to only apply transformer to partialMetadata vs full objects. nodeMetadata := &metav1.PartialObjectMetadata{}
nodeMetadata.SetGroupVersionKind(schema.GroupVersionKind{
Group: "",
Version: "v1",
Kind: "Node",
})
ctrl.Options.NewCache = cache.BuilderWithOptions(cache.Options{
TransformFuncByObject: cache.TransformFuncByObject{
&corev1.Node{}: func(val interface{}) interface{} {
// Transformer for structured v1.Node
....
},
nodeMetadata: func(val interface{}) interface{} {
// Transformer for metadata v1.Node
....
}
}
}) |
/ok-to-test |
5db0fec
to
3cacf4a
Compare
/retitle ✨ Add TransformFuncByObject Option for Informer Cache |
7b28fd8
to
d451655
Compare
94002ac
to
5580820
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.
Two small points, other than that it looks good to me. @FillZpp is there anything left on your end?
flatten arrow code
/retest |
Yeah, I'm not sure if we should define some common transform functions so that most users don't have to search the source code to see how to implement it. (If yes, we should also discuss where to define these functions) func TransformStripManagedFields(obj interface{}) (interface{}, error) {
meta, err := apimeta.Accessor(obj)
if err != nil {
return nil, err
}
meta.SetManagedFields(nil)
return obj, nil
} It can be used for typed, Unstructured and PartialbjectMetadata objects. Another question, should we deep copy first or just modify the given object in the transform func? @alexzielenski |
We don't know how commonly wanted this is. This is definitely an advanced feature that might also serve as a footgun. I'd prefer to not do that unless we are certain that is something ppl are actually interested in.
The whole point is to manipulate the data in the cache directly, so no, no deepcopy. I am happy with the public api changes and there is decent test coverage, so lets merge this. @alexzielenski thanks for making this happen! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alexzielenski, alvaroaleman 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 |
This PR is a complement to a recent addition to client-go kubernetes/kubernetes#107507.
Adds two new
ForOption
s,OwnsOption
s, andWatchesOption
s to be used with the existingOnlyMetadata
calledWithoutAnnotations
andWithoutManagedFields
.Motivation
We have teams which make extensive use of metadata-only watches (tens of thousands of objects), which have seen sizable reductions in RAM usage when these fields are removed. This new options makes it easy and ergonomic to opt into stripping
managedFields
andannotations
metadata before they are persisted in the cache, to avoid wasting resources in controllers which do not use those fields.Implementation
Behind the scenes uses
SetTransform
onSharedIndexInformer
, and uses a transformer which respects the builders' elections for each GVK.Example Usage
The above line of code creates a controller whose cache is metadata-only and the annotations/managed fields have been stripped from the metadata.
Comments
I'm open to other ways to expose this new
SetTransform
API, but would prefer to have it specified near the builder sinceOnlyMetadata
is specified there as well. It seems natural to keep the different options for cache projections together.Additionally included is a go.mod update to a version of client-go which includes
SetTransform
. I am unsure if this PR is the best place to put it, or if another PR should be created updating all components in one shot.It should be noted that in my implementation
WithoutAnnotations
andWithoutManagedFields
only apply to thePartialObjectMeta
cache, and not unstructured/structured caches. This was intentional, since I did not see a reason to use it against other cache types. But this point may be worth discussing.