Default ObjectNameFunc for all REST Stores

All Stores in Kubernetes follow the same logic for determining the name
of an object.  This change makes it so that CompleteWithOptions defaults
the ObjectNameFunc if it is not specified.  Thus a user does not need to
remember to use ObjectMeta.Name.  Using the wrong field as the name can
lead to an object which has a name that bypasses normal object name
validation.

Signed-off-by: Monis Khan <mkhan@redhat.com>
This commit is contained in:
Monis Khan
2017-04-21 15:47:25 -04:00
parent f613e66ad6
commit ed35deb69d
39 changed files with 124 additions and 228 deletions

View File

@@ -34,12 +34,9 @@ type REST struct {
// NewREST returns a RESTStorage object that will work against ClusterRole objects.
func NewREST(optsGetter generic.RESTOptionsGetter) *REST {
store := &genericregistry.Store{
Copier: api.Scheme,
NewFunc: func() runtime.Object { return &rbac.ClusterRole{} },
NewListFunc: func() runtime.Object { return &rbac.ClusterRoleList{} },
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*rbac.ClusterRole).Name, nil
},
Copier: api.Scheme,
NewFunc: func() runtime.Object { return &rbac.ClusterRole{} },
NewListFunc: func() runtime.Object { return &rbac.ClusterRoleList{} },
PredicateFunc: clusterrole.Matcher,
QualifiedResource: rbac.Resource("clusterroles"),
WatchCacheSize: cachesize.GetWatchCacheSizeByResource("clusterroles"),

View File

@@ -34,12 +34,9 @@ type REST struct {
// NewREST returns a RESTStorage object that will work against ClusterRoleBinding objects.
func NewREST(optsGetter generic.RESTOptionsGetter) *REST {
store := &genericregistry.Store{
Copier: api.Scheme,
NewFunc: func() runtime.Object { return &rbac.ClusterRoleBinding{} },
NewListFunc: func() runtime.Object { return &rbac.ClusterRoleBindingList{} },
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*rbac.ClusterRoleBinding).Name, nil
},
Copier: api.Scheme,
NewFunc: func() runtime.Object { return &rbac.ClusterRoleBinding{} },
NewListFunc: func() runtime.Object { return &rbac.ClusterRoleBindingList{} },
PredicateFunc: clusterrolebinding.Matcher,
QualifiedResource: rbac.Resource("clusterrolebindings"),
WatchCacheSize: cachesize.GetWatchCacheSizeByResource("clusterrolebindings"),

View File

@@ -34,12 +34,9 @@ type REST struct {
// NewREST returns a RESTStorage object that will work against Role objects.
func NewREST(optsGetter generic.RESTOptionsGetter) *REST {
store := &genericregistry.Store{
Copier: api.Scheme,
NewFunc: func() runtime.Object { return &rbac.Role{} },
NewListFunc: func() runtime.Object { return &rbac.RoleList{} },
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*rbac.Role).Name, nil
},
Copier: api.Scheme,
NewFunc: func() runtime.Object { return &rbac.Role{} },
NewListFunc: func() runtime.Object { return &rbac.RoleList{} },
PredicateFunc: role.Matcher,
QualifiedResource: rbac.Resource("roles"),
WatchCacheSize: cachesize.GetWatchCacheSizeByResource("roles"),

View File

@@ -34,12 +34,9 @@ type REST struct {
// NewREST returns a RESTStorage object that will work against RoleBinding objects.
func NewREST(optsGetter generic.RESTOptionsGetter) *REST {
store := &genericregistry.Store{
Copier: api.Scheme,
NewFunc: func() runtime.Object { return &rbac.RoleBinding{} },
NewListFunc: func() runtime.Object { return &rbac.RoleBindingList{} },
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*rbac.RoleBinding).Name, nil
},
Copier: api.Scheme,
NewFunc: func() runtime.Object { return &rbac.RoleBinding{} },
NewListFunc: func() runtime.Object { return &rbac.RoleBindingList{} },
PredicateFunc: rolebinding.Matcher,
QualifiedResource: rbac.Resource("rolebindings"),
WatchCacheSize: cachesize.GetWatchCacheSizeByResource("rolebindings"),