-
Notifications
You must be signed in to change notification settings - Fork 40.2k
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
kubectl delete: Introduce new interactive flag for interactive deletion #114530
Conversation
/triage accepted /hold |
43461cb
to
8f698eb
Compare
Hi. I think this release note would work better /release-note-edit Added a new command line argument In Markdown: Added a new command line argument `--confirm` to kubectl. The new command line argument lets a user confirm deletion requests per resource interactively. Not sure from https://www.k8s.dev/docs/guide/release-notes/ if this is the right command; 🤞 hoping it works. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few minor comments, but the code looks good.
But I do have a bigger question about the feature overall:
Have we considered what the user experience will be like if you want to delete a large set of resources?
Would it make sense to summarize what is about to occur and then ask the user for a single confirmation?
For example, with individual confirmation:
$ kubectl delete pod -l group=abc --confirm
Are you sure you want to delete pod/bar? (y/n): y
pod "bar" deleted
Are you sure you want to delete pod/baz? (y/n): y
pod "baz" deleted
Are you sure you want to delete pod/foo? (y/n): y
pod "foo" deleted
Versus a single confirmation:
$ kubectl delete pod -l group=abc --confirm
You are about to delete the following 3 resources:
pod/bar
pod/baz
pod/foo
Do you want to continue? (y/n): y
pod "bar" deleted
pod "baz" deleted
pod "foo" deleted
I'm not trying to redesign the feature, but want to bring up this topic for consideration and make sure it will work well in all situations.
Failure is unrelated; /test pull-kubernetes-node-e2e-containerd |
@@ -155,6 +159,9 @@ func (f *DeleteFlags) AddFlags(cmd *cobra.Command) { | |||
if f.Raw != nil { | |||
cmd.Flags().StringVar(f.Raw, "raw", *f.Raw, "Raw URI to DELETE to the server. Uses the transport specified by the kubeconfig file.") | |||
} | |||
if f.Interactive != nil { | |||
cmd.Flags().BoolVarP(f.Interactive, "interactive", "i", *f.Interactive, "If true, delete resource only when user confirms. This flag is in Alpha.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ardaguclu I had a lengthy conversation with @KnVerey over the past few days and we concluded that it's best to write a KEP laying out all the possible approaches we've discussed during sig-cli call last week, as well as taking into account information from past efforts (kubernetes/enhancements#2775 and kubernetes/enhancements#2777), and the lengthy discussion that happened on k-dev . Especially, that this will be the first installment of interactivity mechanism in kubectl, so this will lay the ground for eventual future work around the topic.
Lastly, given all the various discussions, I'd suggest writing the KEP asap and sharing it with k-dev and sig-cli mailing list, to gather more feedback about its functionality. This will also allow us more time for experiments, when we hide the flag behind feature gate (aka env var).
/hold
for KEP, and 1.28
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
Hi everyone, seen a lot of conversation regarding this issue |
also another query what if admin wants this interactive things as |
Thanks for dropping your comments @dipankardas011. This will be possible, when kuberc feature is landed(see kubernetes/enhancements#3104) |
178f792
to
fd27dd9
Compare
fd27dd9
to
98a6fbd
Compare
@soltysh could you PTAL?. It is changed to align with the KEP. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
// preview result will be used to list resources for confirmation prior to actual delete. | ||
// We can not use r as result object because it can only be used once. But we need to traverse | ||
// twice. Parameters in preview result must be equal to genuine result. | ||
previewr := f.NewBuilder(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit 😉
previewr := f.NewBuilder(). | |
previewer := f.NewBuilder(). |
} | ||
fmt.Fprintf(o.Out, i18n.T("Do you want to continue?")+" (y/n): ") | ||
var input string | ||
_, err := fmt.Fscan(o.In, &input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably better to use fmt.Fscanln
or r.ReadString('\n')
to ensure that it doesn't hang if we don't specify anything. Currently pressing enter will be stuck until you push any button.
Can be addressed in followup.
LGTM label has been added. Git tree hash: 2ba5de33583bfd8a95f56658cbafc769ccb42274
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ardaguclu, soltysh 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 |
/hold cancel |
@ardaguclu: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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/test-infra repository. I understand the commands that are listed here. |
/test pull-kubernetes-e2e-kind-ipv6 |
What type of PR is this?
/kind feature
What this PR does / why we need it:
This PR introduces new interactive flag, namely
interactive
, into delete command. When this flag is set, users have to confirm resource deletion per resource. As alpha stage, this flag will be hidden behindKUBECTL_INTERACTIVE_DELETE
environment variable and can only be used afterKUBECTL_INTERACTIVE_DELETE=true
.This PR is continuation of @eddiezane's previous work eddiezane@e970248
Which issue(s) this PR fixes:
Fixes kubernetes/kubectl#1330
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
Alpha implementation of KEP-3895: kubernetes/enhancements#3895