Merge pull request #55162 from deads2k/cli-06-tolerate-error

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

tolerate discovery errors in the restmapper

Found this while investigating a related problem.  The restmapper can use the information it has found.  It doesn't have to discard all of it.
pull/6/head
Kubernetes Submit Queue 2017-11-09 08:36:44 -08:00 committed by GitHub
commit f4d470c75c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 14 deletions

View File

@ -79,22 +79,24 @@ func (e shortcutExpander) RESTMappings(gk schema.GroupKind, versions ...string)
func (e shortcutExpander) getShortcutMappings() ([]kubectl.ResourceShortcuts, error) {
res := []kubectl.ResourceShortcuts{}
// get server resources
// This can return an error *and* the results it was able to find. We don't need to fail on the error.
apiResList, err := e.discoveryClient.ServerResources()
if err == nil {
for _, apiResources := range apiResList {
for _, apiRes := range apiResources.APIResources {
for _, shortName := range apiRes.ShortNames {
gv, err := schema.ParseGroupVersion(apiResources.GroupVersion)
if err != nil {
glog.V(1).Infof("Unable to parse groupversion = %s due to = %s", apiResources.GroupVersion, err.Error())
continue
}
rs := kubectl.ResourceShortcuts{
ShortForm: schema.GroupResource{Group: gv.Group, Resource: shortName},
LongForm: schema.GroupResource{Group: gv.Group, Resource: apiRes.Name},
}
res = append(res, rs)
if err != nil {
glog.V(1).Infof("Error loading discovery information: %v", err)
}
for _, apiResources := range apiResList {
for _, apiRes := range apiResources.APIResources {
for _, shortName := range apiRes.ShortNames {
gv, err := schema.ParseGroupVersion(apiResources.GroupVersion)
if err != nil {
glog.V(1).Infof("Unable to parse groupversion = %s due to = %s", apiResources.GroupVersion, err.Error())
continue
}
rs := kubectl.ResourceShortcuts{
ShortForm: schema.GroupResource{Group: gv.Group, Resource: shortName},
LongForm: schema.GroupResource{Group: gv.Group, Resource: apiRes.Name},
}
res = append(res, rs)
}
}
}