Skip to content

Commit

Permalink
feat: addon install require to specify the version (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldming authored Oct 10, 2024
1 parent 4aaad5e commit 65f8876
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/user_docs/cli/kbcli_addon_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ kbcli addon install [flags]
-h, --help help for install
--index string specify the addon index, use 'kubeblocks' by default (default "kubeblocks")
--path string specify the local path contains addon CRs and needs to be specified when operating offline
--version string specify the addon version
--version string specify the addon version to install, run 'kbcli addon search <addon-name>' to get the available versions
```

### Options inherited from parent commands
Expand Down
22 changes: 11 additions & 11 deletions pkg/cmd/addon/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ func newInstallCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra
},
}
cmd.Flags().BoolVar(&o.force, "force", false, "force install the addon and ignore the version check")
cmd.Flags().StringVar(&o.version, "version", "", "specify the addon version")
cmd.Flags().StringVar(&o.version, "version", "", "specify the addon version to install, run 'kbcli addon search <addon-name>' to get the available versions")
cmd.Flags().StringVar(&o.index, "index", types.DefaultIndexName, "specify the addon index, use 'kubeblocks' by default")
cmd.Flags().StringVar(&o.clusterChartVersion, "cluster-chart-version", "", "specify the cluster chart version, use the same version as the addon by default")
cmd.Flags().StringVar(&o.clusterChartRepo, "cluster-chart-repo", types.ClusterChartsRepoURL, "specify the repo of cluster chart, use the url of 'kubeblocks-addons' by default")
cmd.Flags().StringVar(&o.path, "path", "", "specify the local path contains addon CRs and needs to be specified when operating offline")

_ = cmd.MarkFlagRequired("version")

return cmd
}

Expand All @@ -163,6 +165,11 @@ func (o *installOption) Complete() error {
if err = o.baseOption.complete(); err != nil {
return err
}

if o.version == "" {
return fmt.Errorf("please specify the version, run 'kbcli addon search %s' to get the available versions", o.name)
}

// search specified addon and match its index
if _, err = semver.NewVersion(o.version); err != nil && o.version != "" {
return fmt.Errorf("the version %s does not comply with the standards", o.version)
Expand Down Expand Up @@ -196,12 +203,7 @@ func (o *installOption) Complete() error {
// descending order of versions
for _, item := range addons {
if o.path != "" || item.index.name == o.index {
// if the version not specified, use the latest version
if o.version == "" {
o.addon = item.addon
o.version = getAddonVersion(item.addon)
break
} else if o.version == getAddonVersion(item.addon) {
if o.version == getAddonVersion(item.addon) {
o.addon = item.addon
break
}
Expand All @@ -215,9 +217,7 @@ func (o *installOption) Complete() error {

if o.addon == nil {
var addonInfo = o.name
if o.version != "" {
addonInfo += "-" + o.version
}
addonInfo += "-" + o.version
return fmt.Errorf("addon '%s' not found in the index '%s'", addonInfo, o.index)
}
return nil
Expand Down Expand Up @@ -271,7 +271,7 @@ func (o *installOption) Run(f cmdutil.Factory, streams genericiooptions.IOStream
// 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.
// https://semver.org/
func validateVersion(annotations, kbVersion string) (bool, error) {
// if kb version is a prerelease version, we will break the rules for developing
// if kb version is a pre-release version, we will break the rules for developing
if strings.Contains(kbVersion, "-") {
addPreReleaseInfo := func(constrain string) string {
constrain = strings.Trim(constrain, " ")
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/addon/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var _ = Describe("test addon upgrade", func() {
tf.FakeDynamicClient = testing.FakeDynamicClient(testing.FakeAddon("apecloud-mysql"))
option = newUpgradeOption(tf, streams)
option.name = "apecloud-mysql"
option.version = "0.7.0"
Expect(option.Complete()).Should(Succeed())
})

Expand Down
3 changes: 2 additions & 1 deletion pkg/util/breakingchange/upgradehandlerto0.7.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import (
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/client-go/dynamic"

"github.com/apecloud/kbcli/pkg/types"
dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
"github.com/apecloud/kubeblocks/pkg/constant"

"github.com/apecloud/kbcli/pkg/types"
)

var _ upgradeHandler = &upgradeHandlerTo7{}
Expand Down

0 comments on commit 65f8876

Please sign in to comment.