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

Fix the errors happened with reset a component #142

Merged
merged 1 commit into from
Jun 4, 2021
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
24 changes: 18 additions & 6 deletions kubectl-plugin/component/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion kubectl-plugin/types/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package types

const (
// KsVersion is the latest release version
KsVersion = "v3.0.0"
KsVersion = "v3.1.0"
)