mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
kubectl/resource: Remove thirdparty special casing
And also remove some duplicate code while I'm at it.
This commit is contained in:
parent
d1aa3dd0b4
commit
24c441e96d
@ -22,7 +22,6 @@ import (
|
|||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api/meta"
|
"k8s.io/kubernetes/pkg/api/meta"
|
||||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/registry/thirdpartyresourcedata"
|
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -54,20 +53,8 @@ func (m *Mapper) InfoForData(data []byte, source string) (*Info, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to decode %q: %v", source, err)
|
return nil, fmt.Errorf("unable to decode %q: %v", source, err)
|
||||||
}
|
}
|
||||||
var obj runtime.Object
|
|
||||||
var versioned runtime.Object
|
obj, versioned := versions.Last(), versions.First()
|
||||||
if isThirdParty, gvkOut, err := thirdpartyresourcedata.IsThirdPartyObject(data, gvk); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else if isThirdParty {
|
|
||||||
obj, err = runtime.Decode(thirdpartyresourcedata.NewDecoder(nil, gvkOut.Kind), data)
|
|
||||||
versioned = obj
|
|
||||||
gvk = gvkOut
|
|
||||||
} else {
|
|
||||||
obj, versioned = versions.Last(), versions.First()
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("unable to decode %q: %v [%v]", source, err, gvk)
|
|
||||||
}
|
|
||||||
mapping, err := m.RESTMapping(gvk.GroupKind(), gvk.Version)
|
mapping, err := m.RESTMapping(gvk.GroupKind(), gvk.Version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to recognize %q: %v", source, err)
|
return nil, fmt.Errorf("unable to recognize %q: %v", source, err)
|
||||||
|
@ -618,13 +618,7 @@ func RetrieveLatest(info *Info, err error) error {
|
|||||||
if info.Namespaced() && len(info.Namespace) == 0 {
|
if info.Namespaced() && len(info.Namespace) == 0 {
|
||||||
return fmt.Errorf("no namespace set on resource %s %q", info.Mapping.Resource, info.Name)
|
return fmt.Errorf("no namespace set on resource %s %q", info.Mapping.Resource, info.Name)
|
||||||
}
|
}
|
||||||
obj, err := NewHelper(info.Client, info.Mapping).Get(info.Namespace, info.Name, info.Export)
|
return info.Get()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
info.Object = obj
|
|
||||||
info.ResourceVersion, _ = info.Mapping.MetadataAccessor.ResourceVersion(obj)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetrieveLazy updates the object if it has not been loaded yet.
|
// RetrieveLazy updates the object if it has not been loaded yet.
|
||||||
|
Loading…
Reference in New Issue
Block a user