From cbeecbf039c69043519d5d141af2f589420ed705 Mon Sep 17 00:00:00 2001 From: Songlu Tsai <111858489+nayutah@users.noreply.github.com> Date: Thu, 25 Jul 2024 21:08:30 +0800 Subject: [PATCH] [Improvement] enable addons in batch (#415) Co-authored-by: nayutah (cherry picked from commit d9d5d146583c7d538a7de42511e7b18ed208c197) --- docs/user_docs/cli/kbcli_addon_disable.md | 10 +++++++++ docs/user_docs/cli/kbcli_addon_enable.md | 3 +++ pkg/cmd/addon/addon.go | 26 +++++++++++++++++------ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/docs/user_docs/cli/kbcli_addon_disable.md b/docs/user_docs/cli/kbcli_addon_disable.md index db332cfad..d90978e1b 100644 --- a/docs/user_docs/cli/kbcli_addon_disable.md +++ b/docs/user_docs/cli/kbcli_addon_disable.md @@ -8,6 +8,16 @@ Disable an addon. kbcli addon disable ADDON_NAME [flags] ``` +### Examples + +``` + # Disable "prometheus" addon + kbcli addon disable prometheus + + # Disable addons in batch + kbcli addon disable prometheus csi-s3 +``` + ### Options ``` diff --git a/docs/user_docs/cli/kbcli_addon_enable.md b/docs/user_docs/cli/kbcli_addon_enable.md index 50ffebf60..3bfcae272 100644 --- a/docs/user_docs/cli/kbcli_addon_enable.md +++ b/docs/user_docs/cli/kbcli_addon_enable.md @@ -31,6 +31,9 @@ kbcli addon enable ADDON_NAME [flags] # Force enabled "csi-s3" addon kbcli addon enable csi-s3 --force + + # Enable addons in batch + kbcli addon enable prometheus csi-s3 ``` ### Options diff --git a/pkg/cmd/addon/addon.go b/pkg/cmd/addon/addon.go index a27d8c4ca..7f80a1ec6 100644 --- a/pkg/cmd/addon/addon.go +++ b/pkg/cmd/addon/addon.go @@ -189,7 +189,7 @@ func newEnableCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra. cmd := &cobra.Command{ Use: "enable ADDON_NAME", Short: "Enable an addon.", - Args: cobra.ExactArgs(1), + Args: cobra.MinimumNArgs(1), ValidArgsFunction: util.ResourceNameCompletionFunc(f, types.AddonGVR()), Example: templates.Examples(` # Enabled "prometheus" addon @@ -212,14 +212,19 @@ func newEnableCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra. # Force enabled "csi-s3" addon kbcli addon enable csi-s3 --force + + # Enable addons in batch + kbcli addon enable prometheus csi-s3 `), Run: func(cmd *cobra.Command, args []string) { - util.CheckErr(o.init(args)) - util.CheckErr(o.fetchAddonObj()) - util.CheckErr(o.validate()) - util.CheckErr(o.complete(o, cmd, args)) - util.CheckErr(o.CmdComplete(cmd)) - util.CheckErr(o.Run()) + for _, name := range args { // This loop will fetch all the addons mentioned in the command and will install them one by one. + util.CheckErr(o.init([]string{name})) + util.CheckErr(o.fetchAddonObj()) + util.CheckErr(o.validate()) + util.CheckErr(o.complete(o, cmd, []string{name})) + util.CheckErr(o.CmdComplete(cmd)) + util.CheckErr(o.Run()) + } }, } cmd.Flags().StringArrayVar(&o.addonEnableFlags.MemorySets, "memory", []string{}, @@ -268,6 +273,13 @@ func newDisableCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra Short: "Disable an addon.", Args: cobra.ExactArgs(1), ValidArgsFunction: util.ResourceNameCompletionFunc(f, types.AddonGVR()), + Example: templates.Examples(` + # Disable "prometheus" addon + kbcli addon disable prometheus + + # Disable addons in batch + kbcli addon disable prometheus csi-s3 +`), Run: func(cmd *cobra.Command, args []string) { util.CheckErr(o.init(args)) util.CheckErr(o.fetchAddonObj())