mirror of
https://github.com/kubernetes/client-go.git
synced 2025-08-10 11:41:47 +00:00
make it possible to allow discovery errors for controllers
Kubernetes-commit: b7286f3188e997c98c89e1a8755b58ae69fbd4b0
This commit is contained in:
parent
54dc2e8920
commit
203206d11a
@ -187,7 +187,7 @@ func (d *DiscoveryClient) ServerResourcesForGroupVersion(groupVersion string) (r
|
|||||||
}
|
}
|
||||||
|
|
||||||
// serverResources returns the supported resources for all groups and versions.
|
// serverResources returns the supported resources for all groups and versions.
|
||||||
func (d *DiscoveryClient) serverResources(failEarly bool) ([]*metav1.APIResourceList, error) {
|
func (d *DiscoveryClient) serverResources() ([]*metav1.APIResourceList, error) {
|
||||||
apiGroups, err := d.ServerGroups()
|
apiGroups, err := d.ServerGroups()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -203,9 +203,6 @@ func (d *DiscoveryClient) serverResources(failEarly bool) ([]*metav1.APIResource
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: maybe restrict this to NotFound errors
|
// TODO: maybe restrict this to NotFound errors
|
||||||
failedGroups[gv] = err
|
failedGroups[gv] = err
|
||||||
if failEarly {
|
|
||||||
return nil, &ErrGroupDiscoveryFailed{Groups: failedGroups}
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,7 +246,7 @@ func IsGroupDiscoveryFailedError(err error) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// serverPreferredResources returns the supported resources with the version preferred by the server.
|
// serverPreferredResources returns the supported resources with the version preferred by the server.
|
||||||
func (d *DiscoveryClient) serverPreferredResources(failEarly bool) ([]*metav1.APIResourceList, error) {
|
func (d *DiscoveryClient) serverPreferredResources() ([]*metav1.APIResourceList, error) {
|
||||||
serverGroupList, err := d.ServerGroups()
|
serverGroupList, err := d.ServerGroups()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -269,9 +266,6 @@ func (d *DiscoveryClient) serverPreferredResources(failEarly bool) ([]*metav1.AP
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: maybe restrict this to NotFound errors
|
// TODO: maybe restrict this to NotFound errors
|
||||||
failedGroups[groupVersion] = err
|
failedGroups[groupVersion] = err
|
||||||
if failEarly {
|
|
||||||
return nil, &ErrGroupDiscoveryFailed{Groups: failedGroups}
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,9 +310,7 @@ func (d *DiscoveryClient) serverPreferredResources(failEarly bool) ([]*metav1.AP
|
|||||||
// ServerPreferredResources returns the supported resources with the version preferred by the
|
// ServerPreferredResources returns the supported resources with the version preferred by the
|
||||||
// server.
|
// server.
|
||||||
func (d *DiscoveryClient) ServerPreferredResources() ([]*metav1.APIResourceList, error) {
|
func (d *DiscoveryClient) ServerPreferredResources() ([]*metav1.APIResourceList, error) {
|
||||||
return withRetries(defaultRetries, func(retryEarly bool) ([]*metav1.APIResourceList, error) {
|
return withRetries(defaultRetries, d.serverPreferredResources)
|
||||||
return d.serverPreferredResources(retryEarly)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerPreferredNamespacedResources returns the supported namespaced resources with the
|
// ServerPreferredNamespacedResources returns the supported namespaced resources with the
|
||||||
@ -394,12 +386,11 @@ func (d *DiscoveryClient) OpenAPISchema() (*openapi_v2.Document, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// withRetries retries the given recovery function in case the groups supported by the server change after ServerGroup() returns.
|
// withRetries retries the given recovery function in case the groups supported by the server change after ServerGroup() returns.
|
||||||
func withRetries(maxRetries int, f func(failEarly bool) ([]*metav1.APIResourceList, error)) ([]*metav1.APIResourceList, error) {
|
func withRetries(maxRetries int, f func() ([]*metav1.APIResourceList, error)) ([]*metav1.APIResourceList, error) {
|
||||||
var result []*metav1.APIResourceList
|
var result []*metav1.APIResourceList
|
||||||
var err error
|
var err error
|
||||||
for i := 0; i < maxRetries; i++ {
|
for i := 0; i < maxRetries; i++ {
|
||||||
failEarly := i < maxRetries-1
|
result, err = f()
|
||||||
result, err = f(failEarly)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user