Remove runtime.Typer, reduce to ObjectKinds(1) (3)

Remove the unnecessary variants, which avoids allocations in several
core paths.
This commit is contained in:
Clayton Coleman
2016-05-21 00:15:31 -04:00
parent a24936355e
commit c6961d6fd6
38 changed files with 159 additions and 210 deletions

View File

@@ -76,28 +76,15 @@ func NewObjectTyper(resources []*unversioned.APIResourceList) (runtime.ObjectTyp
return ot, nil
}
// ObjectKind returns the group,version,kind of the provided object,
// or an error if the object in not *runtime.Unstructured or has no
// group,version,kind information.
func (ot *ObjectTyper) ObjectKind(obj runtime.Object) (unversioned.GroupVersionKind, error) {
if _, ok := obj.(*runtime.Unstructured); !ok {
return unversioned.GroupVersionKind{}, fmt.Errorf("type %T is invalid for dynamic object typer", obj)
}
return obj.GetObjectKind().GroupVersionKind(), nil
}
// ObjectKinds returns a slice of one element with the
// group,version,kind of the provided object, or an error if the
// object is not *runtime.Unstructured or has no group,version,kind
// information.
func (ot *ObjectTyper) ObjectKinds(obj runtime.Object) ([]unversioned.GroupVersionKind, error) {
gvk, err := ot.ObjectKind(obj)
if err != nil {
return nil, err
func (ot *ObjectTyper) ObjectKinds(obj runtime.Object) ([]unversioned.GroupVersionKind, bool, error) {
if _, ok := obj.(*runtime.Unstructured); !ok {
return nil, false, fmt.Errorf("type %T is invalid for dynamic object typer", obj)
}
return []unversioned.GroupVersionKind{gvk}, nil
return []unversioned.GroupVersionKind{obj.GetObjectKind().GroupVersionKind()}, false, nil
}
// Recognizes returns true if the provided group,version,kind was in
@@ -105,15 +92,3 @@ func (ot *ObjectTyper) ObjectKinds(obj runtime.Object) ([]unversioned.GroupVersi
func (ot *ObjectTyper) Recognizes(gvk unversioned.GroupVersionKind) bool {
return ot.registered[gvk]
}
// IsUnversioned returns false always because *runtime.Unstructured
// objects should always have group,version,kind information set. ok
// will be true if the object's group,version,kind is registered.
func (ot *ObjectTyper) IsUnversioned(obj runtime.Object) (unversioned bool, ok bool) {
gvk, err := ot.ObjectKind(obj)
if err != nil {
return false, false
}
return false, ot.registered[gvk]
}