Skip to content

Commit

Permalink
Include k0sctl config path in "k0sctl kubeconfig" tip on apply success (
Browse files Browse the repository at this point in the history
#729)

Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke committed Jun 10, 2024
1 parent 68b97cd commit aaa01d2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
27 changes: 26 additions & 1 deletion action/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package action
import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"strings"
"time"

"github.com/k0sproject/k0sctl/analytics"
Expand All @@ -28,6 +32,8 @@ type Apply struct {
KubeconfigOut io.Writer
// KubeconfigAPIAddress is the API address to use in the kubeconfig
KubeconfigAPIAddress string
// ConfigPath is the path to the configuration file (used for kubeconfig command tip on success)
ConfigPath string
}

func (a Apply) Run() error {
Expand Down Expand Up @@ -116,8 +122,27 @@ func (a Apply) Run() error {
}

if a.KubeconfigOut == nil {
cmd := &strings.Builder{}
executable, err := os.Executable()
if err != nil {
executable = "k0sctl"
} else {
// check if the basename of executable is in the PATH, if so, just use the basename
if _, err := exec.LookPath(filepath.Base(executable)); err == nil {
executable = filepath.Base(executable)
}
}

cmd.WriteString(executable)
cmd.WriteString(" kubeconfig")

if a.ConfigPath != "" && a.ConfigPath != "-" && a.ConfigPath != "k0sctl.yaml" {
cmd.WriteString(" --config ")
cmd.WriteString(a.ConfigPath)
}

log.Infof("Tip: To access the cluster you can now fetch the admin kubeconfig using:")
log.Infof(" " + phase.Colorize.Cyan("k0sctl kubeconfig").String())
log.Infof(" " + phase.Colorize.Cyan(cmd.String()).String())
}

return nil
Expand Down
1 change: 1 addition & 0 deletions cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ var applyCommand = &cli.Command{
NoDrain: ctx.Bool("no-drain"),
DisableDowngradeCheck: ctx.Bool("disable-downgrade-check"),
RestoreFrom: ctx.String("restore-from"),
ConfigPath: ctx.String("config"),
}

if err := applyAction.Run(); err != nil {
Expand Down

0 comments on commit aaa01d2

Please sign in to comment.