Skip to content

Commit

Permalink
Fix token commands role defaulting
Browse files Browse the repository at this point in the history
Signed-off-by: Jussi Nummelin <[email protected]>
  • Loading branch information
jnummelin authored and ncopa committed May 20, 2021
1 parent 4fadec4 commit 57353ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions cmd/token/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"github.com/k0sproject/k0s/pkg/token"
)

var createTokenRole string

func tokenCreateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Expand Down Expand Up @@ -58,7 +60,7 @@ k0s token create --role worker --expiry 10m //sets expiration time to 10 minute
}, func(err error) bool {
return waitCreate
}, func() error {
bootstrapConfig, err = token.CreateKubeletBootstrapConfig(clusterConfig, c.K0sVars, tokenRole, expiry)
bootstrapConfig, err = token.CreateKubeletBootstrapConfig(clusterConfig, c.K0sVars, createTokenRole, expiry)

return err
})
Expand All @@ -71,11 +73,12 @@ k0s token create --role worker --expiry 10m //sets expiration time to 10 minute
return nil
},
}
// append flags
cmd.PersistentFlags().AddFlagSet(config.GetPersistentFlagSet())

cmd.Flags().StringVar(&tokenExpiry, "expiry", "0s", "Expiration time of the token. Format 1.5h, 2h45m or 300ms.")
cmd.Flags().StringVar(&tokenRole, "role", "worker", "Either worker or controller")
cmd.Flags().StringVar(&createTokenRole, "role", "worker", "Either worker or controller")
cmd.Flags().BoolVar(&waitCreate, "wait", false, "wait forever (default false)")

// append flags
cmd.PersistentFlags().AddFlagSet(config.GetPersistentFlagSet())
return cmd
}
6 changes: 4 additions & 2 deletions cmd/token/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"github.com/spf13/cobra"
)

var listTokenRole string

func tokenListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Expand All @@ -38,7 +40,7 @@ func tokenListCmd() *cobra.Command {
return err
}

tokens, err := manager.List(tokenRole)
tokens, err := manager.List(listTokenRole)
if err != nil {
return err
}
Expand Down Expand Up @@ -70,7 +72,7 @@ func tokenListCmd() *cobra.Command {
return nil
},
}
cmd.Flags().StringVar(&tokenRole, "role", "", "Either worker, controller or empty for all roles")
cmd.Flags().StringVar(&listTokenRole, "role", "", "Either worker, controller or empty for all roles")
cmd.PersistentFlags().AddFlagSet(config.GetPersistentFlagSet())
return cmd
}
1 change: 0 additions & 1 deletion cmd/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type CmdOpts config.CLIOptions

var (
tokenExpiry string
tokenRole string
waitCreate bool
)

Expand Down

0 comments on commit 57353ac

Please sign in to comment.