diff --git a/kubectl-plugin/component/reset.go b/kubectl-plugin/component/reset.go index f440a25..d8a2933 100644 --- a/kubectl-plugin/component/reset.go +++ b/kubectl-plugin/component/reset.go @@ -19,10 +19,12 @@ func NewComponentResetCmd(client dynamic.Interface) (cmd *cobra.Command) { cmd = &cobra.Command{ Use: "reset", Short: "Reset the component by name", - Example: `'ks com reset -r=false -a' will reset ks-apiserver, ks-controller-manager, ks-console to the latest + Example: `'ks com reset -r=false --nightly latest console' will reset ks-console to the latest release +'ks com reset -r=false -a' will reset ks-apiserver, ks-controller-manager, ks-console to the latest 'ks com reset -a --nightly latest' will reset the images to the latest nightly which comes from yesterday 'ks com reset -a --nightly latest-1' will reset the images to the nightly which comes from the day before yesterday`, - RunE: opt.resetRunE, + PreRunE: opt.preRunE, + RunE: opt.resetRunE, } flags := cmd.Flags() @@ -39,6 +41,13 @@ func NewComponentResetCmd(client dynamic.Interface) (cmd *cobra.Command) { return } +func (o *ResetOption) preRunE(cmd *cobra.Command, args []string) (err error) { + if o.Name == "" && len(args) > 0 { + o.Name = args[0] + } + return +} + func (o *ResetOption) resetRunE(cmd *cobra.Command, args []string) (err error) { if o.Tag == "" { // let users choose it if the tag option is empty @@ -65,11 +74,10 @@ func (o *ResetOption) resetRunE(cmd *cobra.Command, args []string) (err error) { if o.Release && o.Nightly == "" { imageOrg = "kubesphere" } else { - o.Tag = "latest" + // try to parse the nightly date + _, o.Tag = common.GetNightlyTag(o.Nightly) } - // try to parse the nightly date - _, o.Tag = common.GetNightlyTag(o.Nightly) if o.ResetAll { o.Name = "apiserver" if err = o.updateBy(imageOrg, o.Tag); err != nil { @@ -91,7 +99,11 @@ func (o *ResetOption) resetRunE(cmd *cobra.Command, args []string) (err error) { return } } else { - err = o.updateBy(imageOrg, o.Tag) + if o.Name == "" { + err = fmt.Errorf("please provide a component name") + } else { + err = o.updateBy(imageOrg, o.Tag) + } } return } diff --git a/kubectl-plugin/types/constant.go b/kubectl-plugin/types/constant.go index c54e767..0e47db8 100644 --- a/kubectl-plugin/types/constant.go +++ b/kubectl-plugin/types/constant.go @@ -2,5 +2,5 @@ package types const ( // KsVersion is the latest release version - KsVersion = "v3.0.0" + KsVersion = "v3.1.0" )