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.
|
// 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
|
// Prefers a fully specified GroupVersionResource match. If one is not found, we match on a fully
|
||||||
// GroupVersionResource, or fallback to a match on GroupResource.
|
// specified GroupVersionKind, or fallback to a match on GroupKind.
|
||||||
func (b *Builder) mappingFor(resourceOrKindArg string) (*meta.RESTMapping, error) {
|
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)
|
fullySpecifiedGVK, groupKind := schema.ParseKindArg(resourceOrKindArg)
|
||||||
if fullySpecifiedGVK == nil {
|
if fullySpecifiedGVK == nil {
|
||||||
gvk := groupKind.WithVersion("")
|
gvk := groupKind.WithVersion("")
|
||||||
|
@ -611,27 +623,18 @@ func (b *Builder) mappingFor(resourceOrKindArg string) (*meta.RESTMapping, error
|
||||||
if !fullySpecifiedGVK.Empty() {
|
if !fullySpecifiedGVK.Empty() {
|
||||||
if mapping, err := b.mapper.RESTMapping(fullySpecifiedGVK.GroupKind(), fullySpecifiedGVK.Version); err == nil {
|
if mapping, err := b.mapper.RESTMapping(fullySpecifiedGVK.GroupKind(), fullySpecifiedGVK.Version); err == nil {
|
||||||
return mapping, nil
|
return mapping, nil
|
||||||
} else {
|
|
||||||
if mapping, err := b.mapper.RESTMapping(groupKind, ""); err == nil {
|
|
||||||
return mapping, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fullySpecifiedGVR, groupResource := schema.ParseResourceArg(resourceOrKindArg)
|
mapping, err := b.mapper.RESTMapping(groupKind, gvk.Version)
|
||||||
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 {
|
if err != nil {
|
||||||
return nil, err
|
// 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) {
|
func (b *Builder) resourceMappings() ([]*meta.RESTMapping, error) {
|
||||||
|
|
Loading…
Reference in New Issue