From e1384c91a2f794e4cf0061fcce2f48b3824a70fe Mon Sep 17 00:00:00 2001 From: iwilltry42 Date: Tue, 9 Feb 2021 16:21:55 +0100 Subject: [PATCH] server: trim the port off the dockerHost as it renders the kubeconfig unusable (fixes #487) --- cmd/cluster/clusterCreate.go | 2 +- pkg/client/node.go | 4 +++- pkg/runtimes/docker/docker.go | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/cluster/clusterCreate.go b/cmd/cluster/clusterCreate.go index 07d16f46..70b263c7 100644 --- a/cmd/cluster/clusterCreate.go +++ b/cmd/cluster/clusterCreate.go @@ -352,7 +352,7 @@ func applyCLIOverrides(cfg conf.SimpleConfig) (conf.SimpleConfig, error) { // -> API-PORT // parse the port mapping var ( - err error + err error exposeAPI *k3d.ExposureOpts ) diff --git a/pkg/client/node.go b/pkg/client/node.go index 38c05910..9fb2a546 100644 --- a/pkg/client/node.go +++ b/pkg/client/node.go @@ -374,7 +374,7 @@ func patchAgentSpec(node *k3d.Node) error { return nil } -// patchServerSpec adds agent node specific settings to a node +// patchServerSpec adds server node specific settings to a node func patchServerSpec(node *k3d.Node, runtime runtimes.Runtime) error { // command / arguments if node.Cmd == nil { @@ -391,6 +391,8 @@ func patchServerSpec(node *k3d.Node, runtime runtimes.Runtime) error { if runtime == runtimes.Docker { dockerHost := runtime.GetHost() if dockerHost != "" { + dockerHost = strings.Split(dockerHost, ":")[0] // remove the port + log.Tracef("Using docker host %s", dockerHost) node.Labels[k3d.LabelServerAPIHostIP] = dockerHost node.Labels[k3d.LabelServerAPIHost] = dockerHost } diff --git a/pkg/runtimes/docker/docker.go b/pkg/runtimes/docker/docker.go index a0060377..607a2006 100644 --- a/pkg/runtimes/docker/docker.go +++ b/pkg/runtimes/docker/docker.go @@ -25,6 +25,8 @@ package docker import ( "net/url" "os" + + log "github.com/sirupsen/logrus" ) type Docker struct{} @@ -41,6 +43,7 @@ func (d Docker) GetHost() string { if err != nil { return "" } + log.Debugf("DockerHost: %s", url.Host) return url.Host }