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>

Kubernetes-commit: ed35deb69d6fe480adc9178c30b4b9c9e03ca1a9
This commit is contained in:
Monis Khan 2017-04-21 15:47:25 -04:00 committed by Kubernetes Publisher
parent 32da3a6527
commit c4cc6eba8b
1 changed files with 10 additions and 0 deletions

View File

@ -1194,6 +1194,16 @@ func (e *Store) CompleteWithOptions(options *generic.StoreOptions) error {
e.EnableGarbageCollection = opts.EnableGarbageCollection
if e.ObjectNameFunc == nil {
e.ObjectNameFunc = func(obj runtime.Object) (string, error) {
accessor, err := meta.Accessor(obj)
if err != nil {
return "", err
}
return accessor.GetName(), nil
}
}
if e.Storage == nil {
capacity := DefaultWatchCacheSize
if e.WatchCacheSize != 0 {