Merge pull request #103545 from thockin/rest-create-deepcopy

REST: Document mutable inputs on Create() and fix tests

Kubernetes-commit: 358e5098639f1c160da7319237e53404d49a0525
This commit is contained in:
Kubernetes Publisher 2021-08-23 11:48:22 -07:00
commit 64b9c66d25
4 changed files with 17 additions and 11 deletions

8
go.mod
View File

@ -44,8 +44,8 @@ require (
google.golang.org/grpc v1.38.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/square/go-jose.v2 v2.2.2
k8s.io/api v0.0.0-20210820160405-5403b8c7f696
k8s.io/apimachinery v0.0.0-20210820200223-19d98351410f
k8s.io/api v0.0.0-20210823160431-2e3872a4612f
k8s.io/apimachinery v0.0.0-20210823160225-43d8bfe8f725
k8s.io/client-go v0.0.0-20210820200723-590eaed90a85
k8s.io/component-base v0.0.0-20210820041117-a191e9fae528
k8s.io/klog/v2 v2.9.0
@ -57,8 +57,8 @@ require (
)
replace (
k8s.io/api => k8s.io/api v0.0.0-20210820160405-5403b8c7f696
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210820200223-19d98351410f
k8s.io/api => k8s.io/api v0.0.0-20210823160431-2e3872a4612f
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210823160225-43d8bfe8f725
k8s.io/client-go => k8s.io/client-go v0.0.0-20210820200723-590eaed90a85
k8s.io/component-base => k8s.io/component-base v0.0.0-20210820041117-a191e9fae528
)

8
go.sum
View File

@ -932,10 +932,10 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.0.0-20210820160405-5403b8c7f696 h1:VeDLDi3k0cH4LwrHrza1S5RfNTS5Ke9a4cjDxwl0tes=
k8s.io/api v0.0.0-20210820160405-5403b8c7f696/go.mod h1:4L/pB8yzulD3folKSl90IBVQTkp2WH+Lc5oN9GGFyOg=
k8s.io/apimachinery v0.0.0-20210820200223-19d98351410f h1:/jTdlnzadZ/keFPHUc/agLHDhPCDBHYsl7Yj2tUDM4g=
k8s.io/apimachinery v0.0.0-20210820200223-19d98351410f/go.mod h1:9bsqX1kl7oIEzpNzAVhpZQ9E/AcXq62F+TCC81jicxo=
k8s.io/api v0.0.0-20210823160431-2e3872a4612f h1:2yD9i6wR5BmlzqVamiBG56pgB96NWEKI374nJoThCao=
k8s.io/api v0.0.0-20210823160431-2e3872a4612f/go.mod h1:9NII8izUMCcs10XIYvYhVPgZoYR8Svcxaj4ROCKZE5w=
k8s.io/apimachinery v0.0.0-20210823160225-43d8bfe8f725 h1:fkTd5iY1R9JSSTs2M1mwmzX6Cmepwnd/uj6vawk1+cg=
k8s.io/apimachinery v0.0.0-20210823160225-43d8bfe8f725/go.mod h1:9bsqX1kl7oIEzpNzAVhpZQ9E/AcXq62F+TCC81jicxo=
k8s.io/client-go v0.0.0-20210820200723-590eaed90a85 h1:l1bg5TOnjmD7AZcjimvppPVIJhgqWW77cnDGniuzKi4=
k8s.io/client-go v0.0.0-20210820200723-590eaed90a85/go.mod h1:b7BeUxg/uN2Me9ddwSuzQa2+asz8h3+840bxjk5v4ZI=
k8s.io/component-base v0.0.0-20210820041117-a191e9fae528 h1:rjkrYH4ht8L9NgoeMS6pHJ/PcCAnPatFz4tfR/Jotx4=

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

View File

@ -381,7 +381,8 @@ func (t *Tester) testCreateGeneratesName(valid runtime.Object) {
t.Fatalf("Unexpected error: %v", err)
}
defer t.delete(t.TestContext(), created)
if objectMeta.GetName() == "test-" || !strings.HasPrefix(objectMeta.GetName(), "test-") {
createdMeta := t.getObjectMetaOrFail(created)
if createdMeta.GetName() == "test-" || !strings.HasPrefix(createdMeta.GetName(), "test-") {
t.Errorf("unexpected name: %#v", valid)
}
}
@ -399,7 +400,8 @@ func (t *Tester) testCreateHasMetadata(valid runtime.Object) {
t.Fatalf("Unexpected object from result: %#v", obj)
}
defer t.delete(t.TestContext(), obj)
if !metav1.HasObjectMetaSystemFieldValues(objectMeta) {
createdMeta := t.getObjectMetaOrFail(obj)
if !metav1.HasObjectMetaSystemFieldValues(createdMeta) {
t.Errorf("storage did not populate object meta field values")
}
}
@ -501,7 +503,8 @@ func (t *Tester) testCreateResetsUserData(valid runtime.Object, opts metav1.Crea
t.Fatalf("Unexpected object from result: %#v", obj)
}
defer t.delete(t.TestContext(), obj)
if objectMeta.GetUID() == "bad-uid" || objectMeta.GetCreationTimestamp() == now {
createdMeta := t.getObjectMetaOrFail(obj)
if createdMeta.GetUID() == "bad-uid" || createdMeta.GetCreationTimestamp() == now {
t.Errorf("ObjectMeta did not reset basic fields: %#v", objectMeta)
}
}