diff --git a/test/infrastructure/docker/docker/loadbalancer.go b/test/infrastructure/docker/docker/loadbalancer.go index c65d0e1fa1e4..79ff172d013a 100644 --- a/test/infrastructure/docker/docker/loadbalancer.go +++ b/test/infrastructure/docker/docker/loadbalancer.go @@ -45,6 +45,9 @@ func NewLoadBalancer(name string) (*LoadBalancer, error) { return nil, errors.New("name is required when creating a docker.LoadBalancer") } + // look for the container that is hosting the loadbalancer for the cluster. + // filter based on the lablel and the roles regardless of whether or not it is running. + // if non-running container is chosen, then it will not have an IP address associated with it. container, err := getContainer( withLabel(clusterLabel(name)), withLabel(roleLabel(constants.ExternalLoadBalancerNodeRoleValue)), @@ -137,6 +140,10 @@ func (s *LoadBalancer) IP(ctx context.Context) (string, error) { if err != nil { return "", errors.WithStack(err) } + if lbip4 == "" { + // if there is a load balancer container with the same name exists but is stopped, it may not have IP address associated with it. + return "", errors.Errorf("LoadBalancer IP cannot be empty: container %s does not have an associated IP address", s.containerName()) + } return lbip4, nil }