diff --git a/pkg/ccm/loadbalancer.go b/pkg/ccm/loadbalancer.go index 8605c88b..3f43ddd5 100644 --- a/pkg/ccm/loadbalancer.go +++ b/pkg/ccm/loadbalancer.go @@ -175,7 +175,18 @@ func (l *LoadBalancer) EnsureLoadBalancer( //nolint:gocyclo // not really comple } if lb.Status != nil && *lb.Status == loadbalancer.LOADBALANCERSTATUS_STATUS_ERROR { - return nil, fmt.Errorf("the load balancer is in an error state") + errorsList := lb.GetErrors() + + if len(errorsList) == 0 { + return nil, fmt.Errorf("the load balancer is in an error state") + } + + var errMessages []string + for _, lbErr := range errorsList { + errMessages = append(errMessages, fmt.Sprintf("[%s] %s", lbErr.GetType(), lbErr.GetDescription())) + } + + return nil, fmt.Errorf("the load balancer is in an error state: %s", strings.Join(errMessages, "; ")) } if lb.Status == nil || *lb.Status != loadbalancer.LOADBALANCERSTATUS_STATUS_READY { return nil, api.NewRetryError("waiting for load balancer to become ready. This error is normal while the load balancer starts.", retryDuration) diff --git a/pkg/ccm/loadbalancer_test.go b/pkg/ccm/loadbalancer_test.go index b741ddf5..32afd022 100644 --- a/pkg/ccm/loadbalancer_test.go +++ b/pkg/ccm/loadbalancer_test.go @@ -439,6 +439,51 @@ var _ = Describe("LoadBalancer", func() { // Expect UpdateLoadBalancer to have been called. // Expect DeleteCredentials to have been called. }) + + DescribeTable("return error when LoadBalancer is in error state", + func(lbErrors []loadbalancer.LoadBalancerError, wantedErrorString string) { + svc := minimalLoadBalancerService() + spec, _, err := lbSpecFromService(svc, []*corev1.Node{}, lbOpts, nil) + Expect(err).NotTo(HaveOccurred()) + myLb := &loadbalancer.LoadBalancer{ + Errors: lbErrors, + ExternalAddress: spec.ExternalAddress, + PlanId: spec.PlanId, + Listeners: spec.Listeners, + Name: spec.Name, + Networks: spec.Networks, + Options: spec.Options, + PrivateAddress: spec.PrivateAddress, + Status: new(loadbalancer.LOADBALANCERSTATUS_STATUS_ERROR), + TargetPools: spec.TargetPools, + Version: new("current-version"), + } + + mockClient.EXPECT().GetLoadBalancer(gomock.Any(), gomock.Any()).Return(myLb, nil) + + _, err = loadBalancer.EnsureLoadBalancer(context.Background(), clusterName, svc, []*corev1.Node{}) + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(wantedErrorString)) + + }, + Entry("should return an error without specific errors", + []loadbalancer.LoadBalancerError{}, + "the load balancer is in an error state", + ), + Entry("should return an error with specific errors", + []loadbalancer.LoadBalancerError{ + { + Type: new(loadbalancer.LOADBALANCERERRORTYPE_TYPE_UNSPECIFIED), + Description: new("more details"), + }, + { + Type: new(loadbalancer.LOADBALANCERERRORTYPE_TYPE_UNSPECIFIED), + Description: new("even more details"), + }, + }, + "the load balancer is in an error state: [TYPE_UNSPECIFIED] more details; [TYPE_UNSPECIFIED] even more details", + ), + ) }) Describe("EnsureLoadBalancerDeleted", func() {