List output with differing types should be more resilient
kubectl get can output a series of objects as a List in versioned form, but not all API objects are available in the same schema. Make the act of converting a []runtime.Object to api.List more robust and add a test to verify its behavior in Get. Makes it easier for client code to output unified objects.
This commit is contained in:
@@ -251,3 +251,42 @@ func (m *DefaultRESTMapper) AliasesForResource(alias string) ([]string, bool) {
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// MultiRESTMapper is a wrapper for multiple RESTMappers.
|
||||
type MultiRESTMapper []RESTMapper
|
||||
|
||||
// VersionAndKindForResource provides the Version and Kind mappings for the
|
||||
// REST resources. This implementation supports multiple REST schemas and return
|
||||
// the first match.
|
||||
func (m MultiRESTMapper) VersionAndKindForResource(resource string) (defaultVersion, kind string, err error) {
|
||||
for _, t := range m {
|
||||
defaultVersion, kind, err = t.VersionAndKindForResource(resource)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// RESTMapping provides the REST mapping for the resource based on the resource
|
||||
// kind and version. This implementation supports multiple REST schemas and
|
||||
// return the first match.
|
||||
func (m MultiRESTMapper) RESTMapping(kind string, versions ...string) (mapping *RESTMapping, err error) {
|
||||
for _, t := range m {
|
||||
mapping, err = t.RESTMapping(kind, versions...)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AliasesForResource finds the first alias response for the provided mappers.
|
||||
func (m MultiRESTMapper) AliasesForResource(alias string) (aliases []string, ok bool) {
|
||||
for _, t := range m {
|
||||
if aliases, ok = t.AliasesForResource(alias); ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
Reference in New Issue
Block a user