From 9b8139a6b46dbb3fe10b73292ad985126bc145c7 Mon Sep 17 00:00:00 2001 From: Ashish Amarnath Date: Mon, 29 Mar 2021 15:19:26 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20[capd]=20Ensure=20Loadbalancer?= =?UTF-8?q?=20IP=20is=20not=20empty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ashish Amarnath --- test/infrastructure/docker/docker/loadbalancer.go | 7 +++++++ 1 file changed, 7 insertions(+) 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 }