mirror of https://github.com/k3s-io/k3s
match KindFor first
parent
40143fd687
commit
177dcb998f
|
@ -599,9 +599,21 @@ func (b *Builder) SingleResourceType() *Builder {
|
|||
}
|
||||
|
||||
// mappingFor returns the RESTMapping for the Kind given, or the Kind referenced by the resource.
|
||||
// prefers a fully specified GroupVersionKind match. If we don't have one, match on a fully specified
|
||||
// GroupVersionResource, or fallback to a match on GroupResource.
|
||||
// Prefers a fully specified GroupVersionResource match. If one is not found, we match on a fully
|
||||
// specified GroupVersionKind, or fallback to a match on GroupKind.
|
||||
func (b *Builder) mappingFor(resourceOrKindArg string) (*meta.RESTMapping, error) {
|
||||
fullySpecifiedGVR, groupResource := schema.ParseResourceArg(resourceOrKindArg)
|
||||
gvk := schema.GroupVersionKind{}
|
||||
if fullySpecifiedGVR != nil {
|
||||
gvk, _ = b.mapper.KindFor(*fullySpecifiedGVR)
|
||||
}
|
||||
if gvk.Empty() {
|
||||
gvk, _ = b.mapper.KindFor(groupResource.WithVersion(""))
|
||||
}
|
||||
if !gvk.Empty() {
|
||||
return b.mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
|
||||
}
|
||||
|
||||
fullySpecifiedGVK, groupKind := schema.ParseKindArg(resourceOrKindArg)
|
||||
if fullySpecifiedGVK == nil {
|
||||
gvk := groupKind.WithVersion("")
|
||||
|
@ -611,27 +623,18 @@ func (b *Builder) mappingFor(resourceOrKindArg string) (*meta.RESTMapping, error
|
|||
if !fullySpecifiedGVK.Empty() {
|
||||
if mapping, err := b.mapper.RESTMapping(fullySpecifiedGVK.GroupKind(), fullySpecifiedGVK.Version); err == nil {
|
||||
return mapping, nil
|
||||
} else {
|
||||
if mapping, err := b.mapper.RESTMapping(groupKind, ""); err == nil {
|
||||
return mapping, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fullySpecifiedGVR, groupResource := schema.ParseResourceArg(resourceOrKindArg)
|
||||
gvk := schema.GroupVersionKind{}
|
||||
if fullySpecifiedGVR != nil {
|
||||
gvk, _ = b.mapper.KindFor(*fullySpecifiedGVR)
|
||||
}
|
||||
if gvk.Empty() {
|
||||
var err error
|
||||
gvk, err = b.mapper.KindFor(groupResource.WithVersion(""))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mapping, err := b.mapper.RESTMapping(groupKind, gvk.Version)
|
||||
if err != nil {
|
||||
// if we error out here, it is because we could not match a resource or a kind
|
||||
// for the given argument. To maintain consistency with previous behavior,
|
||||
// announce that a resource type could not be found.
|
||||
return nil, fmt.Errorf("the server doesn't have a resource type %q", groupResource.Resource)
|
||||
}
|
||||
|
||||
return b.mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
|
||||
return mapping, nil
|
||||
}
|
||||
|
||||
func (b *Builder) resourceMappings() ([]*meta.RESTMapping, error) {
|
||||
|
|
Loading…
Reference in New Issue