Skip to content

Commit

Permalink
chore: move init addon repo in index cmd (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengluodb authored Nov 20, 2023
1 parent 91bbbd4 commit a623b61
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 3 additions & 1 deletion docs/user_docs/cli/kbcli_plugin_index_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ kbcli plugin index add [flags]

```
# Add a new plugin index
kbcli plugin index add myIndex
kbcli plugin index add default https://github.com/apecloud/block-index.git
kbcli plugin index add krew https://github.com/kubernetes-sigs/krew-index.git
```

### Options
Expand Down
16 changes: 10 additions & 6 deletions pkg/cmd/addon/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ func newIndexAddCmd() *cobra.Command {
Long: "Configure a new index to install KubeBlocks addon from.",
Example: "kbcli addon index add kubeblocks " + types.DefaultAddonIndexURL,
Args: cobra.ExactArgs(2),
PersistentPreRun: func(_ *cobra.Command, _ []string) {
util.CheckErr(addDefaultIndex())
},
Run: func(_ *cobra.Command, args []string) {
util.CheckErr(addIndex(args))
},
Expand Down Expand Up @@ -95,6 +92,9 @@ func newIndexCmd(streams genericiooptions.IOStreams) *cobra.Command {
Short: "Manage custom addon indexes",
Long: "Manage which repositories are used to discover and install addon from.",
Args: cobra.NoArgs,
PersistentPreRun: func(_ *cobra.Command, _ []string) {
util.CheckErr(addDefaultIndex())
},
}
indexCmd.AddCommand(
newIndexAddCmd(),
Expand Down Expand Up @@ -211,7 +211,7 @@ func addIndex(args []string) error {
} else if err != nil {
return err
}
return errors.New("index already exists")
return fmt.Errorf("index %s:%s already exists", name, url)
}

func listIndexes(out io.Writer) error {
Expand Down Expand Up @@ -261,15 +261,19 @@ func addDefaultIndex() error {
return fmt.Errorf("can't get the index dir : %s", err.Error())
}

// check if the default index is already added
defaultIndexDir := path.Join(addonDir, types.KubeBlocksReleaseName)
if _, err := os.Stat(defaultIndexDir); err != nil && os.IsNotExist(err) {
if _, err := os.Stat(defaultIndexDir); os.IsNotExist(err) {
if err = util.EnsureCloned(types.DefaultAddonIndexURL, defaultIndexDir); err != nil {
return err
}
fmt.Printf("Default addon index \"kubeblocks\" has been added.")
return nil
} else if err != nil {
return err
}
return fmt.Errorf("default index %s:%s already exists", types.KubeBlocksReleaseName, types.DefaultAddonIndexURL)

return nil
}

func getAllIndexes() ([]index, error) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/plugin/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ var (

pluginAddIndexExample = templates.Examples(`
# Add a new plugin index
kbcli plugin index add myIndex
kbcli plugin index add default https://github.com/apecloud/block-index.git
kbcli plugin index add krew https://github.com/kubernetes-sigs/krew-index.git
`)

pluginDeleteIndexExample = templates.Examples(`
Expand Down

0 comments on commit a623b61

Please sign in to comment.