Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support delete -f #1824

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions cmd/sealer/cmd/cluster/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"net"
"path/filepath"

"github.com/sealerio/sealer/utils"

"github.com/sealerio/sealer/cmd/sealer/cmd/types"
cmdutils "github.com/sealerio/sealer/cmd/sealer/cmd/utils"
"github.com/sealerio/sealer/common"
Expand All @@ -31,6 +29,7 @@ import (
"github.com/sealerio/sealer/pkg/imagedistributor"
"github.com/sealerio/sealer/pkg/imageengine"
"github.com/sealerio/sealer/pkg/infradriver"
"github.com/sealerio/sealer/utils"
netutils "github.com/sealerio/sealer/utils/net"
"github.com/sealerio/sealer/utils/os"
"github.com/sealerio/sealer/utils/os/fs"
Expand All @@ -39,9 +38,10 @@ import (
)

var (
deleteFlags *types.Flags
deleteAll bool
ForceDelete bool
deleteFlags *types.Flags
specifyClusterfile string
deleteAll bool
ForceDelete bool
)

var longDeleteCmdDescription = `delete command is used to delete part or all of existing cluster.
Expand Down Expand Up @@ -69,12 +69,13 @@ func NewDeleteCmd() *cobra.Command {
mastersToDelete = deleteFlags.Masters
workersToDelete = deleteFlags.Nodes
)

workClusterfile := common.GetDefaultClusterfile()
if mastersToDelete == "" && workersToDelete == "" && !deleteAll {
return fmt.Errorf("you must input node ip Or set flag -a")
}

workClusterfile := common.GetDefaultClusterfile()
if specifyClusterfile != "" {
workClusterfile = specifyClusterfile
}
if deleteAll {
return deleteCluster(workClusterfile)
}
Expand All @@ -85,8 +86,9 @@ func NewDeleteCmd() *cobra.Command {
deleteFlags = &types.Flags{}
deleteCmd.Flags().StringVarP(&deleteFlags.Masters, "masters", "m", "", "reduce Count or IPList to masters")
deleteCmd.Flags().StringVarP(&deleteFlags.Nodes, "nodes", "n", "", "reduce Count or IPList to nodes")
deleteCmd.Flags().StringVarP(&specifyClusterfile, "Clusterfile", "f", "", "delete a kubernetes cluster with Clusterfile")
deleteCmd.Flags().StringSliceVarP(&deleteFlags.CustomEnv, "env", "e", []string{}, "set custom environment variables")
deleteCmd.Flags().BoolVarP(&ForceDelete, "force", "f", false, "We also can input an --force flag to delete cluster by force")
deleteCmd.Flags().BoolVar(&ForceDelete, "force", false, "We also can input an --force flag to delete cluster by force")
deleteCmd.Flags().BoolVarP(&deleteAll, "all", "a", false, "this flags is for delete the entire cluster, default is false")
deleteCmd.Flags().BoolVarP(&imagedistributor.IsPrune, "prune", "p", true, "this flags is for delete all cluster rootfs, default is true")

Expand Down