diff --git a/components/cluster/command/patch.go b/components/cluster/command/patch.go index bfca649980..0fda5b7bfe 100644 --- a/components/cluster/command/patch.go +++ b/components/cluster/command/patch.go @@ -20,7 +20,8 @@ import ( func newPatchCmd() *cobra.Command { var ( - overwrite bool + overwrite bool + offlineMode bool ) cmd := &cobra.Command{ Use: "patch ", @@ -40,7 +41,7 @@ func newPatchCmd() *cobra.Command { clusterName := args[0] teleCommand = append(teleCommand, scrubClusterName(clusterName)) - return cm.Patch(clusterName, args[1], gOpt, overwrite) + return cm.Patch(clusterName, args[1], gOpt, overwrite, offlineMode) }, } @@ -48,5 +49,6 @@ func newPatchCmd() *cobra.Command { cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Specify the nodes") cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Specify the roles") cmd.Flags().Uint64Var(&gOpt.APITimeout, "transfer-timeout", 300, "Timeout in seconds when transferring PD and TiKV store leaders") + cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Patch a stopped cluster") return cmd } diff --git a/components/cluster/command/upgrade.go b/components/cluster/command/upgrade.go index 5974537241..afc5cf1d83 100644 --- a/components/cluster/command/upgrade.go +++ b/components/cluster/command/upgrade.go @@ -19,6 +19,8 @@ import ( ) func newUpgradeCmd() *cobra.Command { + offlineMode := false + cmd := &cobra.Command{ Use: "upgrade ", Short: "Upgrade a specified TiDB cluster", @@ -35,12 +37,13 @@ func newUpgradeCmd() *cobra.Command { teleCommand = append(teleCommand, scrubClusterName(clusterName)) teleCommand = append(teleCommand, version) - return cm.Upgrade(clusterName, version, gOpt, skipConfirm) + return cm.Upgrade(clusterName, version, gOpt, skipConfirm, offlineMode) }, } cmd.Flags().BoolVar(&gOpt.Force, "force", false, "Force upgrade without transferring PD leader") cmd.Flags().Uint64Var(&gOpt.APITimeout, "transfer-timeout", 300, "Timeout in seconds when transferring PD and TiKV store leaders") cmd.Flags().BoolVarP(&gOpt.IgnoreConfigCheck, "ignore-config-check", "", false, "Ignore the config check result") + cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Upgrade a stopped cluster") return cmd } diff --git a/components/dm/command/patch.go b/components/dm/command/patch.go index f212653859..e45ef2bf21 100644 --- a/components/dm/command/patch.go +++ b/components/dm/command/patch.go @@ -20,7 +20,8 @@ import ( func newPatchCmd() *cobra.Command { var ( - overwrite bool + overwrite bool + offlineMode bool ) cmd := &cobra.Command{ Use: "patch ", @@ -40,12 +41,13 @@ func newPatchCmd() *cobra.Command { clusterName := args[0] - return cm.Patch(clusterName, args[1], gOpt, overwrite) + return cm.Patch(clusterName, args[1], gOpt, overwrite, offlineMode) }, } cmd.Flags().BoolVar(&overwrite, "overwrite", false, "Use this package in the future scale-out operations") cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Specify the nodes") cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Specify the roles") + cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Patch a stopped cluster") return cmd } diff --git a/components/dm/command/upgrade.go b/components/dm/command/upgrade.go index f83006c4b4..9b57b8ca2c 100644 --- a/components/dm/command/upgrade.go +++ b/components/dm/command/upgrade.go @@ -18,6 +18,8 @@ import ( ) func newUpgradeCmd() *cobra.Command { + offlineMode := false + cmd := &cobra.Command{ Use: "upgrade ", Short: "Upgrade a specified DM cluster", @@ -26,9 +28,11 @@ func newUpgradeCmd() *cobra.Command { return cmd.Help() } - return cm.Upgrade(args[0], args[1], gOpt, skipConfirm) + return cm.Upgrade(args[0], args[1], gOpt, skipConfirm, offlineMode) }, } + cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Upgrade a stopped cluster") + return cmd } diff --git a/pkg/cluster/manager/patch.go b/pkg/cluster/manager/patch.go index 6b28f727d1..7e5ee63158 100644 --- a/pkg/cluster/manager/patch.go +++ b/pkg/cluster/manager/patch.go @@ -33,7 +33,7 @@ import ( ) // Patch the cluster. -func (m *Manager) Patch(name string, packagePath string, opt operator.Options, overwrite bool) error { +func (m *Manager) Patch(name string, packagePath string, opt operator.Options, overwrite, offline bool) error { metadata, err := m.meta(name) if err != nil { return err @@ -70,6 +70,9 @@ func (m *Manager) Patch(name string, packagePath string, opt operator.Options, o t := m.sshTaskBuilder(name, topo, base.User, opt). Parallel(false, replacePackageTasks...). Func("UpgradeCluster", func(ctx context.Context) error { + if offline { + return nil + } return operator.Upgrade(ctx, topo, opt, tlsCfg) }). Build() diff --git a/pkg/cluster/manager/upgrade.go b/pkg/cluster/manager/upgrade.go index 0c6c0668b7..d3f6eb1e1c 100644 --- a/pkg/cluster/manager/upgrade.go +++ b/pkg/cluster/manager/upgrade.go @@ -34,7 +34,7 @@ import ( ) // Upgrade the cluster. -func (m *Manager) Upgrade(name string, clusterVersion string, opt operator.Options, skipConfirm bool) error { +func (m *Manager) Upgrade(name string, clusterVersion string, opt operator.Options, skipConfirm, offline bool) error { metadata, err := m.meta(name) if err != nil { return err @@ -167,6 +167,9 @@ func (m *Manager) Upgrade(name string, clusterVersion string, opt operator.Optio Parallel(false, downloadCompTasks...). Parallel(opt.Force, copyCompTasks...). Func("UpgradeCluster", func(ctx context.Context) error { + if offline { + return nil + } return operator.Upgrade(ctx, topo, opt, tlsCfg) }). Build() diff --git a/tests/tiup-cluster/script/cmd_subtest.sh b/tests/tiup-cluster/script/cmd_subtest.sh index 6c248a9c2a..17c449aeab 100755 --- a/tests/tiup-cluster/script/cmd_subtest.sh +++ b/tests/tiup-cluster/script/cmd_subtest.sh @@ -56,6 +56,9 @@ function cmd_subtest() { tiup-cluster $client --yes start $name + # Patch a stopped cluster + tiup-cluster $client --yes patch $name ~/.tiup/storage/cluster/packages/tidb-v$version-linux-amd64.tar.gz -R tidb --offline + tiup-cluster $client _test $name writable # check the data dir of tikv