mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
fix outputversion restmapper
This commit is contained in:
parent
ed95a6d77f
commit
9e9b9f2da3
@ -189,9 +189,21 @@ func (m *DefaultRESTMapper) GroupForResource(resource string) (string, error) {
|
|||||||
// them with group/version tuples.
|
// them with group/version tuples.
|
||||||
// TODO this should probably become RESTMapping(GroupKind, versions ...string)
|
// TODO this should probably become RESTMapping(GroupKind, versions ...string)
|
||||||
func (m *DefaultRESTMapper) RESTMapping(kind string, versions ...string) (*RESTMapping, error) {
|
func (m *DefaultRESTMapper) RESTMapping(kind string, versions ...string) (*RESTMapping, error) {
|
||||||
|
// TODO, this looks really strange, but once this API is update, the version detection becomes clean again
|
||||||
|
// because you won't be able to request cross-group kinds
|
||||||
|
hadVersion := false
|
||||||
|
for _, gvString := range versions {
|
||||||
|
currGroupVersion, err := unversioned.ParseGroupVersion(gvString)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(currGroupVersion.Version) != 0 {
|
||||||
|
hadVersion = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Pick an appropriate version
|
// Pick an appropriate version
|
||||||
var groupVersion *unversioned.GroupVersion
|
var groupVersion *unversioned.GroupVersion
|
||||||
hadVersion := false
|
|
||||||
for _, v := range versions {
|
for _, v := range versions {
|
||||||
if len(v) == 0 {
|
if len(v) == 0 {
|
||||||
continue
|
continue
|
||||||
@ -202,7 +214,6 @@ func (m *DefaultRESTMapper) RESTMapping(kind string, versions ...string) (*RESTM
|
|||||||
}
|
}
|
||||||
|
|
||||||
currGVK := currGroupVersion.WithKind(kind)
|
currGVK := currGroupVersion.WithKind(kind)
|
||||||
hadVersion = true
|
|
||||||
if _, ok := m.kindToPluralResource[currGVK]; ok {
|
if _, ok := m.kindToPluralResource[currGVK]; ok {
|
||||||
groupVersion = &currGroupVersion
|
groupVersion = &currGroupVersion
|
||||||
break
|
break
|
||||||
|
@ -51,21 +51,12 @@ type OutputVersionMapper struct {
|
|||||||
|
|
||||||
// RESTMapping implements meta.RESTMapper by prepending the output version to the preferred version list.
|
// RESTMapping implements meta.RESTMapper by prepending the output version to the preferred version list.
|
||||||
func (m OutputVersionMapper) RESTMapping(kind string, versions ...string) (*meta.RESTMapping, error) {
|
func (m OutputVersionMapper) RESTMapping(kind string, versions ...string) (*meta.RESTMapping, error) {
|
||||||
preferred := []string{m.OutputVersion}
|
mapping, err := m.RESTMapper.RESTMapping(kind, m.OutputVersion)
|
||||||
for _, version := range versions {
|
if err == nil {
|
||||||
if len(version) > 0 {
|
return mapping, nil
|
||||||
preferred = append(preferred, version)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// if the caller wants to use the default version list, try with the preferred version, and on
|
|
||||||
// error, use the default behavior.
|
return m.RESTMapper.RESTMapping(kind, versions...)
|
||||||
if len(preferred) == 1 {
|
|
||||||
if m, err := m.RESTMapper.RESTMapping(kind, preferred...); err == nil {
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
preferred = nil
|
|
||||||
}
|
|
||||||
return m.RESTMapper.RESTMapping(kind, preferred...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShortcutExpander is a RESTMapper that can be used for Kubernetes
|
// ShortcutExpander is a RESTMapper that can be used for Kubernetes
|
||||||
|
Loading…
Reference in New Issue
Block a user