Skip to content

Commit 8233cb6

Browse files
committed
allow error and partial result for legacy discovery
1 parent 9e98436 commit 8233cb6

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

pkg/oc/cli/util/clientcmd/legacy_discovery.go

+23-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"k8s.io/apimachinery/pkg/api/errors"
77
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
"k8s.io/apimachinery/pkg/runtime/schema"
89
"k8s.io/client-go/discovery"
910
restclient "k8s.io/client-go/rest"
1011
)
@@ -16,6 +17,7 @@ type legacyDiscoveryClient struct {
1617
}
1718

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

4345
parentList.APIResources = append(parentList.APIResources, originResources.APIResources...)
4446
return parentList, nil
4547
}
4648

4749
// ServerResources returns the supported resources for all groups and versions.
50+
// This can return an error *and* a partial result
4851
func (d *legacyDiscoveryClient) ServerResources() ([]*metav1.APIResourceList, error) {
4952
apiGroups, err := d.ServerGroups()
5053
if err != nil {
5154
return nil, err
5255
}
53-
groupVersions := metav1.ExtractGroupVersions(apiGroups)
56+
5457
result := []*metav1.APIResourceList{}
55-
for _, groupVersion := range groupVersions {
56-
resources, err := d.ServerResourcesForGroupVersion(groupVersion)
57-
if err != nil {
58-
return nil, err
58+
failedGroups := make(map[schema.GroupVersion]error)
59+
60+
for _, apiGroup := range apiGroups.Groups {
61+
for _, version := range apiGroup.Versions {
62+
gv := schema.GroupVersion{Group: apiGroup.Name, Version: version.Version}
63+
resources, err := d.ServerResourcesForGroupVersion(version.GroupVersion)
64+
if err != nil {
65+
failedGroups[gv] = err
66+
continue
67+
}
68+
69+
result = append(result, resources)
5970
}
60-
result = append(result, resources)
6171
}
62-
return result, nil
72+
73+
if len(failedGroups) == 0 {
74+
return result, nil
75+
}
76+
77+
return result, &discovery.ErrGroupDiscoveryFailed{Groups: failedGroups}
6378
}
6479

6580
// newLegacyDiscoveryClient creates a new DiscoveryClient for the given RESTClient.

0 commit comments

Comments
 (0)