github.com/pingcap/tiup@v1.15.1/components/cluster/command/scale_in.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 "crypto/tls" 18 19 operator "github.com/pingcap/tiup/pkg/cluster/operation" 20 "github.com/pingcap/tiup/pkg/cluster/spec" 21 "github.com/pingcap/tiup/pkg/cluster/task" 22 "github.com/spf13/cobra" 23 ) 24 25 func newScaleInCmd() *cobra.Command { 26 cmd := &cobra.Command{ 27 Use: "scale-in <cluster-name>", 28 Short: "Scale in a TiDB cluster", 29 RunE: func(cmd *cobra.Command, args []string) error { 30 if len(args) != 1 { 31 return cmd.Help() 32 } 33 34 clusterName := args[0] 35 clusterReport.ID = scrubClusterName(clusterName) 36 teleCommand = append(teleCommand, scrubClusterName(clusterName)) 37 38 scale := func(b *task.Builder, imetadata spec.Metadata, tlsCfg *tls.Config) { 39 metadata := imetadata.(*spec.ClusterMeta) 40 41 nodes := gOpt.Nodes 42 if !gOpt.Force { 43 nodes = operator.AsyncNodes(metadata.Topology, nodes, false) 44 } 45 46 b.ClusterOperate(metadata.Topology, operator.ScaleInOperation, gOpt, tlsCfg). 47 UpdateMeta(clusterName, metadata, nodes). 48 UpdateTopology(clusterName, tidbSpec.Path(clusterName), metadata, nodes) 49 } 50 51 return cm.ScaleIn(clusterName, skipConfirm, gOpt, scale) 52 }, 53 ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { 54 switch len(args) { 55 case 0: 56 return shellCompGetClusterName(cm, toComplete) 57 default: 58 return nil, cobra.ShellCompDirectiveNoFileComp 59 } 60 }, 61 } 62 63 cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Specify the nodes (required)") 64 cmd.Flags().Uint64Var(&gOpt.APITimeout, "transfer-timeout", 600, "Timeout in seconds when transferring PD and TiKV store leaders, also for TiCDC drain one capture") 65 cmd.Flags().BoolVar(&gOpt.Force, "force", false, "Force just try stop and destroy instance before removing the instance from topo") 66 67 _ = cmd.MarkFlagRequired("node") 68 69 return cmd 70 }