Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions cmd/helmvm/install.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"context"
"fmt"
"io"
Expand Down Expand Up @@ -236,24 +237,27 @@ func runK0sctlApply(ctx context.Context) error {
// is overwritten, no questions asked.
func runK0sctlKubeconfig(ctx context.Context) error {
bin := defaults.PathToHelmVMBinary("k0sctl")
kpath := defaults.PathToConfig("kubeconfig")
fp, err := os.OpenFile(kpath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return fmt.Errorf("unable to open kubeconfig: %w", err)
}
defer fp.Close()
cfgpath := defaults.PathToConfig("k0sctl.yaml")
if _, err := os.Stat(cfgpath); err != nil {
os.RemoveAll(kpath)
return fmt.Errorf("cluster configuration not found")
}
kctl := exec.Command(bin, "kubeconfig", "-c", cfgpath, "--disable-telemetry")
kctl.Stderr = fp
kctl.Stdout = fp
buf := bytes.NewBuffer(nil)
kctl := exec.Command(bin, "kubeconfig", "-c", cfgpath)
kctl.Stderr, kctl.Stdout = buf, buf
if err := kctl.Run(); err != nil {
os.RemoveAll(kpath)
logrus.Errorf("Failed to read kubeconfig:")
logrus.Errorf(buf.String())
return fmt.Errorf("unable to run kubeconfig: %w", err)
}
kpath := defaults.PathToConfig("kubeconfig")
fp, err := os.OpenFile(kpath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return fmt.Errorf("unable to open kubeconfig: %w", err)
}
defer fp.Close()
if _, err := io.Copy(fp, buf); err != nil {
return fmt.Errorf("unable to write kubeconfig: %w", err)
}
logrus.Infof("Kubeconfig saved to %s", kpath)
return nil
}
Expand Down