github.com/pingcap/tiup@v1.15.1/components/cluster/command/patch.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 perrs "github.com/pingcap/errors" 18 "github.com/spf13/cobra" 19 ) 20 21 func newPatchCmd() *cobra.Command { 22 var ( 23 overwrite bool 24 offlineMode bool 25 ) 26 cmd := &cobra.Command{ 27 Use: "patch <cluster-name> <package-path>", 28 Short: "Replace the remote package with a specified package and restart the service", 29 RunE: func(cmd *cobra.Command, args []string) error { 30 if len(args) != 2 { 31 return cmd.Help() 32 } 33 34 if err := validRoles(gOpt.Roles); err != nil { 35 return err 36 } 37 38 if len(gOpt.Nodes) == 0 && len(gOpt.Roles) == 0 { 39 return perrs.New("the flag -R or -N must be specified at least one") 40 } 41 clusterName := args[0] 42 clusterReport.ID = scrubClusterName(clusterName) 43 teleCommand = append(teleCommand, scrubClusterName(clusterName)) 44 45 return cm.Patch(clusterName, args[1], gOpt, overwrite, offlineMode, skipConfirm) 46 }, 47 } 48 49 cmd.Flags().BoolVar(&overwrite, "overwrite", false, "Use this package in the future scale-out operations") 50 cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Specify the nodes") 51 cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Specify the roles") 52 cmd.Flags().Uint64Var(&gOpt.APITimeout, "transfer-timeout", 600, "Timeout in seconds when transferring PD and TiKV store leaders, also for TiCDC drain one capture") 53 cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Patch a stopped cluster") 54 return cmd 55 }