From a15013ec8b1b3c52464a01f06b97cd27e3a5bb34 Mon Sep 17 00:00:00 2001 From: Timo Reimann Date: Sun, 23 Oct 2022 10:27:26 +0200 Subject: [PATCH] Document RetryError properly --- staging/src/k8s.io/cloud-provider/cloud.go | 12 +++++++++--- .../cloud-provider/controllers/service/controller.go | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/staging/src/k8s.io/cloud-provider/cloud.go b/staging/src/k8s.io/cloud-provider/cloud.go index 7e7bf9dfab8..c9a04085f48 100644 --- a/staging/src/k8s.io/cloud-provider/cloud.go +++ b/staging/src/k8s.io/cloud-provider/cloud.go @@ -131,11 +131,11 @@ func GetInstanceProviderID(ctx context.Context, cloud Interface, nodeName types. // irrespective of the ImplementedElsewhere error. Additional finalizers for // LB services must be managed in the alternate implementation. type LoadBalancer interface { - // TODO: Break this up into different interfaces (LB, etc) when we have more than one type of service // GetLoadBalancer returns whether the specified load balancer exists, and // if so, what its status is. // Implementations must treat the *v1.Service parameter as read-only and not modify it. - // Parameter 'clusterName' is the name of the cluster as presented to kube-controller-manager + // Parameter 'clusterName' is the name of the cluster as presented to kube-controller-manager. + // TODO: Break this up into different interfaces (LB, etc) when we have more than one type of service GetLoadBalancer(ctx context.Context, clusterName string, service *v1.Service) (status *v1.LoadBalancerStatus, exists bool, err error) // GetLoadBalancerName returns the name of the load balancer. Implementations must treat the // *v1.Service parameter as read-only and not modify it. @@ -143,7 +143,13 @@ type LoadBalancer interface { // EnsureLoadBalancer creates a new load balancer 'name', or updates the existing one. Returns the status of the balancer // Implementations must treat the *v1.Service and *v1.Node // parameters as read-only and not modify them. - // Parameter 'clusterName' is the name of the cluster as presented to kube-controller-manager + // Parameter 'clusterName' is the name of the cluster as presented to kube-controller-manager. + // + // Implementations may return a (possibly wrapped) api.RetryError to enforce + // backing off at a fixed duration. This can be used for cases like when the + // load balancer is not ready yet (e.g., it is still being provisioned) and + // polling at a fixed rate is preferred over backing off exponentially in + // order to minimize latency. EnsureLoadBalancer(ctx context.Context, clusterName string, service *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error) // UpdateLoadBalancer updates hosts under the specified load balancer. // Implementations must treat the *v1.Service and *v1.Node diff --git a/staging/src/k8s.io/cloud-provider/controllers/service/controller.go b/staging/src/k8s.io/cloud-provider/controllers/service/controller.go index ad02b3d72e4..179b2d4e8f0 100644 --- a/staging/src/k8s.io/cloud-provider/controllers/service/controller.go +++ b/staging/src/k8s.io/cloud-provider/controllers/service/controller.go @@ -410,6 +410,7 @@ func (c *Controller) syncLoadBalancerIfNeeded(ctx context.Context, service *v1.S klog.V(4).Infof("LoadBalancer for service %s implemented by a different controller %s, Ignoring error", key, c.cloud.ProviderName()) return op, nil } + // Use %w deliberately so that a returned RetryError can be handled. return op, fmt.Errorf("failed to ensure load balancer: %w", err) } if newStatus == nil {