-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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 configuration point to SharedInformer to transform objects before storing #107507
Add configuration point to SharedInformer to transform objects before storing #107507
Conversation
Hi @alexzielenski. 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. |
/hold I still need to add tests. Posting this PR in the meantime for comments. |
e78c531
to
03e7633
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.
I've modified the PR to use refactor SharedIndexInformer
to now share code with newInformer
. SharedIndexInformer
has a few quirks which required some minor changes but it did fit fairly nicely.
There is one hairy area around sending the notification on update events. The ResourceEventHandler
interface does not have an argument for the event type, so the original logic which silenced Sync notifications for non-sync listeners may be different and the new implementation needs to be looked at.
/triage accepted |
fc19d82
to
d992c5c
Compare
/hold cancel test added |
/ok-to-test /lgtm |
/lgtm cancel Test failure is relevant to this PR - please fix. |
…rts transformers avoids code duplication, allows transformer to be used with SharedIndexInformer
d992c5c
to
754bf3b
Compare
Test failure was a bug in the test. Since the transformer is run even for relists/updates it is important for it copy before mutating, if it is going to change the object. Otherwise, there is a potential data race. I've corrected the test and added a note to |
@wojtek-t Tests passing again. Please re-lgtm |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alexzielenski, wojtek-t 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 |
The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass. This bot retests PRs for certain kubernetes repos according to the following rules:
You can:
/retest |
currently blocked by #107708 |
The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass. This bot retests PRs for certain kubernetes repos according to the following rules:
You can:
/retest |
// | ||
// Must be set before starting the informer. | ||
// | ||
// Note: Since the object given to the handler may be already shared with |
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.
How does this happen? Seems like a sharedIndexInformer can only run once, and ProcessDeltas is called in controller.processLoop which is not concurrent.
DeepCopy may be expensive so given one of the primary use cases for this is performance it seems fairly important to not do extra work when not needed?
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.
When a relist of existing data occurs it is possible for handledeltas to be called multiple times for the same object. The first time the transformation is applied it the object instance will not have been shared. Assuming you have a way of marking an already- transformed object in order to skip repeated transformation applications then a copy should not be necessary.
// other goroutines, it is advisable to copy the object being | ||
// transform before mutating it at all and returning the copy to prevent | ||
// data races. | ||
SetTransform(handler TransformFunc) error |
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 am a bit concerned that if an error occurs there is, as far as I can tell, no logging at all. This bubbles up to processLoop
, which discards the error
|
||
// The TransformFunc is called for each object which is about to be stored. | ||
// | ||
// This function is intended for you to take the opportunity to |
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.
It would be helpful to list the limitations of this. Does the returned type have to be the same type as the input?
From what I can tell it does not but must implement runtime.Object
and metav1.ObjectMetaAccessor
or equivalent interfaces
Just curious, why we are using the transform function in We have a client program that uses reflector directly, and we'd like to use the object transform functionality. Is it ok we also add transform function to reflector.go as well |
What type of PR is this?
/kind feature
What this PR does / why we need it:
We have teams who use client-go's
SharedIndexInformer
through controller-runtime extensively. Some applications create caches for object metadata. These caches can have tens of thousands of objects. We have found that some our controllers are being OOM-killed more frequently recently since the addition ofmanagedFields
.This PR adds a configuration point to SharedInformer to arbitrarily transform the object before it is stored in the cache. We intend to use it to null out any large unused fields to save ram cost; since our controller cares only about a subset of the object's fields. It may also have other applications, as well.
Special notes for your reviewer:
Does this PR introduce a user-facing change?