mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-27 15:39:39 +00:00
Scheme should provide ObjectTyper for Unstructured objects as well
This will allow us to recognize unstructured objects in the absence of server side discovery info. Kubernetes-commit: d77b95723c4fb67c87a0ec8c09d4054ae2c77ee1
This commit is contained in:
parent
fbdcd4b515
commit
de5d593c0d
@ -49,28 +49,22 @@ func NewUnstructuredObjectTyper(groupResources []*APIGroupResources) *Unstructur
|
|||||||
return dot
|
return dot
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 (d *UnstructuredObjectTyper) ObjectKind(obj runtime.Object) (schema.GroupVersionKind, error) {
|
|
||||||
if _, ok := obj.(runtime.Unstructured); !ok {
|
|
||||||
return schema.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
|
// 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
|
// provided object, or an error if the object is not runtime.Unstructured or
|
||||||
// has no group,version,kind information. unversionedType will always be false
|
// has no group,version,kind information. unversionedType will always be false
|
||||||
// because runtime.Unstructured object should always have group,version,kind
|
// because runtime.Unstructured object should always have group,version,kind
|
||||||
// information set.
|
// information set.
|
||||||
func (d *UnstructuredObjectTyper) ObjectKinds(obj runtime.Object) (gvks []schema.GroupVersionKind, unversionedType bool, err error) {
|
func (d *UnstructuredObjectTyper) ObjectKinds(obj runtime.Object) (gvks []schema.GroupVersionKind, unversionedType bool, err error) {
|
||||||
gvk, err := d.ObjectKind(obj)
|
if _, ok := obj.(runtime.Unstructured); !ok {
|
||||||
if err != nil {
|
return nil, false, fmt.Errorf("type %T is invalid for dynamic object typer", obj)
|
||||||
return nil, false, err
|
}
|
||||||
|
gvk := obj.GetObjectKind().GroupVersionKind()
|
||||||
|
if len(gvk.Kind) == 0 {
|
||||||
|
return nil, false, runtime.NewMissingKindErr("unstructured object has no kind")
|
||||||
|
}
|
||||||
|
if len(gvk.Version) == 0 {
|
||||||
|
return nil, false, runtime.NewMissingVersionErr("unstructured object has no version")
|
||||||
}
|
}
|
||||||
|
|
||||||
return []schema.GroupVersionKind{gvk}, false, nil
|
return []schema.GroupVersionKind{gvk}, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,16 +74,4 @@ func (d *UnstructuredObjectTyper) Recognizes(gvk schema.GroupVersionKind) bool {
|
|||||||
return d.registered[gvk]
|
return d.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 api.Registry.
|
|
||||||
func (d *UnstructuredObjectTyper) IsUnversioned(obj runtime.Object) (unversioned bool, ok bool) {
|
|
||||||
gvk, err := d.ObjectKind(obj)
|
|
||||||
if err != nil {
|
|
||||||
return false, false
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, d.registered[gvk]
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ runtime.ObjectTyper = &UnstructuredObjectTyper{}
|
var _ runtime.ObjectTyper = &UnstructuredObjectTyper{}
|
||||||
|
Loading…
Reference in New Issue
Block a user