diff --git a/components/cluster/command/upgrade.go b/components/cluster/command/upgrade.go index 2afe973a07..6ee3941e65 100644 --- a/components/cluster/command/upgrade.go +++ b/components/cluster/command/upgrade.go @@ -20,6 +20,7 @@ import ( func newUpgradeCmd() *cobra.Command { offlineMode := false + ignoreVersionCheck := false cmd := &cobra.Command{ Use: "upgrade ", @@ -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) { @@ -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") diff --git a/components/dm/command/upgrade.go b/components/dm/command/upgrade.go index bb6abf0ac7..fda3185089 100644 --- a/components/dm/command/upgrade.go +++ b/components/dm/command/upgrade.go @@ -19,7 +19,7 @@ import ( func newUpgradeCmd() *cobra.Command { offlineMode := false - + ignoreVersionCheck := false cmd := &cobra.Command{ Use: "upgrade ", Short: "Upgrade a specified DM cluster", @@ -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) { @@ -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 } diff --git a/pkg/cluster/manager/upgrade.go b/pkg/cluster/manager/upgrade.go index cf28dbadb0..06a668b999 100644 --- a/pkg/cluster/manager/upgrade.go +++ b/pkg/cluster/manager/upgrade.go @@ -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 } @@ -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 {