Only insert outputversion as a preferred mapping type if no error occurs
Some types will be looked up based on their internal type, which is passed directly to RESTMapping(). RESTMapping() will search the entire version list if no external types are passed, but OutputVersionMapper was bypassing that because the default type was always present. Change OutputVersionMapper to collapse empty versions, and when no external type is specified, try with the preferred version and then try without.
This commit is contained in:
parent
a97635e643
commit
17f7dd8d6d
@ -63,7 +63,20 @@ 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 := append([]string{m.OutputVersion}, versions...)
|
||||
preferred := []string{m.OutputVersion}
|
||||
for _, version := range versions {
|
||||
if len(version) > 0 {
|
||||
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.
|
||||
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...)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user