@@ -54,7 +54,10 @@ type CacheReader struct {
5454}
5555
5656// Get checks the indexer for the object and writes a copy of it if found.
57- func (c * CacheReader ) Get (_ context.Context , key client.ObjectKey , out client.Object , _ ... client.GetOption ) error {
57+ func (c * CacheReader ) Get (_ context.Context , key client.ObjectKey , out client.Object , opts ... client.GetOption ) error {
58+ getOpts := client.GetOptions {}
59+ getOpts .ApplyOptions (opts )
60+
5861 if c .scopeName == apimeta .RESTScopeNameRoot {
5962 key .Namespace = ""
6063 }
@@ -81,7 +84,7 @@ func (c *CacheReader) Get(_ context.Context, key client.ObjectKey, out client.Ob
8184 return fmt .Errorf ("cache contained %T, which is not an Object" , obj )
8285 }
8386
84- if c .disableDeepCopy {
87+ if c .disableDeepCopy || ( getOpts . UnsafeDisableDeepCopy != nil && * getOpts . UnsafeDisableDeepCopy ) {
8588 // skip deep copy which might be unsafe
8689 // you must DeepCopy any object before mutating it outside
8790 } else {
@@ -97,7 +100,7 @@ func (c *CacheReader) Get(_ context.Context, key client.ObjectKey, out client.Ob
97100 return fmt .Errorf ("cache had type %s, but %s was asked for" , objVal .Type (), outVal .Type ())
98101 }
99102 reflect .Indirect (outVal ).Set (reflect .Indirect (objVal ))
100- if ! c .disableDeepCopy {
103+ if ! c .disableDeepCopy && ( getOpts . UnsafeDisableDeepCopy == nil || ! * getOpts . UnsafeDisableDeepCopy ) {
101104 out .GetObjectKind ().SetGroupVersionKind (c .groupVersionKind )
102105 }
103106
0 commit comments