Skip to content

Commit

Permalink
Only insert outputversion as a preferred mapping type if no error occurs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
smarterclayton committed Mar 4, 2015
1 parent a97635e commit 17f7dd8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}

Expand Down

0 comments on commit 17f7dd8

Please sign in to comment.