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

[kwokctl] Support Force Delete Cluster #1128

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions pkg/kwokctl/cmd/delete/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type flagpole struct {
Name string
Kubeconfig string
All bool
Force bool
}

// NewCommand returns a new cobra.Command for cluster deletion
Expand All @@ -56,7 +57,7 @@ func NewCommand(ctx context.Context) *cobra.Command {
}
cmd.Flags().StringVar(&flags.Kubeconfig, "kubeconfig", flags.Kubeconfig, "The path to the kubeconfig file that will remove the deleted cluster")
cmd.Flags().BoolVar(&flags.All, "all", flags.All, "Delete all clusters managed by kwokctl")

cmd.Flags().BoolVar(&flags.Force, "force", false, "Force delete the cluster")
return cmd
}

Expand All @@ -70,13 +71,13 @@ func runE(ctx context.Context, flags *flagpole) error {
return err
}
for _, cluster := range clusters {
err = deleteCluster(ctx, cluster, flags.Kubeconfig)
err = deleteCluster(ctx, cluster, flags.Kubeconfig, flags.Force)
if err != nil {
return err
}
}
} else {
err = deleteCluster(ctx, flags.Name, flags.Kubeconfig)
err = deleteCluster(ctx, flags.Name, flags.Kubeconfig, flags.Force)
if err != nil {
return err
}
Expand All @@ -85,7 +86,7 @@ func runE(ctx context.Context, flags *flagpole) error {
return nil
}

func deleteCluster(ctx context.Context, clusterName string, kubeconfigPath string) error {
func deleteCluster(ctx context.Context, clusterName string, kubeconfigPath string, force bool) error {
name := config.ClusterName(clusterName)
workdir := path.Join(config.ClustersDir, clusterName)

Expand All @@ -108,6 +109,13 @@ func deleteCluster(ctx context.Context, clusterName string, kubeconfigPath strin
return err
}

joeyyy09 marked this conversation as resolved.
Show resolved Hide resolved
if err := rt.Available(ctx); err != nil {
if !force {
return err
}
logger.Warn("Unavailable runtime but proceed with force delete", "err", err)
}

// Stop the cluster
start := time.Now()
logger.Info("Cluster is stopping")
Expand Down
1 change: 1 addition & 0 deletions site/content/en/docs/generated/kwokctl_delete_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ kwokctl delete cluster [flags]

```
--all Delete all clusters managed by kwokctl
--force Force delete the cluster
-h, --help help for cluster
--kubeconfig string The path to the kubeconfig file that will remove the deleted cluster (default "~/.kube/config")
```
Expand Down
Loading