Skip to content

Commit 2ee49ef

Browse files
trawlerkke
andauthored
Remove --config flag from token command (#303)
* Remove --config flag from token command This commit removes the config flag to comply with the changes in k0sproject/k0s#1409 Signed-off-by: Karen Almog <[email protected]> * Light touch-up * Typo Co-authored-by: Kimmo Lehto <[email protected]>
1 parent bbd575c commit 2ee49ef

File tree

1 file changed

+14
-3
lines changed
  • pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster

1 file changed

+14
-3
lines changed

pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/k0s.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/Masterminds/semver"
12+
"github.com/alessio/shellescape"
1213
"github.com/avast/retry-go"
1314
"github.com/creasty/defaults"
1415
validation "github.com/go-ozzo/ozzo-validation/v4"
@@ -91,10 +92,20 @@ func (k *K0s) SetDefaults() {
9192
}
9293

9394
// GenerateToken runs the k0s token create command
94-
func (k K0s) GenerateToken(h *Host, role string, expiry time.Duration) (token string, err error) {
95+
func (k K0s) GenerateToken(h *Host, role string, expiry time.Duration) (string, error) {
96+
var k0sFlags Flags
97+
k0sFlags.Add(fmt.Sprintf("--role %s", role))
98+
k0sFlags.Add(fmt.Sprintf("--expiry %s", expiry))
99+
100+
out, err := h.ExecOutput(h.Configurer.K0sCmdf("token create --help"), exec.Sudo(h))
101+
if err == nil && strings.Contains(out, "--config") {
102+
k0sFlags.Add(fmt.Sprintf("--config %s", shellescape.Quote(h.K0sConfigPath())))
103+
}
104+
105+
var token string
95106
err = retry.Do(
96107
func() error {
97-
output, err := h.ExecOutput(h.Configurer.K0sCmdf("token create --config %s --role %s --expiry %s", h.K0sConfigPath(), role, expiry.String()), exec.HideOutput(), exec.Sudo(h))
108+
output, err := h.ExecOutput(h.Configurer.K0sCmdf("token create %s", k0sFlags.Join()), exec.HideOutput(), exec.Sudo(h))
98109
if err != nil {
99110
return err
100111
}
@@ -107,7 +118,7 @@ func (k K0s) GenerateToken(h *Host, role string, expiry time.Duration) (token st
107118
retry.Attempts(60),
108119
retry.LastErrorOnly(true),
109120
)
110-
return
121+
return token, err
111122
}
112123

113124
// GetClusterID uses kubectl to fetch the kube-system namespace uid

0 commit comments

Comments
 (0)