From 6dfae64d9bebb2c40680bbd6e8270f69839ab013 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 13 Aug 2021 11:54:00 -0700 Subject: [PATCH] REST: Document mutable inputs on Create() If one doesn't DeepCopy() on the way into Create, we can end up writing into the original object. This is by design, and should not be a problem EXCEPT for tests. If a test compares the input to this function with the result, but the input was mutated in-situ, it may hide errors, resulting in tests that pass, but shouldn't. --- .../k8s.io/apiserver/pkg/registry/generic/registry/store.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go b/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go index ec9870a035a..d94627834da 100644 --- a/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go +++ b/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go @@ -360,6 +360,9 @@ func (e *Store) ListPredicate(ctx context.Context, p storage.SelectionPredicate, func finishNothing(context.Context, bool) {} // Create inserts a new item according to the unique key from the object. +// Note that registries may mutate the input object (e.g. in the strategy +// hooks). Tests which call this might want to call DeepCopy if they expect to +// be able to examine the input and output objects for differences. func (e *Store) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) { var finishCreate FinishFunc = finishNothing