Skip to content

Commit

Permalink
Add detailed error when lb fail to get IP
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Wang <[email protected]>
  • Loading branch information
w13915984028 authored and starbops committed Jul 10, 2024
1 parent 7fa600b commit 73c0e1f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/cloud-controller-manager/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,12 @@ func (l *LoadBalancerManager) constructLB(oldLB *lbv1.LoadBalancer, service *v1.
func (l *LoadBalancerManager) updatePrimaryServiceLoadBalancerIP(lbName string, service *v1.Service) error {
object, ip, err := waitForIP(func() (runtime.Object, string, error) {
lb, err := l.lbClient.Get(l.namespace, lbName, metav1.GetOptions{})
if err != nil || lb.Status.AllocatedAddress.IP == "" {
return nil, "", fmt.Errorf("could not get allocated IP address")
if err != nil {
return nil, "", fmt.Errorf("fail to get lb %w", err)
}
if lb.Status.AllocatedAddress.IP == "" {
// when Ready condition is false, the message has useful information
return nil, "", fmt.Errorf("ip is not allocated, mode: %s, message: %s", string(lb.Spec.IPAM), lbv1.LoadBalancerReady.GetMessage(lb))
}
return lb, lb.Status.AllocatedAddress.IP, nil
})
Expand Down Expand Up @@ -332,6 +336,7 @@ func (l *LoadBalancerManager) deleteLoadBalancer(clusterName string, service *v1
}

func waitForIP(callback func() (runtime.Object, string, error)) (runtime.Object, string, error) {
var err error
for i := 0; i < retryTimes; i++ {
object, ip, err := callback()
if err == nil {
Expand All @@ -340,7 +345,7 @@ func waitForIP(callback func() (runtime.Object, string, error)) (runtime.Object,
time.Sleep(retryInterval)
}

return nil, "", fmt.Errorf("timeout waiting for IP address")
return nil, "", fmt.Errorf("timeout waiting for IP address, last error:%w", err)
}

func (l *LoadBalancerManager) checkPortOverlap(primary, secondary *v1.Service) error {
Expand Down

0 comments on commit 73c0e1f

Please sign in to comment.