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

Conversation

joeyyy09
Copy link
Contributor

@joeyyy09 joeyyy09 commented May 31, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR introduces a new --force flag for the kwokctl delete cluster command. This flag allows users to force delete a cluster, even if the runtime is unavailable or the cluster does not exist.

Which issue(s) this PR fixes:

Fixes #1124

Special notes for your reviewer:

The main changes include:
Addition of the Force field in the flagpole struct.
Modification of the deleteCluster function to handle the force flag.
Addition of the --force command-line flag in the NewCommand function.

Does this PR introduce a user-facing change?

- Added `--force` flag to `kwokctl delete cluster` command to forcefully delete a cluster.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. kind/documentation Categorizes issue or PR as related to documentation. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 31, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @joeyyy09. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 31, 2024
Copy link

netlify bot commented May 31, 2024

Deploy Preview for k8s-kwok canceled.

Name Link
🔨 Latest commit af10de4
🔍 Latest deploy log https://app.netlify.com/sites/k8s-kwok/deploys/667510feac0a4c00080d0b06

@joeyyy09 joeyyy09 changed the title Support Force Delete Cluster [kwokctl] Support Force Delete Cluster May 31, 2024
@wzshiming
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 31, 2024
@joeyyy09
Copy link
Contributor Author

Hey @wzshiming, I've made the required changes, can you please let me know if i've got to change anything else? Thanks!

Copy link
Member

@wzshiming wzshiming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/pkg/kwokctl/cmd/delete/cluster/cluster.go b/pkg/kwokctl/cmd/delete/cluster/cluster.go
index 7530a260..571dbefd 100644
--- a/pkg/kwokctl/cmd/delete/cluster/cluster.go
+++ b/pkg/kwokctl/cmd/delete/cluster/cluster.go
@@ -35,9 +35,10 @@ import (
 type flagpole struct {
 	Name       string
 	Kubeconfig string
+	Force      bool
 }
 
-// NewCommand returns a new cobra.Command for cluster creation
+// NewCommand returns a new cobra.Command for cluster deletion
 func NewCommand(ctx context.Context) *cobra.Command {
 	flags := &flagpole{}
 	flags.Kubeconfig = path.RelFromHome(kubeconfig.GetRecommendedKubeconfigPath())
@@ -52,6 +53,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.Force, "force", false, "Force delete the cluster")
 	return cmd
 }
 
@@ -77,6 +79,13 @@ func runE(ctx context.Context, flags *flagpole) error {
 		return err
 	}
 
