Skip to content

Commit aaa01d2

Browse files
authored
Include k0sctl config path in "k0sctl kubeconfig" tip on apply success (#729)
Signed-off-by: Kimmo Lehto <[email protected]>
1 parent 68b97cd commit aaa01d2

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

action/apply.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package action
33
import (
44
"fmt"
55
"io"
6+
"os"
7+
"os/exec"
8+
"path/filepath"
9+
"strings"
610
"time"
711

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

3339
func (a Apply) Run() error {
@@ -116,8 +122,27 @@ func (a Apply) Run() error {
116122
}
117123

118124
if a.KubeconfigOut == nil {
125+
cmd := &strings.Builder{}
126+
executable, err := os.Executable()
127+
if err != nil {
128+
executable = "k0sctl"
129+
} else {
130+
// check if the basename of executable is in the PATH, if so, just use the basename
131+
if _, err := exec.LookPath(filepath.Base(executable)); err == nil {
132+
executable = filepath.Base(executable)
133+
}
134+
}
135+
136+
cmd.WriteString(executable)
137+
cmd.WriteString(" kubeconfig")
138+
139+
if a.ConfigPath != "" && a.ConfigPath != "-" && a.ConfigPath != "k0sctl.yaml" {
140+
cmd.WriteString(" --config ")
141+
cmd.WriteString(a.ConfigPath)
142+
}
143+
119144
log.Infof("Tip: To access the cluster you can now fetch the admin kubeconfig using:")
120-
log.Infof(" " + phase.Colorize.Cyan("k0sctl kubeconfig").String())
145+
log.Infof(" " + phase.Colorize.Cyan(cmd.String()).String())
121146
}
122147

123148
return nil

cmd/apply.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ var applyCommand = &cli.Command{
8181
NoDrain: ctx.Bool("no-drain"),
8282
DisableDowngradeCheck: ctx.Bool("disable-downgrade-check"),
8383
RestoreFrom: ctx.String("restore-from"),
84+
ConfigPath: ctx.String("config"),
8485
}
8586

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

0 commit comments

Comments
 (0)