From b9f67733dbf4e318c158e67bf1109f0ce58eef67 Mon Sep 17 00:00:00 2001 From: 9547 Date: Wed, 20 Jan 2021 12:47:53 +0800 Subject: [PATCH] Feature/dm destroy support --force --retaion-node-data --retaion-role-data (#1080) * typo(cluster/command): destoyOpt -> destroyOpt * feat(dm/command): destory --force --retain-node-data,--retain-role-data --- components/cluster/command/destroy.go | 14 +++++++------- components/dm/command/destroy.go | 21 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/components/cluster/command/destroy.go b/components/cluster/command/destroy.go index 4c81c36027..2201906ead 100644 --- a/components/cluster/command/destroy.go +++ b/components/cluster/command/destroy.go @@ -22,7 +22,7 @@ import ( ) func newDestroyCmd() *cobra.Command { - destoyOpt := operator.Options{} + destroyOpt := operator.Options{} cmd := &cobra.Command{ Use: "destroy ", Short: "Destroy a specified cluster", @@ -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 } diff --git a/components/dm/command/destroy.go b/components/dm/command/destroy.go index 8d29c31082..9f0cfd9a80 100644 --- a/components/dm/command/destroy.go +++ b/components/dm/command/destroy.go @@ -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 ", Short: "Destroy a specified DM cluster", @@ -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 }