fix port collisions due to default exposed port on master nodes

This commit is contained in:
iwilltry42 2019-11-22 18:46:52 +01:00
parent ff98343420
commit 189e430f90
2 changed files with 13 additions and 11 deletions

View File

@ -290,6 +290,9 @@ func parseCreateClusterCmd(cmd *cobra.Command, args []string) (runtimes.Runtime,
MasterOpts: k3d.MasterOpts{}, MasterOpts: k3d.MasterOpts{},
} }
// TODO: by default, we don't expose an PI port, even if we only have a single master: should we change that?
// -> if we want to change that, simply add the exposeAPI struct here
// first master node will be init node if we have more than one master specified but no external datastore // first master node will be init node if we have more than one master specified but no external datastore
if i == 0 && masterCount > 1 && datastoreEndpoint == "" { if i == 0 && masterCount > 1 && datastoreEndpoint == "" {
node.MasterOpts.IsInit = true node.MasterOpts.IsInit = true

View File

@ -112,27 +112,26 @@ func patchWorkerSpec(node *k3d.Node) error {
// patchMasterSpec adds worker node specific settings to a node // patchMasterSpec adds worker node specific settings to a node
func patchMasterSpec(node *k3d.Node) error { func patchMasterSpec(node *k3d.Node) error {
// command / arguments
node.Args = append([]string{"server"}, node.Args...) node.Args = append([]string{"server"}, node.Args...)
// role label
node.Labels["k3d.role"] = string(k3d.MasterRole) // TODO: maybe put those in a global var DefaultMasterNodeSpec? node.Labels["k3d.role"] = string(k3d.MasterRole) // TODO: maybe put those in a global var DefaultMasterNodeSpec?
hostIP := "0.0.0.0" // TODO: from defaults // extra settings to expose the API port (if wanted)
apiPort := "6443" // TODO: from defaults
if node.MasterOpts.ExposeAPI.Port != "" { if node.MasterOpts.ExposeAPI.Port != "" {
apiPort = node.MasterOpts.ExposeAPI.Port if node.MasterOpts.ExposeAPI.Host == "" {
node.Labels["k3d.master.api.port"] = node.MasterOpts.ExposeAPI.Port node.MasterOpts.ExposeAPI.Host = "0.0.0.0"
} }
if node.MasterOpts.ExposeAPI.Host != "" {
hostIP = node.MasterOpts.ExposeAPI.HostIP
node.Labels["k3d.master.api.hostIP"] = node.MasterOpts.ExposeAPI.HostIP // TODO: maybe get docker machine IP here node.Labels["k3d.master.api.hostIP"] = node.MasterOpts.ExposeAPI.HostIP // TODO: maybe get docker machine IP here
node.Labels["k3d.master.api.host"] = node.MasterOpts.ExposeAPI.Host node.Labels["k3d.master.api.host"] = node.MasterOpts.ExposeAPI.Host
node.Args = append(node.Args, "--tls-san", node.MasterOpts.ExposeAPI.Host) // add TLS SAN for non default host name node.Args = append(node.Args, "--tls-san", node.MasterOpts.ExposeAPI.Host) // add TLS SAN for non default host name
node.Labels["k3d.master.api.port"] = node.MasterOpts.ExposeAPI.Port
node.Ports = append(node.Ports, fmt.Sprintf("%s:%s:6443/tcp", node.MasterOpts.ExposeAPI.Host, node.MasterOpts.ExposeAPI.Port)) // TODO: get '6443' from defaultport variable
} }
node.Ports = append(node.Ports, fmt.Sprintf("%s:%s:6443/tcp", hostIP, apiPort)) // TODO: get '6443' from defaultport variable
return nil return nil
} }