@@ -30,6 +30,7 @@ import (
30
30
"k8s.io/apimachinery/pkg/runtime"
31
31
"k8s.io/apimachinery/pkg/runtime/schema"
32
32
utilrand "k8s.io/apimachinery/pkg/util/rand"
33
+ "k8s.io/apimachinery/pkg/util/validation/field"
33
34
"k8s.io/client-go/kubernetes/scheme"
34
35
"k8s.io/client-go/testing"
35
36
@@ -85,6 +86,12 @@ func (t versionedTracker) Create(gvr schema.GroupVersionResource, obj runtime.Ob
85
86
if err != nil {
86
87
return err
87
88
}
89
+ if accessor .GetName () == "" {
90
+ return apierrors .NewInvalid (
91
+ obj .GetObjectKind ().GroupVersionKind ().GroupKind (),
92
+ accessor .GetName (),
93
+ field.ErrorList {field .Required (field .NewPath ("metadata.name" ), "name is required" )})
94
+ }
88
95
if accessor .GetResourceVersion () != "" {
89
96
return apierrors .NewBadRequest ("resourceVersion can not be set for Create requests" )
90
97
}
@@ -97,6 +104,12 @@ func (t versionedTracker) Update(gvr schema.GroupVersionResource, obj runtime.Ob
97
104
if err != nil {
98
105
return fmt .Errorf ("failed to get accessor for object: %v" , err )
99
106
}
107
+ if accessor .GetName () == "" {
108
+ return apierrors .NewInvalid (
109
+ obj .GetObjectKind ().GroupVersionKind ().GroupKind (),
110
+ accessor .GetName (),
111
+ field.ErrorList {field .Required (field .NewPath ("metadata.name" ), "name is required" )})
112
+ }
100
113
oldObject , err := t .ObjectTracker .Get (gvr , ns , accessor .GetName ())
101
114
if err != nil {
102
115
return err
0 commit comments