forked from rancher/rke2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Brad Davidson <[email protected]>
- Loading branch information
Showing
5 changed files
with
130 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,34 @@ | ||
package cmds | ||
|
||
import "testing" | ||
import ( | ||
"testing" | ||
|
||
"github.com/urfave/cli" | ||
) | ||
|
||
// Test_NewCommands confirms that all the top-level commands can be created | ||
// successfully without causing any panics in mustCmdFromK3S. Covering this | ||
// with a test allows us to catch K3s flag option mismatches in testing, | ||
// instead of not noticing until the main command crashes in functional tests. | ||
func Test_NewCommands(t *testing.T) { | ||
NewServerCommand() | ||
NewAgentCommand() | ||
NewEtcdSnapshotCommand() | ||
NewCertRotateCommand() | ||
NewSecretsEncryptCommand() | ||
app := cli.NewApp() | ||
app.Name = "rke2" | ||
app.Commands = []cli.Command{ | ||
NewServerCommand(), | ||
NewAgentCommand(), | ||
NewEtcdSnapshotCommand(), | ||
NewCertCommand(), | ||
NewSecretsEncryptCommand(), | ||
NewTokenCommand(), | ||
} | ||
|
||
for _, command := range app.Commands { | ||
t.Logf("Testing command: %s", command.Name) | ||
app.Run([]string{app.Name, command.Name, "--help"}) | ||
|
||
for _, subcommand := range command.Subcommands { | ||
t.Logf("Testing subcommand: %s %s", command.Name, subcommand.Name) | ||
app.Run([]string{app.Name, command.Name, subcommand.Name, "--help"}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cmds | ||
|
||
import ( | ||
"github.com/k3s-io/k3s/pkg/cli/cmds" | ||
"github.com/k3s-io/k3s/pkg/cli/token" | ||
"github.com/k3s-io/k3s/pkg/configfilearg" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func NewTokenCommand() cli.Command { | ||
k3sOpts := K3SFlagSet{ | ||
"kubeconfig": copy, | ||
"data-dir": { | ||
Usage: "(data) Folder to hold state", | ||
Default: rke2Path, | ||
}, | ||
} | ||
subCommandOpts := map[string]K3SFlagSet{ | ||
"create": { | ||
"description": copy, | ||
"groups": copy, | ||
"ttl": copy, | ||
"usages": copy, | ||
}, | ||
"list": { | ||
"output": copy, | ||
}, | ||
} | ||
|
||
command := cmds.NewTokenCommands(token.Create, token.Delete, token.Generate, token.List) | ||
configfilearg.DefaultParser.ValidFlags[command.Name] = command.Flags | ||
for i, subcommand := range command.Subcommands { | ||
if s, ok := subCommandOpts[subcommand.Name]; ok { | ||
k3sOpts.CopyInto(s) | ||
command.Subcommands[i] = mustCmdFromK3S(subcommand, s) | ||
} else { | ||
command.Subcommands[i] = mustCmdFromK3S(subcommand, k3sOpts) | ||
} | ||
} | ||
return mustCmdFromK3S(command, nil) | ||
} |