Skip to content

Commit

Permalink
Merge pull request #1128 from joeyyy09/force-flag
Browse files Browse the repository at this point in the history
[kwokctl] Support Force Delete Cluster
  • Loading branch information
k8s-ci-robot authored Jun 24, 2024
2 parents 51633a7 + af10de4 commit 98f0a81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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
}

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

0 comments on commit 98f0a81

Please sign in to comment.