Skip to content

Commit

Permalink
feat: supprot disable deepcopy on list funcion
Browse files Browse the repository at this point in the history
Signed-off-by: qiankunli <qiankun.li@qq.com>
  • Loading branch information
qiankunli authored and qiankunli committed Dec 5, 2022
1 parent d991225 commit 4595915
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/cache/internal/cache_reader.go
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/client/options.go
Expand Up @@ -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.
Expand Down

0 comments on commit 4595915

Please sign in to comment.