github.com/pingcap/tiup@v1.15.1/components/cluster/command/upgrade.go (about) 1 // Copyright 2020 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package command 15 16 import ( 17 "github.com/pingcap/tiup/pkg/cluster/spec" 18 "github.com/pingcap/tiup/pkg/utils" 19 "github.com/spf13/cobra" 20 ) 21 22 func newUpgradeCmd() *cobra.Command { 23 offlineMode := false 24 ignoreVersionCheck := false 25 var tidbVer, tikvVer, pdVer, tiflashVer, kvcdcVer, dashboardVer, cdcVer, alertmanagerVer, nodeExporterVer, blackboxExporterVer, tiproxyVer string 26 27 cmd := &cobra.Command{ 28 Use: "upgrade <cluster-name> <version>", 29 Short: "Upgrade a specified TiDB cluster", 30 RunE: func(cmd *cobra.Command, args []string) error { 31 if len(args) != 2 { 32 return cmd.Help() 33 } 34 35 clusterName := args[0] 36 version, err := utils.FmtVer(args[1]) 37 if err != nil { 38 return err 39 } 40 clusterReport.ID = scrubClusterName(clusterName) 41 teleCommand = append(teleCommand, scrubClusterName(clusterName)) 42 teleCommand = append(teleCommand, version) 43 44 componentVersions := map[string]string{ 45 spec.ComponentDashboard: dashboardVer, 46 spec.ComponentAlertmanager: alertmanagerVer, 47 spec.ComponentTiDB: tidbVer, 48 spec.ComponentTiKV: tikvVer, 49 spec.ComponentPD: pdVer, 50 spec.ComponentTiFlash: tiflashVer, 51 spec.ComponentTiKVCDC: kvcdcVer, 52 spec.ComponentCDC: cdcVer, 53 spec.ComponentTiProxy: tiproxyVer, 54 spec.ComponentBlackboxExporter: blackboxExporterVer, 55 spec.ComponentNodeExporter: nodeExporterVer, 56 } 57 58 return cm.Upgrade(clusterName, version, componentVersions, gOpt, skipConfirm, offlineMode, ignoreVersionCheck) 59 }, 60 ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { 61 switch len(args) { 62 case 0: 63 return shellCompGetClusterName(cm, toComplete) 64 default: 65 return nil, cobra.ShellCompDirectiveNoFileComp 66 } 67 }, 68 } 69 cmd.Flags().BoolVar(&gOpt.Force, "force", false, "Force upgrade without transferring PD leader") 70 cmd.Flags().Uint64Var(&gOpt.APITimeout, "transfer-timeout", 600, "Timeout in seconds when transferring PD and TiKV store leaders, also for TiCDC drain one capture") 71 cmd.Flags().BoolVarP(&gOpt.IgnoreConfigCheck, "ignore-config-check", "", false, "Ignore the config check result") 72 cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Upgrade a stopped cluster") 73 cmd.Flags().BoolVarP(&ignoreVersionCheck, "ignore-version-check", "", false, "Ignore checking if target version is bigger than current version") 74 cmd.Flags().StringVar(&gOpt.SSHCustomScripts.BeforeRestartInstance.Raw, "pre-upgrade-script", "", "(EXPERIMENTAL) Custom script to be executed on each server before the server is upgraded") 75 cmd.Flags().StringVar(&gOpt.SSHCustomScripts.AfterRestartInstance.Raw, "post-upgrade-script", "", "(EXPERIMENTAL) Custom script to be executed on each server after the server is upgraded") 76 77 // cmd.Flags().StringVar(&tidbVer, "tidb-version", "", "Fix the version of tidb and no longer follows the cluster version.") 78 cmd.Flags().StringVar(&tikvVer, "tikv-version", "", "Fix the version of tikv and no longer follows the cluster version.") 79 cmd.Flags().StringVar(&pdVer, "pd-version", "", "Fix the version of pv and no longer follows the cluster version.") 80 cmd.Flags().StringVar(&tiflashVer, "tiflash-version", "", "Fix the version of tiflash and no longer follows the cluster version.") 81 cmd.Flags().StringVar(&dashboardVer, "tidb-dashboard-version", "", "Fix the version of tidb-dashboard and no longer follows the cluster version.") 82 cmd.Flags().StringVar(&cdcVer, "cdc-version", "", "Fix the version of cdc and no longer follows the cluster version.") 83 cmd.Flags().StringVar(&kvcdcVer, "tikv-cdc-version", "", "Fix the version of tikv-cdc and no longer follows the cluster version.") 84 cmd.Flags().StringVar(&alertmanagerVer, "alertmanager-version", "", "Fix the version of alertmanager and no longer follows the cluster version.") 85 cmd.Flags().StringVar(&nodeExporterVer, "node-exporter-version", "", "Fix the version of node-exporter and no longer follows the cluster version.") 86 cmd.Flags().StringVar(&blackboxExporterVer, "blackbox-exporter-version", "", "Fix the version of blackbox-exporter and no longer follows the cluster version.") 87 cmd.Flags().StringVar(&tiproxyVer, "tiproxy-version", "", "Fix the version of tiproxy and no longer follows the cluster version.") 88 return cmd 89 }