@@ -3,6 +3,10 @@ package action
33import (
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
3339func (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
0 commit comments