-
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
CacheReader: DeepCopyObject on every Get/List method calls #1235
Comments
Not sure if there is a way to avoid it right now, if we don't deep copy the object users might modify the underlying cache object, which is incorrect and can cause headaches |
What do you think about extracting deepCopy into a separate object that also implements var _ client.Reader = &CopyCacheReader{}
type CopyCacheReader struct {
CacheReader
}
func (c *CopyCacheReader) Get(ctx context.Context, key client.ObjectKey, out runtime.Object) error {
copyOut := ...
if err := c.CacheReader.Get(ctx, key, copyOut); err != nil {
return err
}
copyOut = copyOut.(runtime.Object).DeepCopyObject()
// set 'copyOut' value to 'out'
return nil
}
func (c *CopyCacheReader) List(ctx context.Context, out runtime.Object, opts ...client.ListOption) error {
copyOut := ...
if err := c.CacheReader.List(ctx, copyOut, opts...); err != nil {
return err
}
// iterate over 'copyOut' and call DeepCopyObject for every item, set result to 'out'
return nil
} And then when calling Maybe you can recommend some other way to approach this problem. Because right now we have to create a fork and it's really difficult to maintain in a long run. |
@lobkovilya not using the If you have memory issues I recommend to set up indexes: https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#FieldIndexer |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
Rotten issues close after 30d of inactivity. Send feedback to sig-contributor-experience at kubernetes/community. |
@fejta-bot: Closing this issue. In response to this:
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. |
We are actively using
CacheReader
in our project and we faced a memory issue caused byDeepCopyObject
insideGet
andList
methods.CacheReader's
List
calls Indexer'sList
and then callsDeepCopyObject
for every object:But
Indexer
implemented bycache
has the following doc-comment for methodList
:And that's exactly our scenario. We call
CacheReader.List
from different goroutines and everywhere treat the result items as immutable.Is there any way to avoid
DeepCopyObject
and have this behavior parametrized?The text was updated successfully, but these errors were encountered: