mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #60932 from juanvallejo/jvallejo/fix-builder-mapping
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Prefer GroupVersionResource, fallback to GVK **Release note**: ```release-note NONE ``` Addresses https://github.com/kubernetes/kubernetes/pull/59353#discussion_r173048411 cc @smarterclayton @deads2k @soltysh
This commit is contained in:
commit
a2f0ddcedb
@ -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
Block a user