Fix for KubeAPI Port assignment when using config files (#490, @dtomasi)
This commit is contained in:
parent
df9859eae6
commit
dbfaeb4af3
@ -24,6 +24,7 @@ package cluster
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
@ -350,25 +351,41 @@ func applyCLIOverrides(cfg conf.SimpleConfig) (conf.SimpleConfig, error) {
|
||||
|
||||
// -> API-PORT
|
||||
// parse the port mapping
|
||||
var exposeAPI *k3d.ExposureOpts
|
||||
var (
|
||||
err error
|
||||
exposeAPI *k3d.ExposureOpts
|
||||
)
|
||||
|
||||
// Apply config file values as defaults
|
||||
exposeAPI = &k3d.ExposureOpts{
|
||||
PortMapping: nat.PortMapping{
|
||||
Binding: nat.PortBinding{
|
||||
HostIP: cfg.ExposeAPI.HostIP,
|
||||
HostPort: cfg.ExposeAPI.HostPort,
|
||||
},
|
||||
},
|
||||
Host: cfg.ExposeAPI.Host,
|
||||
}
|
||||
|
||||
// Overwrite if cli arg is set
|
||||
if ppViper.IsSet("cli.api-port") {
|
||||
if cfg.ExposeAPI.HostPort != "" {
|
||||
log.Debugf("Overriding pre-defined kubeAPI Exposure Spec %+v with CLI argument %s", cfg.ExposeAPI, ppViper.GetString("cli.api-port"))
|
||||
}
|
||||
var err error
|
||||
exposeAPI, err = cliutil.ParsePortExposureSpec(ppViper.GetString("cli.api-port"), k3d.DefaultAPIPort)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
}
|
||||
|
||||
if exposeAPI == nil {
|
||||
var err error
|
||||
// Set to random port if port is empty string
|
||||
if len(exposeAPI.Binding.HostPort) == 0 {
|
||||
exposeAPI, err = cliutil.ParsePortExposureSpec("random", k3d.DefaultAPIPort)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
}
|
||||
|
||||
cfg.ExposeAPI = conf.SimpleExposureOpts{
|
||||
Host: exposeAPI.Host,
|
||||
HostIP: exposeAPI.Binding.HostIP,
|
||||
|
Loading…
Reference in New Issue
Block a user