Skip to content

Commit

Permalink
Remove --config flag from token command (#303)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
trawler and kke committed Jan 21, 2022
1 parent bbd575c commit 2ee49ef
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/Masterminds/semver"
"github.com/alessio/shellescape"
"github.com/avast/retry-go"
"github.com/creasty/defaults"
validation "github.com/go-ozzo/ozzo-validation/v4"
Expand Down Expand Up @@ -91,10 +92,20 @@ func (k *K0s) SetDefaults() {
}

// GenerateToken runs the k0s token create command
func (k K0s) GenerateToken(h *Host, role string, expiry time.Duration) (token string, err error) {
func (k K0s) GenerateToken(h *Host, role string, expiry time.Duration) (string, error) {
var k0sFlags Flags
k0sFlags.Add(fmt.Sprintf("--role %s", role))
k0sFlags.Add(fmt.Sprintf("--expiry %s", expiry))

out, err := h.ExecOutput(h.Configurer.K0sCmdf("token create --help"), exec.Sudo(h))
if err == nil && strings.Contains(out, "--config") {
k0sFlags.Add(fmt.Sprintf("--config %s", shellescape.Quote(h.K0sConfigPath())))
}

var token string
err = retry.Do(
func() error {
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))
output, err := h.ExecOutput(h.Configurer.K0sCmdf("token create %s", k0sFlags.Join()), exec.HideOutput(), exec.Sudo(h))
if err != nil {
return err
}
Expand All @@ -107,7 +118,7 @@ func (k K0s) GenerateToken(h *Host, role string, expiry time.Duration) (token st
retry.Attempts(60),
retry.LastErrorOnly(true),
)
return
return token, err
}

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

0 comments on commit 2ee49ef

Please sign in to comment.