Skip to content

Commit

Permalink
cluster/dm: support ignore version check when upgrade (#2282)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar authored Sep 25, 2023
1 parent 456f37a commit f3b0806
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion components/cluster/command/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

func newUpgradeCmd() *cobra.Command {
offlineMode := false
ignoreVersionCheck := false

cmd := &cobra.Command{
Use: "upgrade <cluster-name> <version>",
Expand All @@ -38,7 +39,7 @@ func newUpgradeCmd() *cobra.Command {
teleCommand = append(teleCommand, scrubClusterName(clusterName))
teleCommand = append(teleCommand, version)

return cm.Upgrade(clusterName, version, gOpt, skipConfirm, offlineMode)
return cm.Upgrade(clusterName, version, gOpt, skipConfirm, offlineMode, ignoreVersionCheck)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
switch len(args) {
Expand All @@ -53,6 +54,7 @@ func newUpgradeCmd() *cobra.Command {
cmd.Flags().Uint64Var(&gOpt.APITimeout, "transfer-timeout", 600, "Timeout in seconds when transferring PD and TiKV store leaders, also for TiCDC drain one capture")
cmd.Flags().BoolVarP(&gOpt.IgnoreConfigCheck, "ignore-config-check", "", false, "Ignore the config check result")
cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Upgrade a stopped cluster")
cmd.Flags().BoolVarP(&ignoreVersionCheck, "ignore-version-check", "", false, "Ignore checking if target version is bigger than current version")
cmd.Flags().StringVar(&gOpt.SSHCustomScripts.BeforeRestartInstance.Raw, "pre-upgrade-script", "", "(EXPERIMENTAL) Custom script to be executed on each server before the server is upgraded")
cmd.Flags().StringVar(&gOpt.SSHCustomScripts.AfterRestartInstance.Raw, "post-upgrade-script", "", "(EXPERIMENTAL) Custom script to be executed on each server after the server is upgraded")

Expand Down
5 changes: 3 additions & 2 deletions components/dm/command/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

func newUpgradeCmd() *cobra.Command {
offlineMode := false

ignoreVersionCheck := false
cmd := &cobra.Command{
Use: "upgrade <cluster-name> <version>",
Short: "Upgrade a specified DM cluster",
Expand All @@ -28,7 +28,7 @@ func newUpgradeCmd() *cobra.Command {
return cmd.Help()
}

return cm.Upgrade(args[0], args[1], gOpt, skipConfirm, offlineMode)
return cm.Upgrade(args[0], args[1], gOpt, skipConfirm, offlineMode, ignoreVersionCheck)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
switch len(args) {
Expand All @@ -41,6 +41,7 @@ func newUpgradeCmd() *cobra.Command {
}

cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Upgrade a stopped cluster")
cmd.Flags().BoolVarP(&ignoreVersionCheck, "ignore-version-check", "", false, "Ignore checking if target version is higher than current version")

return cmd
}
7 changes: 5 additions & 2 deletions pkg/cluster/manager/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
)

// Upgrade the cluster.
func (m *Manager) Upgrade(name string, clusterVersion string, opt operator.Options, skipConfirm, offline bool) error {
func (m *Manager) Upgrade(name string, clusterVersion string, opt operator.Options, skipConfirm, offline, ignoreVersionCheck bool) error {
if err := clusterutil.ValidateClusterNameOrError(name); err != nil {
return err
}
Expand Down Expand Up @@ -68,7 +68,10 @@ func (m *Manager) Upgrade(name string, clusterVersion string, opt operator.Optio
)

if err := versionCompare(base.Version, clusterVersion); err != nil {
return err
if !ignoreVersionCheck {
return err
}
m.logger.Warnf(color.RedString("There is no guarantee that the cluster can be downgraded. Be careful before you continue."))
}

if !skipConfirm {
Expand Down

0 comments on commit f3b0806

Please sign in to comment.