server: trim the port off the dockerHost as it renders the kubeconfig unusable (fixes #487)

This commit is contained in:
iwilltry42 2021-02-09 16:21:55 +01:00
parent 26fa7224ff
commit e1384c91a2
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
3 changed files with 7 additions and 2 deletions

View File

@ -374,7 +374,7 @@ func patchAgentSpec(node *k3d.Node) error {
return nil 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 { func patchServerSpec(node *k3d.Node, runtime runtimes.Runtime) error {
// command / arguments // command / arguments
if node.Cmd == nil { if node.Cmd == nil {
@ -391,6 +391,8 @@ func patchServerSpec(node *k3d.Node, runtime runtimes.Runtime) error {
if runtime == runtimes.Docker { if runtime == runtimes.Docker {
dockerHost := runtime.GetHost() dockerHost := runtime.GetHost()
if dockerHost != "" { 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.LabelServerAPIHostIP] = dockerHost
node.Labels[k3d.LabelServerAPIHost] = dockerHost node.Labels[k3d.LabelServerAPIHost] = dockerHost
} }

View File

@ -25,6 +25,8 @@ package docker
import ( import (
"net/url" "net/url"
"os" "os"
log "github.com/sirupsen/logrus"
) )
type Docker struct{} type Docker struct{}
@ -41,6 +43,7 @@ func (d Docker) GetHost() string {
if err != nil { if err != nil {
return "" return ""
} }
log.Debugf("DockerHost: %s", url.Host)
return url.Host return url.Host
} }