Skip to content

Commit

Permalink
refactor: rely on docker host to generate ephemeral port for LB
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Case <[email protected]>
  • Loading branch information
richardcase committed May 15, 2023
1 parent e79628d commit adac432
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 7 additions & 1 deletion test/infrastructure/container/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,15 @@ func configurePortMappings(portMappings []PortMapping, config *dockercontainer.C
HostIP: pm.ListenAddress,
HostPort: fmt.Sprintf("%d", pm.HostPort),
}
if pm.HostPort == 0 {
mapping.HostIP = ""
mapping.HostPort = ""
}
hostConfig.PortBindings[port] = append(hostConfig.PortBindings[port], mapping)
exposedPorts[port] = struct{}{}
exposedPorts[nat.Port(fmt.Sprintf("%d/tcp", pm.HostPort))] = struct{}{}
if pm.HostPort > 0 {
exposedPorts[nat.Port(fmt.Sprintf("%d/tcp", pm.HostPort))] = struct{}{}
}
}

config.ExposedPorts = exposedPorts
Expand Down
14 changes: 7 additions & 7 deletions test/infrastructure/docker/internal/docker/kind_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ func (m *Manager) CreateWorkerNode(ctx context.Context, name, image, clusterName
func (m *Manager) CreateExternalLoadBalancerNode(ctx context.Context, name, image, clusterName, listenAddress string, port int32, _ clusterv1.ClusterIPFamily) (*types.Node, error) {
// gets a random host port for control-plane load balancer
// gets a random host port for the API server
if port == 0 {
p, err := getPort()
if err != nil {
return nil, errors.Wrap(err, "failed to get port for API server")
}
port = p
}
// if port == 0 {
// p, err := getPort()
// if err != nil {
// return nil, errors.Wrap(err, "failed to get port for API server")
// }
// port = p
// }

// load balancer port mapping
portMappings := []v1alpha4.PortMapping{{
Expand Down

0 comments on commit adac432

Please sign in to comment.