diff --git a/pkg/cache/internal/cache_reader.go b/pkg/cache/internal/cache_reader.go index 107f20fa6b..4928641ec2 100644 --- a/pkg/cache/internal/cache_reader.go +++ b/pkg/cache/internal/cache_reader.go @@ -161,7 +161,7 @@ func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...cli } var outObj runtime.Object - if c.disableDeepCopy { + if c.disableDeepCopy || listOpts.DisableDeepCopy { // skip deep copy which might be unsafe // you must DeepCopy any object before mutating it outside outObj = obj diff --git a/pkg/client/options.go b/pkg/client/options.go index e56a538bea..5c33d7cbce 100644 --- a/pkg/client/options.go +++ b/pkg/client/options.go @@ -417,6 +417,11 @@ type ListOptions struct { // it has expired. This field is not supported if watch is true in the Raw ListOptions. Continue string + // disableDeepCopy indicates not to deep copy objects during list objects. + // Be very careful with this, when enabled you must DeepCopy any object before mutating it, + // otherwise you will mutate the object in the cache. + DisableDeepCopy bool + // Raw represents raw ListOptions, as passed to the API server. Note // that these may not be respected by all implementations of interface, // and the LabelSelector, FieldSelector, Limit and Continue fields are ignored.