fix outputversion restmapper

This commit is contained in:
deads2k 2015-11-20 16:19:26 -05:00
parent ed95a6d77f
commit 9e9b9f2da3
2 changed files with 18 additions and 16 deletions

View File

@ -189,9 +189,21 @@ func (m *DefaultRESTMapper) GroupForResource(resource string) (string, error) {
// them with group/version tuples.
// TODO this should probably become RESTMapping(GroupKind, versions ...string)
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
var groupVersion *unversioned.GroupVersion
hadVersion := false
for _, v := range versions {
if len(v) == 0 {
continue
@ -202,7 +214,6 @@ func (m *DefaultRESTMapper) RESTMapping(kind string, versions ...string) (*RESTM
}
currGVK := currGroupVersion.WithKind(kind)
hadVersion = true
if _, ok := m.kindToPluralResource[currGVK]; ok {
groupVersion = &currGroupVersion
break

View File

@ -51,21 +51,12 @@ type OutputVersionMapper struct {
// 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) {
preferred := []string{m.OutputVersion}
for _, version := range versions {
if len(version) > 0 {
preferred = append(preferred, version)
}
mapping, err := m.RESTMapper.RESTMapping(kind, m.OutputVersion)
if err == nil {
return mapping, nil
}
// if the caller wants to use the default version list, try with the preferred version, and on
// error, use the default behavior.
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...)
return m.RESTMapper.RESTMapping(kind, versions...)
}
// ShortcutExpander is a RESTMapper that can be used for Kubernetes