Skip to content

Commit

Permalink
Feature/dm destroy support --force --retaion-node-data --retaion-role…
Browse files Browse the repository at this point in the history
…-data (pingcap#1080)

* typo(cluster/command): destoyOpt -> destroyOpt

* feat(dm/command): destory --force --retain-node-data,--retain-role-data
  • Loading branch information
jsvisa authored and 余国聪 committed Jan 21, 2021
1 parent 9cddaeb commit b9f6773
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
14 changes: 7 additions & 7 deletions components/cluster/command/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func newDestroyCmd() *cobra.Command {
destoyOpt := operator.Options{}
destroyOpt := operator.Options{}
cmd := &cobra.Command{
Use: "destroy <cluster-name>",
Short: "Destroy a specified cluster",
Expand All @@ -41,22 +41,22 @@ You can retain some nodes and roles data when destroy cluster, eg:
teleCommand = append(teleCommand, scrubClusterName(clusterName))

// Validate the retained roles to prevent unexpected deleting data
if len(destoyOpt.RetainDataRoles) > 0 {
if len(destroyOpt.RetainDataRoles) > 0 {
validRoles := set.NewStringSet(spec.AllComponentNames()...)
for _, role := range destoyOpt.RetainDataRoles {
for _, role := range destroyOpt.RetainDataRoles {
if !validRoles.Exist(role) {
return perrs.Errorf("role name `%s` invalid", role)
}
}
}

return cm.DestroyCluster(clusterName, gOpt, destoyOpt, skipConfirm)
return cm.DestroyCluster(clusterName, gOpt, destroyOpt, skipConfirm)
},
}

cmd.Flags().StringArrayVar(&destoyOpt.RetainDataNodes, "retain-node-data", nil, "Specify the nodes or hosts whose data will be retained")
cmd.Flags().StringArrayVar(&destoyOpt.RetainDataRoles, "retain-role-data", nil, "Specify the roles whose data will be retained")
cmd.Flags().BoolVar(&destoyOpt.Force, "force", false, "Force will ignore remote error while destroy the cluster")
cmd.Flags().StringArrayVar(&destroyOpt.RetainDataNodes, "retain-node-data", nil, "Specify the nodes or hosts whose data will be retained")
cmd.Flags().StringArrayVar(&destroyOpt.RetainDataRoles, "retain-role-data", nil, "Specify the roles whose data will be retained")
cmd.Flags().BoolVar(&destroyOpt.Force, "force", false, "Force will ignore remote error while destroy the cluster")

return cmd
}
21 changes: 19 additions & 2 deletions components/dm/command/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
package command

import (
perrs "github.com/pingcap/errors"
"github.com/pingcap/tiup/components/dm/spec"
operator "github.com/pingcap/tiup/pkg/cluster/operation"
"github.com/pingcap/tiup/pkg/set"
"github.com/spf13/cobra"
)

// TODO support retain data like cluster?
func newDestroyCmd() *cobra.Command {
destroyOpt := operator.Options{}
cmd := &cobra.Command{
Use: "destroy <cluster-name>",
Short: "Destroy a specified DM cluster",
Expand All @@ -30,9 +33,23 @@ func newDestroyCmd() *cobra.Command {

clusterName := args[0]

return cm.DestroyCluster(clusterName, gOpt, operator.Options{}, skipConfirm)
// Validate the retained roles to prevent unexpected deleting data
if len(destroyOpt.RetainDataRoles) > 0 {
validRoles := set.NewStringSet(spec.AllDMComponentNames()...)
for _, role := range destroyOpt.RetainDataRoles {
if !validRoles.Exist(role) {
return perrs.Errorf("role name `%s` invalid", role)
}
}
}

return cm.DestroyCluster(clusterName, gOpt, destroyOpt, skipConfirm)
},
}

cmd.Flags().StringArrayVar(&destroyOpt.RetainDataNodes, "retain-node-data", nil, "Specify the nodes or hosts whose data will be retained")
cmd.Flags().StringArrayVar(&destroyOpt.RetainDataRoles, "retain-role-data", nil, "Specify the roles whose data will be retained")
cmd.Flags().BoolVar(&destroyOpt.Force, "force", false, "Force will ignore remote error while destroy the cluster")

return cmd
}

0 comments on commit b9f6773

Please sign in to comment.