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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/docker/go-connections/nat"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@ -350,25 +351,41 @@ func applyCLIOverrides(cfg conf.SimpleConfig) (conf.SimpleConfig, error) {
|
|||||||
|
|
||||||
// -> API-PORT
|
// -> API-PORT
|
||||||
// parse the port mapping
|
// 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 ppViper.IsSet("cli.api-port") {
|
||||||
if cfg.ExposeAPI.HostPort != "" {
|
if cfg.ExposeAPI.HostPort != "" {
|
||||||
log.Debugf("Overriding pre-defined kubeAPI Exposure Spec %+v with CLI argument %s", cfg.ExposeAPI, ppViper.GetString("cli.api-port"))
|
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)
|
exposeAPI, err = cliutil.ParsePortExposureSpec(ppViper.GetString("cli.api-port"), k3d.DefaultAPIPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if exposeAPI == nil {
|
// Set to random port if port is empty string
|
||||||
var err error
|
if len(exposeAPI.Binding.HostPort) == 0 {
|
||||||
exposeAPI, err = cliutil.ParsePortExposureSpec("random", k3d.DefaultAPIPort)
|
exposeAPI, err = cliutil.ParsePortExposureSpec("random", k3d.DefaultAPIPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.ExposeAPI = conf.SimpleExposureOpts{
|
cfg.ExposeAPI = conf.SimpleExposureOpts{
|
||||||
Host: exposeAPI.Host,
|
Host: exposeAPI.Host,
|
||||||
HostIP: exposeAPI.Binding.HostIP,
|
HostIP: exposeAPI.Binding.HostIP,
|
||||||
|
Loading…
Reference in New Issue
Block a user