Skip to content

Commit

Permalink
🌱 [capd] Ensure Loadbalancer IP is not empty
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Amarnath <[email protected]>
  • Loading branch information
ashish-amarnath committed Mar 31, 2021
1 parent fec46e4 commit 5c068db
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/infrastructure/docker/docker/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 label 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)),
Expand Down Expand Up @@ -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("load balancer IP cannot be empty: container %s does not have an associated IP address", s.containerName())
}
return lbip4, nil
}

Expand Down

0 comments on commit 5c068db

Please sign in to comment.