Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pkg/ccm/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
45 changes: 45 additions & 0 deletions pkg/ccm/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 keep DisableTargetSecurityGroupAssignment as true when it is initially true",
[]loadbalancer.LoadBalancerError{},
"the load balancer is in an error state",
),
Entry("should not set DisableTargetSecurityGroupAssignment to true when it is initially false",
[]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() {
Expand Down