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.

Kubernetes-commit: 6dfae64d9bebb2c40680bbd6e8270f69839ab013
This commit is contained in:
Tim Hockin 2021-08-13 11:54:00 -07:00 committed by Kubernetes Publisher
parent 578388b70b
commit cf0112f87e
1 changed files with 3 additions and 0 deletions

View File

@ -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