From 36d84ae894e8d87d351e981740cd8417e5ffd490 Mon Sep 17 00:00:00 2001 From: qiankunli Date: Mon, 5 Dec 2022 21:33:57 +0800 Subject: [PATCH] feat: supprot disable deepcopy on list funcion Signed-off-by: qiankunli --- pkg/cache/internal/cache_reader.go | 2 +- pkg/client/options.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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.