Skip to content

Commit 0d80684

Browse files
committed
Add more details for load balancers in error state
1 parent ccce173 commit 0d80684

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

pkg/ccm/loadbalancer.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,18 @@ func (l *LoadBalancer) EnsureLoadBalancer( //nolint:gocyclo // not really comple
175175
}
176176

177177
if lb.Status != nil && *lb.Status == loadbalancer.LOADBALANCERSTATUS_STATUS_ERROR {
178-
return nil, fmt.Errorf("the load balancer is in an error state")
178+
errorsList := lb.GetErrors()
179+
180+
if len(errorsList) == 0 {
181+
return nil, fmt.Errorf("the load balancer is in an error state")
182+
}
183+
184+
var errMessages []string
185+
for _, lbErr := range errorsList {
186+
errMessages = append(errMessages, fmt.Sprintf("[%s] %s", lbErr.GetType(), lbErr.GetDescription()))
187+
}
188+
189+
return nil, fmt.Errorf("the load balancer is in an error state: %s", strings.Join(errMessages, "; "))
179190
}
180191
if lb.Status == nil || *lb.Status != loadbalancer.LOADBALANCERSTATUS_STATUS_READY {
181192
return nil, api.NewRetryError("waiting for load balancer to become ready. This error is normal while the load balancer starts.", retryDuration)

pkg/ccm/loadbalancer_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,51 @@ var _ = Describe("LoadBalancer", func() {
439439
// Expect UpdateLoadBalancer to have been called.
440440
// Expect DeleteCredentials to have been called.
441441
})
442+
443+
DescribeTable("return error when LoadBalancer is in error state",
444+
func(lbErrors []loadbalancer.LoadBalancerError, wantedErrorString string) {
445+
svc := minimalLoadBalancerService()
446+
spec, _, err := lbSpecFromService(svc, []*corev1.Node{}, lbOpts, nil)
447+
Expect(err).NotTo(HaveOccurred())
448+
myLb := &loadbalancer.LoadBalancer{
449+
Errors: lbErrors,
450+
ExternalAddress: spec.ExternalAddress,
451+
PlanId: spec.PlanId,
452+
Listeners: spec.Listeners,
453+
Name: spec.Name,
454+
Networks: spec.Networks,
455+
Options: spec.Options,
456+
PrivateAddress: spec.PrivateAddress,
457+
Status: new(loadbalancer.LOADBALANCERSTATUS_STATUS_ERROR),
458+
TargetPools: spec.TargetPools,
459+
Version: new("current-version"),
460+
}
461+
462+
mockClient.EXPECT().GetLoadBalancer(gomock.Any(), gomock.Any()).Return(myLb, nil)
463+
464+
_, err = loadBalancer.EnsureLoadBalancer(context.Background(), clusterName, svc, []*corev1.Node{})
465+
Expect(err).To(HaveOccurred())
466+
Expect(err).To(MatchError(wantedErrorString))
467+
468+
},
469+
Entry("should keep DisableTargetSecurityGroupAssignment as true when it is initially true",
470+
[]loadbalancer.LoadBalancerError{},
471+
"the load balancer is in an error state",
472+
),
473+
Entry("should not set DisableTargetSecurityGroupAssignment to true when it is initially false",
474+
[]loadbalancer.LoadBalancerError{
475+
{
476+
Type: new(loadbalancer.LOADBALANCERERRORTYPE_TYPE_UNSPECIFIED),
477+
Description: new("more details"),
478+
},
479+
{
480+
Type: new(loadbalancer.LOADBALANCERERRORTYPE_TYPE_UNSPECIFIED),
481+
Description: new("even more details"),
482+
},
483+
},
484+
"the load balancer is in an error state: [TYPE_UNSPECIFIED] more details; [TYPE_UNSPECIFIED] even more details",
485+
),
486+
)
442487
})
443488

444489
Describe("EnsureLoadBalancerDeleted", func() {

0 commit comments

Comments
 (0)