-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 TransformStripManagedFields #2791
✨ Add TransformStripManagedFields #2791
Conversation
01dce5f
to
742fa6c
Compare
a7015d9
to
85aa0fc
Compare
This change adds `TransformStripManagedFields` to the Cache, a transform func that strips off all managed fields for objects. There are no known issues when using this as a `DefaultTransform` unless there is explicit code to access objects `ManagedFields` and can lead to a significant reduction in memory usage.
85aa0fc
to
4cf9db0
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.
This is very useful when using client.Patch with Apply logic, thanks
/lgtm
/hold
if anyone wants to take a look
LGTM label has been added. Git tree hash: 8bfda55969144726bdabcfb9c7cad9a597b588a0
|
Thx!! /approve /hold cancel |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, Danil-Grigorev, sbueringer 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 patch adds support for stripping managed fields for objects entering the cache. The controller-runtime documentation for this transformer states: If you are not explicitly accessing managedFields from your code, setting this as `DefaultTransform` on the cache can lead to significant reduction in memory usage. Given that VM Operator never directly accesses the managed fields for any object, there is no reason we should not be using this transformer. Please see kubernetes-sigs/controller-runtime#2791 for more information on this feature.
This patch adds support for stripping managed fields for objects entering the cache. The controller-runtime documentation for this transformer states: If you are not explicitly accessing managedFields from your code, setting this as `DefaultTransform` on the cache can lead to significant reduction in memory usage. Given that VM Operator never directly accesses the managed fields for any object, there is no reason we should not be using this transformer. Please see kubernetes-sigs/controller-runtime#2791 for more information on this feature.
Howdy @alvaroaleman, How did you arrive at:
Per https://kubernetes.io/docs/reference/using-api/server-side-apply/:
Is the transformer from this PR not going to result in controllers sending patches/updates that no longer have the managed fields? For example, none of our controllers directly access managed fields, but we do write objects back to etcd, and if the cached object no longer has the managed fields, won't an update (we do use patch, but for example) remove the managed fields? Is it because an update from a controller-runtime manager client will have field manager ID of |
I think with patch, if you don't modify the managed fields in your code they simply won't be part of the delta and thus not part of the patch sent to the apiserver (so doesn't matter if they are there and don't have a diff or if they are not there and don't have a diff). It is definitely easily possible to Patch managedFields if you actually modify managed fields in your code. We're using this in some places in Cluster API. I have no experience with update. There I could imagine it might lead to problems |
This patch adds support for stripping managed fields for objects entering the cache. The controller-runtime documentation for this transformer states: If you are not explicitly accessing managedFields from your code, setting this as `DefaultTransform` on the cache can lead to significant reduction in memory usage. Given that VM Operator never directly accesses the managed fields for any object, there is no reason we should not be using this transformer. Please see kubernetes-sigs/controller-runtime#2791 for more information on this feature.
This patch adds support for stripping managed fields for objects entering the cache. The controller-runtime documentation for this transformer states: If you are not explicitly accessing managedFields from your code, setting this as `DefaultTransform` on the cache can lead to significant reduction in memory usage. Given that VM Operator never directly accesses the managed fields for any object, there is no reason we should not be using this transformer. Please see kubernetes-sigs/controller-runtime#2791 for more information on this feature.
If the above is true, then I do think the documentation for the transformer and description of this PR should be updated. Otherwise the current documentation makes it sound like there is zero downside for using the stripping transformer, but that may not be the case if folks are using |
Let's see if someone else knows more. I simply never tried what happens with Update, we are always using Patch |
So a quick test shows that update with nil managed fields does not clear them:
It should also be mentioned that upstream did this change for the controller-manager and scheduler), those two are what prompted me to do this change. According to that scheduler PR |
Nice! Thx for testing! So there is special handling for nil. I assume if some managedfields are set/modified it would update accordingly |
This change adds
TransformStripManagedFields
to the Cache, a transform func that strips off all managed fields for objects. There are no known issues when using this as aDefaultTransform
unless there is explicit code to access objectsManagedFields
and it can lead to a significant reduction in memory usage.