From 400e85c3dbcd1c6b169cb0522a85e65a519119cf Mon Sep 17 00:00:00 2001 From: iwilltry42 Date: Mon, 11 Nov 2019 11:49:16 +0100 Subject: [PATCH] replace 'default' in kubeconfig with cluster name --- pkg/cluster/kubeconfig.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/cluster/kubeconfig.go b/pkg/cluster/kubeconfig.go index e123b76b..d076e455 100644 --- a/pkg/cluster/kubeconfig.go +++ b/pkg/cluster/kubeconfig.go @@ -69,7 +69,7 @@ func GetKubeconfig(runtime runtimes.Runtime, cluster *k3d.Cluster) ([]byte, erro // get the kubeconfig from the first master node reader, err := runtime.GetKubeconfig(chosenMaster) if err != nil { - log.Errorf("Failed to get kubeconfig from node '%s'", chosenMaster) + log.Errorf("Failed to get kubeconfig from node '%s'", chosenMaster.Name) return nil, err } defer reader.Close() @@ -84,8 +84,13 @@ func GetKubeconfig(runtime runtimes.Runtime, cluster *k3d.Cluster) ([]byte, erro // and trim any NULL characters trimBytes := bytes.Trim(readBytes[512:], "\x00") + // TODO: parse yaml and modify fields directly? + // replace host and port where the API is exposed with what we've found in the master node labels (or use the default) - trimBytes = []byte(strings.Replace(string(trimBytes), "localhost:6443", fmt.Sprintf("%s:%s", APIHost, APIPort), 1)) // replace localhost:6443 with localhost: in kubeconfig + trimBytes = []byte(strings.Replace(string(trimBytes), "localhost:6443", fmt.Sprintf("%s:%s", APIHost, APIPort), 1)) // replace localhost:6443 with : in kubeconfig + + // replace 'default' in kubeconfig with // TODO: only do this for the context and cluster name (?) -> parse yaml + trimBytes = []byte(strings.ReplaceAll(string(trimBytes), "default", cluster.Name)) return trimBytes, nil }