5
5
6
6
"k8s.io/apimachinery/pkg/api/errors"
7
7
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8
+ "k8s.io/apimachinery/pkg/runtime/schema"
8
9
"k8s.io/client-go/discovery"
9
10
restclient "k8s.io/client-go/rest"
10
11
)
@@ -16,6 +17,7 @@ type legacyDiscoveryClient struct {
16
17
}
17
18
18
19
// ServerResourcesForGroupVersion returns the supported resources for a group and version.
20
+ // This can return an error *and* a partial result
19
21
func (d * legacyDiscoveryClient ) ServerResourcesForGroupVersion (groupVersion string ) (resources * metav1.APIResourceList , err error ) {
20
22
parentList , err := d .DiscoveryClient .ServerResourcesForGroupVersion (groupVersion )
21
23
if err != nil {
@@ -37,29 +39,42 @@ func (d *legacyDiscoveryClient) ServerResourcesForGroupVersion(groupVersion stri
37
39
if groupVersion == "v1" && (errors .IsNotFound (err ) || errors .IsForbidden (err )) {
38
40
return parentList , nil
39
41
}
40
- return nil , err
42
+ return parentList , err
41
43
}
42
44
43
45
parentList .APIResources = append (parentList .APIResources , originResources .APIResources ... )
44
46
return parentList , nil
45
47
}
46
48
47
49
// ServerResources returns the supported resources for all groups and versions.
50
+ // This can return an error *and* a partial result
48
51
func (d * legacyDiscoveryClient ) ServerResources () ([]* metav1.APIResourceList , error ) {
49
52
apiGroups , err := d .ServerGroups ()
50
53
if err != nil {
51
54
return nil , err
52
55
}
53
- groupVersions := metav1 . ExtractGroupVersions ( apiGroups )
56
+
54
57
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 )
59
70
}
60
- result = append (result , resources )
61
71
}
62
- return result , nil
72
+
73
+ if len (failedGroups ) == 0 {
74
+ return result , nil
75
+ }
76
+
77
+ return result , & discovery.ErrGroupDiscoveryFailed {Groups : failedGroups }
63
78
}
64
79
65
80
// newLegacyDiscoveryClient creates a new DiscoveryClient for the given RESTClient.
0 commit comments