Skip to content

Commit

Permalink
[Improvement] enable addons in batch (#415)
Browse files Browse the repository at this point in the history
Co-authored-by: nayutah <[email protected]>
(cherry picked from commit d9d5d14)
  • Loading branch information
nayutah authored and 1aal committed Jul 25, 2024
1 parent db7748a commit cbeecbf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
10 changes: 10 additions & 0 deletions docs/user_docs/cli/kbcli_addon_disable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
3 changes: 3 additions & 0 deletions docs/user_docs/cli/kbcli_addon_enable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 19 additions & 7 deletions pkg/cmd/addon/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{},
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit cbeecbf

Please sign in to comment.