From 152c76ebc7a188a4b01ca5a5dc5fed2f523607f1 Mon Sep 17 00:00:00 2001 From: Anuj Chaudhari Date: Thu, 22 Feb 2024 16:04:52 -0800 Subject: [PATCH] Add new target `operations`/`ops` (#679) * Add operations target * Update shell completion * Update help for target commands * Fix unit tests, Update README --- docs/cli/commands/tanzu_plugin_describe.md | 2 +- docs/cli/commands/tanzu_plugin_install.md | 2 +- docs/cli/commands/tanzu_plugin_search.md | 2 +- docs/cli/commands/tanzu_plugin_uninstall.md | 2 +- docs/cli/commands/tanzu_plugin_upgrade.md | 2 +- docs/full/README.md | 17 ++- docs/quickstart/quickstart.md | 5 +- go.mod | 2 +- go.sum | 4 +- pkg/command/completion_helper.go | 5 +- pkg/command/plugin.go | 14 ++- pkg/command/plugin_search.go | 2 +- pkg/command/plugin_search_test.go | 2 +- pkg/command/plugin_test.go | 13 ++- pkg/command/root.go | 24 +++- pkg/command/root_test.go | 116 +++++++++++++++++--- pkg/common/constants.go | 2 +- test/e2e/framework/framework_constants.go | 2 +- 18 files changed, 166 insertions(+), 52 deletions(-) diff --git a/docs/cli/commands/tanzu_plugin_describe.md b/docs/cli/commands/tanzu_plugin_describe.md index 21a498119..07838e21f 100644 --- a/docs/cli/commands/tanzu_plugin_describe.md +++ b/docs/cli/commands/tanzu_plugin_describe.md @@ -15,7 +15,7 @@ tanzu plugin describe PLUGIN_NAME [flags] ``` -h, --help help for describe -o, --output string Output format (yaml|json|table) - -t, --target string target of the plugin (kubernetes[k8s]/mission-control[tmc]/global) + -t, --target string target of the plugin (kubernetes[k8s]/mission-control[tmc]/operations[ops]/global) ``` ### SEE ALSO diff --git a/docs/cli/commands/tanzu_plugin_install.md b/docs/cli/commands/tanzu_plugin_install.md index b36b5cf53..0f562bf49 100644 --- a/docs/cli/commands/tanzu_plugin_install.md +++ b/docs/cli/commands/tanzu_plugin_install.md @@ -48,7 +48,7 @@ tanzu plugin install [PLUGIN_NAME] [flags] ``` --group string install the plugins specified by a plugin-group version -h, --help help for install - -t, --target string target of the plugin (kubernetes[k8s]/mission-control[tmc]/global) + -t, --target string target of the plugin (kubernetes[k8s]/mission-control[tmc]/operations[ops]/global) -v, --version string version of the plugin (default "latest") ``` diff --git a/docs/cli/commands/tanzu_plugin_search.md b/docs/cli/commands/tanzu_plugin_search.md index 7ae198889..4048a727c 100644 --- a/docs/cli/commands/tanzu_plugin_search.md +++ b/docs/cli/commands/tanzu_plugin_search.md @@ -20,7 +20,7 @@ tanzu plugin search [flags] -n, --name string limit the search to plugins with the specified name -o, --output string output format (yaml|json|table) --show-details show the details of the specified plugin, including all available versions - -t, --target string limit the search to plugins of the specified target (kubernetes[k8s]/mission-control[tmc]/global) + -t, --target string limit the search to plugins of the specified target (kubernetes[k8s]/mission-control[tmc]/operations[ops]/global) ``` ### SEE ALSO diff --git a/docs/cli/commands/tanzu_plugin_uninstall.md b/docs/cli/commands/tanzu_plugin_uninstall.md index f12440272..6e56065bb 100644 --- a/docs/cli/commands/tanzu_plugin_uninstall.md +++ b/docs/cli/commands/tanzu_plugin_uninstall.md @@ -14,7 +14,7 @@ tanzu plugin uninstall PLUGIN_NAME [flags] ``` -h, --help help for uninstall - -t, --target string target of the plugin (kubernetes[k8s]/mission-control[tmc]/global) + -t, --target string target of the plugin (kubernetes[k8s]/mission-control[tmc]/operations[ops]/global) -y, --yes uninstall the plugin without asking for confirmation ``` diff --git a/docs/cli/commands/tanzu_plugin_upgrade.md b/docs/cli/commands/tanzu_plugin_upgrade.md index 4f6afb2c5..f08c70378 100644 --- a/docs/cli/commands/tanzu_plugin_upgrade.md +++ b/docs/cli/commands/tanzu_plugin_upgrade.md @@ -14,7 +14,7 @@ tanzu plugin upgrade PLUGIN_NAME [flags] ``` -h, --help help for upgrade - -t, --target string target of the plugin (kubernetes[k8s]/mission-control[tmc]/global) + -t, --target string target of the plugin (kubernetes[k8s]/mission-control[tmc]/operations[ops]/global) ``` ### SEE ALSO diff --git a/docs/full/README.md b/docs/full/README.md index a8da90a25..69a4f7c78 100644 --- a/docs/full/README.md +++ b/docs/full/README.md @@ -51,16 +51,14 @@ contexts for the same combination of `(user, server)`. ## Target -A Target refers to a category or tier of control planes that the CLI can -interact with. There are currently two supported targets : `kubernetes` (or -`k8s`) and `mission-control` (or `tmc`) which corresponds to the Kubernetes -cluster endpoint type and Tanzu Mission Control endpoint type respectively. A -context is associated with one of the two supported targets. Plugins are +A Target refers to a category of commands or tier of control planes that the CLI +can interact with. There are currently three supported targets : `kubernetes` (or +`k8s`), `mission-control` (or `tmc`) and `operations` (or `ops`). Plugins are generally associated with one of the above mentioned targets but if a plugin doesn't fall into any of the above categories a developer can create a plugin with the `global` target. A plugin using the `global` target is available as a -root Tanzu CLI sub-command. To see plugins that only apply to the `kubernetes` target -or only to the `mission-control` target, run the command `tanzu '. +root Tanzu CLI sub-command. To see plugins that only apply to a specific target, +run the command `tanzu '. Similarly, commands from plugins that are associated with a target are unambiguously invoked by prefixing the command group with the target, like so: @@ -69,13 +67,14 @@ unambiguously invoked by prefixing the command group with the target, like so: tanzu mission-control data-protection ... or tanzu k8s management-cluster ... +or +tanzu operations clustergroup ... ``` Note that today, the CLI supports omitting the target for historical reasons, but this omission only applies to commands for the `k8s` target. (So `tanzu management-cluster ...` is a valid variant of the above example, but not -`tanzu data-protection ...`). The CLI team is exploring making the 'assumed target' -configurable. +`tanzu data-protection ...` or `tanzu clustergroup`). Note also that until a plugin associated with a target is installed, the target in question will be hidden from the user. For example, if no `tmc`/`mission-control` diff --git a/docs/quickstart/quickstart.md b/docs/quickstart/quickstart.md index 21167e887..4da877f18 100644 --- a/docs/quickstart/quickstart.md +++ b/docs/quickstart/quickstart.md @@ -21,8 +21,9 @@ such sets of plugins. *Target* : A class of control-plane endpoints that a plugin may interact with. The list of targets supported thus far are `kubernetes`, which applies to -Kubernetes clusters, and `mission-control`, which applies to Tanzu Mission -Control service endpoints. A plugin can be associated with one or zero targets. +Kubernetes endpoint, `mission-control`, which applies to Tanzu Mission +Control service endpoints, and `operations`, to support Kubernetes operations +for Tanzu Application Platform. A plugin can be associated with one or zero targets. A plugin associated with no target implies its functionality can be used regardless of what endpoint the CLI may be connecting to. diff --git a/go.mod b/go.mod index ec6d83a32..44f169a03 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,7 @@ require ( github.com/vmware-tanzu/carvel-ytt v0.40.0 github.com/vmware-tanzu/tanzu-cli/test/e2e/framework v0.0.0-00010101000000-000000000000 github.com/vmware-tanzu/tanzu-framework/capabilities/client v0.0.0-20230523145612-1c6fbba34686 - github.com/vmware-tanzu/tanzu-plugin-runtime v1.2.0-dev.0.20240206192120-055fd83cf63d + github.com/vmware-tanzu/tanzu-plugin-runtime v1.2.0-dev.0.20240222161642-59c7320668fa go.pinniped.dev v0.20.0 golang.org/x/mod v0.12.0 golang.org/x/oauth2 v0.8.0 diff --git a/go.sum b/go.sum index 5e7b06c06..afed0ce54 100644 --- a/go.sum +++ b/go.sum @@ -738,8 +738,8 @@ github.com/vmware-tanzu/tanzu-framework/apis/run v0.0.0-20230419030809-7081502eb github.com/vmware-tanzu/tanzu-framework/apis/run v0.0.0-20230419030809-7081502ebf68/go.mod h1:e1Uef+Ux5BIHpYwqbeP2ZZmOzehBcez2vUEWXHe+xHE= github.com/vmware-tanzu/tanzu-framework/capabilities/client v0.0.0-20230523145612-1c6fbba34686 h1:VcuXqUXFxm5WDqWkzAlU/6cJXua0ozELnqD59fy7J6E= github.com/vmware-tanzu/tanzu-framework/capabilities/client v0.0.0-20230523145612-1c6fbba34686/go.mod h1:AFGOXZD4tH+KhpmtV0VjWjllXhr8y57MvOsIxTtywc4= -github.com/vmware-tanzu/tanzu-plugin-runtime v1.2.0-dev.0.20240206192120-055fd83cf63d h1:I2eep1os5VH2jdFMFC1ObjzUcOrNFARWubZbpDkTEGk= -github.com/vmware-tanzu/tanzu-plugin-runtime v1.2.0-dev.0.20240206192120-055fd83cf63d/go.mod h1:M7WVZoItdyQp53tEprQIa6PZmhbrLe3CzuyQphWuRyI= +github.com/vmware-tanzu/tanzu-plugin-runtime v1.2.0-dev.0.20240222161642-59c7320668fa h1:153bh9h0EVQHX0EjyiHy+w9KjfLkcN5Z9jITKdKnHpo= +github.com/vmware-tanzu/tanzu-plugin-runtime v1.2.0-dev.0.20240222161642-59c7320668fa/go.mod h1:M7WVZoItdyQp53tEprQIa6PZmhbrLe3CzuyQphWuRyI= github.com/xanzy/go-gitlab v0.83.0 h1:37p0MpTPNbsTMKX/JnmJtY8Ch1sFiJzVF342+RvZEGw= github.com/xanzy/go-gitlab v0.83.0/go.mod h1:5ryv+MnpZStBH8I/77HuQBsMbBGANtVpLWC15qOjWAw= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= diff --git a/pkg/command/completion_helper.go b/pkg/command/completion_helper.go index f626b283a..2e5a5e01d 100644 --- a/pkg/command/completion_helper.go +++ b/pkg/command/completion_helper.go @@ -10,8 +10,9 @@ import ( const ( // Completion strings for the values of the --target flag compGlobalTarget = "global\tApplicable globally" - compK8sTarget = "k8s\tFor interactions with a Kubernetes cluster" - compTMCTarget = "tmc\tFor interactions with a Tanzu Mission Control endpoint" + compK8sTarget = "k8s\tInteractions with a Kubernetes endpoint" + compTMCTarget = "tmc\tInteractions with a Tanzu Mission Control endpoint" + compOpsTarget = "ops\tKubernetes operations for Tanzu Application Platform" // Completion strings for the values of the --type flag compK8sContextType = "k8s\tContext for a Kubernetes cluster" diff --git a/pkg/command/plugin.go b/pkg/command/plugin.go index cf540ad91..58a8a73a5 100644 --- a/pkg/command/plugin.go +++ b/pkg/command/plugin.go @@ -980,12 +980,12 @@ func completeTargetsForInstalledPlugins(_ *cobra.Command, args []string, _ strin pluginName := args[0] if pluginName == cli.AllPlugins { // Suggest all targets - return []string{compGlobalTarget, compK8sTarget, compTMCTarget}, cobra.ShellCompDirectiveNoFileComp + return []string{compGlobalTarget, compK8sTarget, compTMCTarget, compOpsTarget}, cobra.ShellCompDirectiveNoFileComp } installedPlugins, err := pluginsupplier.GetInstalledPlugins() if err != nil { - return []string{compGlobalTarget, compK8sTarget, compTMCTarget}, cobra.ShellCompDirectiveNoFileComp + return []string{compGlobalTarget, compK8sTarget, compTMCTarget, compOpsTarget}, cobra.ShellCompDirectiveNoFileComp } // Find all plugins matching the pluginName. Each of the corresponding target should be suggested @@ -998,7 +998,7 @@ func completeTargetsForInstalledPlugins(_ *cobra.Command, args []string, _ strin // If we found no plugins with the correct name, just complete all targets if len(availableTargets) == 0 { - return []string{compGlobalTarget, compK8sTarget, compTMCTarget}, cobra.ShellCompDirectiveNoFileComp + return []string{compGlobalTarget, compK8sTarget, compTMCTarget, compOpsTarget}, cobra.ShellCompDirectiveNoFileComp } sort.Strings(availableTargets) @@ -1006,7 +1006,7 @@ func completeTargetsForInstalledPlugins(_ *cobra.Command, args []string, _ strin } // Suggest all targets - return []string{compGlobalTarget, compK8sTarget, compTMCTarget}, cobra.ShellCompDirectiveNoFileComp + return []string{compGlobalTarget, compK8sTarget, compTMCTarget, compOpsTarget}, cobra.ShellCompDirectiveNoFileComp } func completeTargetsForAllPlugins(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) { @@ -1021,7 +1021,7 @@ func completeTargetsForAllPlugins(_ *cobra.Command, args []string, _ string) ([] // If we found no plugins with the correct name, just complete all targets if err != nil || len(plugins) == 0 { - return []string{compGlobalTarget, compK8sTarget, compTMCTarget}, cobra.ShellCompDirectiveNoFileComp + return []string{compGlobalTarget, compK8sTarget, compTMCTarget, compOpsTarget}, cobra.ShellCompDirectiveNoFileComp } // For all plugins withe the specified name, the corresponding target should be suggested @@ -1034,7 +1034,7 @@ func completeTargetsForAllPlugins(_ *cobra.Command, args []string, _ string) ([] } // Suggest all targets - return []string{compGlobalTarget, compK8sTarget, compTMCTarget}, cobra.ShellCompDirectiveNoFileComp + return []string{compGlobalTarget, compK8sTarget, compTMCTarget, compOpsTarget}, cobra.ShellCompDirectiveNoFileComp } func compTargetToCompString(target configtypes.Target) string { @@ -1045,6 +1045,8 @@ func compTargetToCompString(target configtypes.Target) string { return compK8sTarget case configtypes.TargetTMC: return compTMCTarget + case configtypes.TargetOperations: + return compOpsTarget } return string(target) } diff --git a/pkg/command/plugin_search.go b/pkg/command/plugin_search.go index e62e95f74..a5feb799b 100644 --- a/pkg/command/plugin_search.go +++ b/pkg/command/plugin_search.go @@ -100,7 +100,7 @@ func newSearchPluginCmd() *cobra.Command { f.StringVarP(&targetStr, "target", "t", "", fmt.Sprintf("limit the search to plugins of the specified target (%s)", common.TargetList)) utils.PanicOnErr(searchCmd.RegisterFlagCompletionFunc("target", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { - return []string{compGlobalTarget, compK8sTarget, compTMCTarget}, cobra.ShellCompDirectiveNoFileComp + return []string{compGlobalTarget, compK8sTarget, compTMCTarget, compOpsTarget}, cobra.ShellCompDirectiveNoFileComp })) searchCmd.MarkFlagsMutuallyExclusive("local", "name") diff --git a/pkg/command/plugin_search_test.go b/pkg/command/plugin_search_test.go index 1e1f6b7b7..d6ecf369f 100644 --- a/pkg/command/plugin_search_test.go +++ b/pkg/command/plugin_search_test.go @@ -105,7 +105,7 @@ func TestCompletionPluginSearch(t *testing.T) { // command. Let's deactivate it. os.Setenv("TANZU_ACTIVE_HELP", "no_short_help") - expectedOutforTargetFlag := compGlobalTarget + "\n" + compK8sTarget + "\n" + compTMCTarget + "\n" + expectedOutforTargetFlag := compGlobalTarget + "\n" + compK8sTarget + "\n" + compTMCTarget + "\n" + compOpsTarget + "\n" tests := []struct { test string diff --git a/pkg/command/plugin_test.go b/pkg/command/plugin_test.go index 6b3115810..227418f48 100644 --- a/pkg/command/plugin_test.go +++ b/pkg/command/plugin_test.go @@ -209,7 +209,7 @@ func TestDeletePlugin(t *testing.T) { targets: []configtypes.Target{configtypes.TargetTMC, configtypes.TargetK8s}, args: []string{"plugin", "delete", "foo", "-y"}, expectedFailure: true, - expectedErrorMsg: "unable to uniquely identify plugin 'foo'. Please specify the target (kubernetes[k8s]/mission-control[tmc]/global) of the plugin using the `--target` flag", + expectedErrorMsg: "unable to uniquely identify plugin 'foo'. Please specify the target (kubernetes[k8s]/mission-control[tmc]/operations[ops]/global) of the plugin using the `--target` flag", }, { test: "delete an installed plugin present for multiple targets using --target", @@ -476,8 +476,8 @@ func TestCompletionPlugin(t *testing.T) { // This is global logic and needs not be tested for each // command. Let's deactivate it. os.Setenv("TANZU_ACTIVE_HELP", "no_short_help") - // Test local discovery + localSourcePath := filepath.Join("..", "fakes", "plugins", cli.GOOS, cli.GOARCH) tests := []struct { @@ -636,6 +636,7 @@ func TestCompletionPlugin(t *testing.T) { expected: compGlobalTarget + "\n" + compK8sTarget + "\n" + compTMCTarget + "\n" + + compOpsTarget + "\n" + ":4\n", }, { @@ -652,6 +653,7 @@ func TestCompletionPlugin(t *testing.T) { expected: compGlobalTarget + "\n" + compK8sTarget + "\n" + compTMCTarget + "\n" + + compOpsTarget + "\n" + ":4\n", }, @@ -759,6 +761,7 @@ func TestCompletionPlugin(t *testing.T) { expected: compGlobalTarget + "\n" + compK8sTarget + "\n" + compTMCTarget + "\n" + + compOpsTarget + "\n" + ":4\n", }, { @@ -776,6 +779,7 @@ func TestCompletionPlugin(t *testing.T) { expected: compGlobalTarget + "\n" + compK8sTarget + "\n" + compTMCTarget + "\n" + + compOpsTarget + "\n" + ":4\n", }, @@ -849,6 +853,7 @@ func TestCompletionPlugin(t *testing.T) { expected: compGlobalTarget + "\n" + compK8sTarget + "\n" + compTMCTarget + "\n" + + compOpsTarget + "\n" + ":4\n", }, { @@ -866,6 +871,7 @@ func TestCompletionPlugin(t *testing.T) { expected: compGlobalTarget + "\n" + compK8sTarget + "\n" + compTMCTarget + "\n" + + compOpsTarget + "\n" + ":4\n", }, { @@ -875,6 +881,7 @@ func TestCompletionPlugin(t *testing.T) { expected: compGlobalTarget + "\n" + compK8sTarget + "\n" + compTMCTarget + "\n" + + compOpsTarget + "\n" + ":4\n", }, // ===================== @@ -926,6 +933,7 @@ func TestCompletionPlugin(t *testing.T) { expected: compGlobalTarget + "\n" + compK8sTarget + "\n" + compTMCTarget + "\n" + + compOpsTarget + "\n" + ":4\n", }, { @@ -942,6 +950,7 @@ func TestCompletionPlugin(t *testing.T) { expected: compGlobalTarget + "\n" + compK8sTarget + "\n" + compTMCTarget + "\n" + + compOpsTarget + "\n" + ":4\n", }, } diff --git a/pkg/command/root.go b/pkg/command/root.go index d9ee04b33..66948767d 100644 --- a/pkg/command/root.go +++ b/pkg/command/root.go @@ -52,6 +52,7 @@ func NewRootCmd() (*cobra.Command, error) { contextCmd, k8sCmd, tmcCmd, + opsCmd, // Note(TODO:prkalle): The below ceip-participation command(experimental) added may be removed in the next release, // If we decide to fold this functionality into existing 'tanzu telemetry' plugin newCEIPParticipationCmd(), @@ -131,8 +132,9 @@ func NewRootCmd() (*cobra.Command, error) { // setupTargetPlugins sets up the commands for the plugins under the k8s and tmc targets func setupTargetPlugins() error { mapTargetToCmd := map[configtypes.Target]*cobra.Command{ - configtypes.TargetK8s: k8sCmd, - configtypes.TargetTMC: tmcCmd, + configtypes.TargetK8s: k8sCmd, + configtypes.TargetTMC: tmcCmd, + configtypes.TargetOperations: opsCmd, } installedPlugins, err := pluginsupplier.GetInstalledPlugins() @@ -267,7 +269,7 @@ func InstallEssentialPlugins(cmd *cobra.Command) { func handleTargetHelp(cmd *cobra.Command, args []string) { // If there are no plugins installed for this target, print a message if len(cmd.Commands()) == 0 { - fmt.Fprintf(cmd.OutOrStdout(), "Note: No plugins are currently installed for the %[1]q target.\n Such plugins will be accessible when a %[1]q context is created/activated or a %[1]q plugin is explicitly installed.\n\n", cmd.Name()) + fmt.Fprintf(cmd.OutOrStdout(), "Note: No plugins are currently installed for the %[1]q target.\n\n", cmd.Name()) } // Always print the help for the target command is invoked without any subcommand cmd.HelpFunc()(cmd, args) @@ -275,7 +277,7 @@ func handleTargetHelp(cmd *cobra.Command, args []string) { var k8sCmd = &cobra.Command{ Use: "kubernetes", - Short: "Tanzu CLI plugins that target a Kubernetes cluster", + Short: "Commands that interact with a Kubernetes endpoint", Aliases: []string{"k8s"}, Annotations: map[string]string{ "group": string(plugin.TargetCmdGroup), @@ -287,7 +289,7 @@ var k8sCmd = &cobra.Command{ var tmcCmd = &cobra.Command{ Use: "mission-control", - Short: "Tanzu CLI plugins that target a Tanzu Mission Control endpoint", + Short: "Commands that provide functionality for Tanzu Mission Control", Aliases: []string{"tmc"}, Annotations: map[string]string{ "group": string(plugin.TargetCmdGroup), @@ -297,6 +299,18 @@ var tmcCmd = &cobra.Command{ }, } +var opsCmd = &cobra.Command{ + Use: "operations", + Short: "Commands that support Kubernetes operations for Tanzu Application Platform", + Aliases: []string{"ops"}, + Annotations: map[string]string{ + "group": string(plugin.TargetCmdGroup), + }, + Run: func(cmd *cobra.Command, args []string) { + handleTargetHelp(cmd, args) + }, +} + func findSubCommand(rootCmd, subCmd *cobra.Command) *cobra.Command { arrSubCmd := rootCmd.Commands() for i := range arrSubCmd { diff --git a/pkg/command/root_test.go b/pkg/command/root_test.go index 254d90a4a..b6e45015f 100644 --- a/pkg/command/root_test.go +++ b/pkg/command/root_test.go @@ -436,7 +436,7 @@ func TestTargetCommands(t *testing.T) { args: []string{"k8s"}, expected: []string{ "Note: No plugins are currently installed for the \"kubernetes\" target", - "Tanzu CLI plugins that target a Kubernetes cluster", + "Commands that interact with a Kubernetes endpoint", }, unexpected: []string{ "Available command groups", @@ -446,7 +446,7 @@ func TestTargetCommands(t *testing.T) { test: "help for k8s target help when empty", args: []string{"k8s", "-h"}, expected: []string{ - "Tanzu CLI plugins that target a Kubernetes cluster", + "Commands that interact with a Kubernetes endpoint", }, unexpected: []string{ "Available command groups", @@ -457,7 +457,7 @@ func TestTargetCommands(t *testing.T) { args: []string{"k8s", "invalid"}, expected: []string{ "Note: No plugins are currently installed for the \"kubernetes\" target", - "Tanzu CLI plugins that target a Kubernetes cluster", + "Commands that interact with a Kubernetes endpoint", }, unexpected: []string{ "Available command groups", @@ -468,7 +468,7 @@ func TestTargetCommands(t *testing.T) { args: []string{"k8s"}, installedPluginTargets: []configtypes.Target{configtypes.TargetK8s}, expected: []string{ - "Tanzu CLI plugins that target a Kubernetes cluster", + "Commands that interact with a Kubernetes endpoint", "Available command groups:\n\n System\n dummy dummy \n\nFlags:", }, unexpected: []string{ @@ -480,7 +480,7 @@ func TestTargetCommands(t *testing.T) { args: []string{"k8s", "-h"}, installedPluginTargets: []configtypes.Target{configtypes.TargetK8s}, expected: []string{ - "Tanzu CLI plugins that target a Kubernetes cluster", + "Commands that interact with a Kubernetes endpoint", "Available command groups:\n\n System\n dummy dummy \n\nFlags:", }, unexpected: []string{ @@ -492,7 +492,7 @@ func TestTargetCommands(t *testing.T) { args: []string{"k8s"}, installedPluginTargets: []configtypes.Target{configtypes.TargetTMC}, expected: []string{ - "Tanzu CLI plugins that target a Kubernetes cluster", + "Commands that interact with a Kubernetes endpoint", "Note: No plugins are currently installed for the \"kubernetes\" target", }, unexpected: []string{ @@ -504,7 +504,7 @@ func TestTargetCommands(t *testing.T) { args: []string{"k8s", "-h"}, installedPluginTargets: []configtypes.Target{configtypes.TargetTMC}, expected: []string{ - "Tanzu CLI plugins that target a Kubernetes cluster", + "Commands that interact with a Kubernetes endpoint", }, unexpected: []string{ "Available command groups", @@ -518,7 +518,7 @@ func TestTargetCommands(t *testing.T) { args: []string{"tmc"}, expected: []string{ "Note: No plugins are currently installed for the \"mission-control\" target", - "Tanzu CLI plugins that target a Tanzu Mission Control endpoint", + "Commands that provide functionality for Tanzu Mission Control", }, unexpected: []string{ "Available command groups", @@ -528,7 +528,7 @@ func TestTargetCommands(t *testing.T) { test: "help for tmc target help when empty", args: []string{"tmc", "-h"}, expected: []string{ - "Tanzu CLI plugins that target a Tanzu Mission Control endpoint", + "Commands that provide functionality for Tanzu Mission Control", }, unexpected: []string{ "Available command groups", @@ -539,7 +539,7 @@ func TestTargetCommands(t *testing.T) { args: []string{"tmc", "invalid"}, expected: []string{ "Note: No plugins are currently installed for the \"mission-control\" target", - "Tanzu CLI plugins that target a Tanzu Mission Control endpoint", + "Commands that provide functionality for Tanzu Mission Control", }, unexpected: []string{ "Available command groups", @@ -550,7 +550,7 @@ func TestTargetCommands(t *testing.T) { args: []string{"tmc"}, installedPluginTargets: []configtypes.Target{configtypes.TargetTMC}, expected: []string{ - "Tanzu CLI plugins that target a Tanzu Mission Control endpoint", + "Commands that provide functionality for Tanzu Mission Control", "Available command groups:\n\n System\n dummy dummy \n\nFlags:", }, unexpected: []string{ @@ -562,7 +562,7 @@ func TestTargetCommands(t *testing.T) { args: []string{"tmc", "-h"}, installedPluginTargets: []configtypes.Target{configtypes.TargetTMC}, expected: []string{ - "Tanzu CLI plugins that target a Tanzu Mission Control endpoint", + "Commands that provide functionality for Tanzu Mission Control", "Available command groups:\n\n System\n dummy dummy \n\nFlags:", }, unexpected: []string{ @@ -574,7 +574,7 @@ func TestTargetCommands(t *testing.T) { args: []string{"tmc"}, installedPluginTargets: []configtypes.Target{configtypes.TargetK8s}, expected: []string{ - "Tanzu CLI plugins that target a Tanzu Mission Control endpoint", + "Commands that provide functionality for Tanzu Mission Control", "Note: No plugins are currently installed for the \"mission-control\" target", }, unexpected: []string{ @@ -586,7 +586,89 @@ func TestTargetCommands(t *testing.T) { args: []string{"tmc", "-h"}, installedPluginTargets: []configtypes.Target{configtypes.TargetK8s}, expected: []string{ - "Tanzu CLI plugins that target a Tanzu Mission Control endpoint", + "Commands that provide functionality for Tanzu Mission Control", + }, + unexpected: []string{ + "Available command groups", + }, + }, + // ======================== + // Tests for the ops target + // ======================== + { + test: "help for ops target run when empty", + args: []string{"ops"}, + expected: []string{ + "Note: No plugins are currently installed for the \"operations\" target", + "Commands that support Kubernetes operations for Tanzu Application Platform", + }, + unexpected: []string{ + "Available command groups", + }, + }, + { + test: "help for ops target help when empty", + args: []string{"ops", "-h"}, + expected: []string{ + "Commands that support Kubernetes operations for Tanzu Application Platform", + }, + unexpected: []string{ + "Available command groups", + }, + }, + { + test: "help for ops target invalid when empty", + args: []string{"ops", "invalid"}, + expected: []string{ + "Note: No plugins are currently installed for the \"operations\" target", + "Commands that support Kubernetes operations for Tanzu Application Platform", + }, + unexpected: []string{ + "Available command groups", + }, + }, + { + test: "help for ops target run when not empty", + args: []string{"ops"}, + installedPluginTargets: []configtypes.Target{configtypes.TargetOperations}, + expected: []string{ + "Commands that support Kubernetes operations for Tanzu Application Platform", + "Available command groups:\n\n System\n dummy dummy \n\nFlags:", + }, + unexpected: []string{ + "Note: No plugins are currently installed", + }, + }, + { + test: "help for ops target help when not empty", + args: []string{"ops", "-h"}, + installedPluginTargets: []configtypes.Target{configtypes.TargetOperations}, + expected: []string{ + "Commands that support Kubernetes operations for Tanzu Application Platform", + "Available command groups:\n\n System\n dummy dummy \n\nFlags:", + }, + unexpected: []string{ + "Note: No plugins are currently installed", + }, + }, + { + test: "help for ops target run when empty but k8s not empty", + args: []string{"ops"}, + installedPluginTargets: []configtypes.Target{configtypes.TargetK8s}, + expected: []string{ + "Commands that support Kubernetes operations for Tanzu Application Platform", + "Note: No plugins are currently installed for the \"operations\" target", + }, + unexpected: []string{ + "Available command groups", + }, + }, + { + test: "help for ops target help when empty but k8s not empty", + args: []string{"ops", "-h"}, + installedPluginTargets: []configtypes.Target{configtypes.TargetK8s}, + expected: []string{ + "Commands that support Kubernetes operations for Tanzu Application Platform", }, unexpected: []string{ "Available command groups", @@ -629,6 +711,12 @@ func TestTargetCommands(t *testing.T) { if helpFlag != nil { _ = helpFlag.Value.Set("false") } + opsCmd.ResetCommands() + opsCmd.Hidden = false + helpFlag = opsCmd.Flags().Lookup("help") + if helpFlag != nil { + _ = helpFlag.Value.Set("false") + } t.Run(spec.test, func(t *testing.T) { assert := assert.New(t) diff --git a/pkg/common/constants.go b/pkg/common/constants.go index 3f564ff57..f4da82461 100644 --- a/pkg/common/constants.go +++ b/pkg/common/constants.go @@ -29,7 +29,7 @@ const ( // Shared strings const ( - TargetList = "kubernetes[k8s]/mission-control[tmc]/global" + TargetList = "kubernetes[k8s]/mission-control[tmc]/operations[ops]/global" ) // CoreName is the name of the core binary. diff --git a/test/e2e/framework/framework_constants.go b/test/e2e/framework/framework_constants.go index 112b35fe6..54ef04f39 100644 --- a/test/e2e/framework/framework_constants.go +++ b/test/e2e/framework/framework_constants.go @@ -11,7 +11,7 @@ import ( const ( CliCore = "[CLI-Core]" - TargetList = "kubernetes[k8s]/mission-control[tmc]/global" + TargetList = "kubernetes[k8s]/mission-control[tmc]/operations[ops]/global" InitCmd = "%s init" VersionCmd = "%s version"