+	if err := rt.Available(ctx); err != nil {
+		if !flags.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")

@wzshiming
Copy link
Member

wzshiming commented Jun 5, 2024

This needs rebase.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 5, 2024
@joeyyy09
Copy link
Contributor Author

joeyyy09 commented Jun 5, 2024

This needs rebase.

I think the changes made in this PR have been made in #1125 and has been merged.

@wzshiming
Copy link
Member

wzshiming commented Jun 6, 2024

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 6, 2024
@joeyyy09
Copy link
Contributor Author

joeyyy09 commented Jun 6, 2024

So now you need to rebase this branch to the main. refer https://www.google.com/search?q=git+rebase+and+fix+conflicts

Made the changes

@wzshiming
Copy link
Member

diff --git a/pkg/kwokctl/cmd/delete/cluster/cluster.go b/pkg/kwokctl/cmd/delete/cluster/cluster.go
index 7530a260..571dbefd 100644
--- a/pkg/kwokctl/cmd/delete/cluster/cluster.go
+++ b/pkg/kwokctl/cmd/delete/cluster/cluster.go
@@ -35,9 +35,10 @@ import (
 type flagpole struct {
 	Name       string
 	Kubeconfig string
+	Force      bool
 }
 
-// NewCommand returns a new cobra.Command for cluster creation
+// NewCommand returns a new cobra.Command for cluster deletion
 func NewCommand(ctx context.Context) *cobra.Command {
 	flags := &flagpole{}
 	flags.Kubeconfig = path.RelFromHome(kubeconfig.GetRecommendedKubeconfigPath())
@@ -52,6 +53,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.Force, "force", false, "Force delete the cluster")
 	return cmd
 }
 
@@ -77,6 +79,13 @@ func runE(ctx context.Context, flags *flagpole) error {
 		return err
 	}
 
+	if err := rt.Available(ctx); err != nil {
+		if !flags.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")

NOTICE THIS PATCH

@joeyyy09
Copy link
Contributor Author

joeyyy09 commented Jun 6, 2024

diff --git a/pkg/kwokctl/cmd/delete/cluster/cluster.go b/pkg/kwokctl/cmd/delete/cluster/cluster.go
index 7530a260..571dbefd 100644
--- a/pkg/kwokctl/cmd/delete/cluster/cluster.go
+++ b/pkg/kwokctl/cmd/delete/cluster/cluster.go
@@ -35,9 +35,10 @@ import (
 type flagpole struct {
 	Name       string
 	Kubeconfig string
+	Force      bool
 }
 
-// NewCommand returns a new cobra.Command for cluster creation
+// NewCommand returns a new cobra.Command for cluster deletion
 func NewCommand(ctx context.Context) *cobra.Command {
 	flags := &flagpole{}
 	flags.Kubeconfig = path.RelFromHome(kubeconfig.GetRecommendedKubeconfigPath())
@@ -52,6 +53,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.Force, "force", false, "Force delete the cluster")
 	return cmd
 }
 
@@ -77,6 +79,13 @@ func runE(ctx context.Context, flags *flagpole) error {
 		return err
 	}
 
+	if err := rt.Available(ctx); err != nil {
+		if !flags.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")

NOTICE THIS PATCH

Yeah, should i modify anything here?

@wzshiming
Copy link
Member

Your changes are wrong.

@joeyyy09
Copy link
Contributor Author

joeyyy09 commented Jun 6, 2024

Your changes are wrong.

Okay, I'll rethink my approach and will fix this.

@wzshiming
Copy link
Member

It cannot achieve the effect of not forcing deletion

@joeyyy09
Copy link
Contributor Author

joeyyy09 commented Jun 6, 2024

Normal deletion works normal when the --force flag is not set and the runtime is available. If the runtime is not available and the --force flag is not set, the cluster will not be deleted. If the --force flag is set to true, the cluster will be deleted despite the unavailability of the runtime. Is this correct? I was trying to implement this and i've checked with and without the flags on my local build. Can you please explain me in detail if this understanding of mine is wrong?

@wzshiming
Copy link
Member

wzshiming commented Jun 9, 2024

diff --git a/pkg/kwokctl/cmd/delete/cluster/cluster.go b/pkg/kwokctl/cmd/delete/cluster/cluster.go
index 7530a260..571dbefd 100644
--- a/pkg/kwokctl/cmd/delete/cluster/cluster.go
+++ b/pkg/kwokctl/cmd/delete/cluster/cluster.go
@@ -35,9 +35,10 @@ import (
 type flagpole struct {
 	Name       string
 	Kubeconfig string
+	Force      bool
 }
 
-// NewCommand returns a new cobra.Command for cluster creation
+// NewCommand returns a new cobra.Command for cluster deletion
 func NewCommand(ctx context.Context) *cobra.Command {
 	flags := &flagpole{}
 	flags.Kubeconfig = path.RelFromHome(kubeconfig.GetRecommendedKubeconfigPath())
@@ -52,6 +53,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.Force, "force", false, "Force delete the cluster")
 	return cmd
 }
 
@@ -77,6 +79,13 @@ func runE(ctx context.Context, flags *flagpole) error {
 		return err
 	}
 
+	if err := rt.Available(ctx); err != nil {
+		if !flags.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")

NOTICE THIS PATCH

Can't you see this patch?
I've already sent you the changes that need to be made.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 9, 2024
Copy link
Member

@wzshiming wzshiming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are too many irrelevant changes, please squash all commits

Signed-off-by: Joeyyy09 <[email protected]>

Add check for runtime

Signed-off-by: Joeyyy09 <[email protected]>

Update docs

Signed-off-by: Joeyyy09 <[email protected]>

Rebase to main

Signed-off-by: Joeyyy09 <[email protected]>

Add force flag

Signed-off-by: Joeyyy09 <[email protected]>

Modify according to the patch

Signed-off-by: Joeyyy09 <[email protected]>
@joeyyy09
Copy link
Contributor Author

There are too many irrelevant changes, please squash all commits

Yep, squashed all the commits

@wzshiming
Copy link
Member

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 24, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: joeyyy09, wzshiming

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 24, 2024
@k8s-ci-robot k8s-ci-robot merged commit 98f0a81 into kubernetes-sigs:main Jun 24, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/documentation Categorizes issue or PR as related to documentation. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[kwokctl] Support force delete cluster
3 participants