From 22c5bd2bcd07869af416f661c98e66df39bdd93d Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Wed, 12 Jun 2024 10:27:31 +0300 Subject: [PATCH] Replace reading admin.conf with reading output of "k0s kubeconfig admin" Signed-off-by: Kimmo Lehto --- phase/get_kubeconfig.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/phase/get_kubeconfig.go b/phase/get_kubeconfig.go index 93853c08..2b291d9b 100644 --- a/phase/get_kubeconfig.go +++ b/phase/get_kubeconfig.go @@ -4,8 +4,10 @@ import ( "fmt" "strings" + "github.com/alessio/shellescape" "github.com/k0sproject/dig" "github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster" + "github.com/k0sproject/rig/exec" "gopkg.in/yaml.v2" "k8s.io/client-go/tools/clientcmd" ) @@ -22,7 +24,11 @@ func (p *GetKubeconfig) Title() string { } var readKubeconfig = func(h *cluster.Host) (string, error) { - return h.Configurer.ReadFile(h, h.Configurer.KubeconfigPath(h, h.K0sDataDir())) + output, err := h.ExecOutput(h.Configurer.K0sCmdf("kubeconfig admin --data-dir=%s", shellescape.Quote(h.K0sDataDir())), exec.Sudo(h)) + if err != nil { + return "", fmt.Errorf("get kubeconfig from host: %w", err) + } + return output, nil } var k0sConfig = func(h *cluster.Host) (dig.Mapping, error) {