fix: allow allow port-ranges on the loadbalancer
This commit is contained in:
parent
7b07b8b6dc
commit
d3c5cfb766
@ -285,7 +285,25 @@ func ClusterCreate(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clus
|
||||
ports := k3d.DefaultAPIPort
|
||||
for _, portString := range cluster.ServerLoadBalancer.Ports {
|
||||
split := strings.Split(portString, ":")
|
||||
ports += "," + split[len(split)-1]
|
||||
port := split[len(split)-1]
|
||||
if strings.Contains(port, "-") {
|
||||
split := strings.Split(port, "-")
|
||||
start, err := strconv.Atoi(split[0])
|
||||
if err != nil {
|
||||
log.Errorln("Failed to parse port mapping for loadbalancer '%s'", port)
|
||||
return err
|
||||
}
|
||||
end, err := strconv.Atoi(split[1])
|
||||
if err != nil {
|
||||
log.Errorln("Failed to parse port mapping for loadbalancer '%s'", port)
|
||||
return err
|
||||
}
|
||||
for i := start; i <= end; i++ {
|
||||
ports += "," + strconv.Itoa(i)
|
||||
}
|
||||
} else {
|
||||
ports += "," + port
|
||||
}
|
||||
}
|
||||
|
||||
// Create LB as a modified node with loadbalancerRole
|
||||
@ -296,6 +314,7 @@ func ClusterCreate(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clus
|
||||
Env: []string{
|
||||
fmt.Sprintf("SERVERS=%s", servers),
|
||||
fmt.Sprintf("PORTS=%s", ports),
|
||||
fmt.Sprintf("WORKER_PROCESSES=%d", len(strings.Split(ports, ","))),
|
||||
},
|
||||
Role: k3d.LoadBalancerRole,
|
||||
Labels: k3d.DefaultObjectLabels, // TODO: createLoadBalancer: add more expressive labels
|
||||
|
@ -1,13 +1,12 @@
|
||||
{{- $servers := split (getenv "SERVERS") "," -}}
|
||||
{{- $ports := split (getenv "PORTS") "," -}}
|
||||
|
||||
error_log stderr notice;
|
||||
|
||||
worker_processes auto;
|
||||
events {
|
||||
multi_accept on;
|
||||
use epoll;
|
||||
worker_connections 1024;
|
||||
worker_connections {{ add 1024 (len $ports) }};
|
||||
}
|
||||
|
||||
stream {
|
||||
|
Loading…
Reference in New Issue
Block a user