Skip to content

Commit

Permalink
allow error and partial result for legacy discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Jan 15, 2018
1 parent 9e98436 commit 8233cb6
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions pkg/oc/cli/util/clientcmd/legacy_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
restclient "k8s.io/client-go/rest"
)
Expand All @@ -16,6 +17,7 @@ type legacyDiscoveryClient struct {
}

// ServerResourcesForGroupVersion returns the supported resources for a group and version.
// This can return an error *and* a partial result
func (d *legacyDiscoveryClient) ServerResourcesForGroupVersion(groupVersion string) (resources *metav1.APIResourceList, err error) {
parentList, err := d.DiscoveryClient.ServerResourcesForGroupVersion(groupVersion)
if err != nil {
Expand All @@ -37,29 +39,42 @@ func (d *legacyDiscoveryClient) ServerResourcesForGroupVersion(groupVersion stri
if groupVersion == "v1" && (errors.IsNotFound(err) || errors.IsForbidden(err)) {
return parentList, nil
}
return nil, err
return parentList, err
}

parentList.APIResources = append(parentList.APIResources, originResources.APIResources...)
return parentList, nil
}

// ServerResources returns the supported resources for all groups and versions.
// This can return an error *and* a partial result
func (d *legacyDiscoveryClient) ServerResources() ([]*metav1.APIResourceList, error) {
apiGroups, err := d.ServerGroups()
if err != nil {
return nil, err
}
groupVersions := metav1.ExtractGroupVersions(apiGroups)

result := []*metav1.APIResourceList{}
for _, groupVersion := range groupVersions {
resources, err := d.ServerResourcesForGroupVersion(groupVersion)
if err != nil {
return nil, err
failedGroups := make(map[schema.GroupVersion]error)

for _, apiGroup := range apiGroups.Groups {
for _, version := range apiGroup.Versions {
gv := schema.GroupVersion{Group: apiGroup.Name, Version: version.Version}
resources, err := d.ServerResourcesForGroupVersion(version.GroupVersion)
if err != nil {
failedGroups[gv] = err
continue
}

result = append(result, resources)
}
result = append(result, resources)
}
return result, nil

if len(failedGroups) == 0 {
return result, nil
}

return result, &discovery.ErrGroupDiscoveryFailed{Groups: failedGroups}
}

// newLegacyDiscoveryClient creates a new DiscoveryClient for the given RESTClient.
Expand Down

0 comments on commit 8233cb6

Please sign in to comment.