Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move init addon repo in index cmd #57

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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