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

kubectl delete: Introduce new interactive flag for interactive deletion #114530

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

ardaguclu
Copy link
Member

@ardaguclu ardaguclu commented Dec 16, 2022

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 behind KUBECTL_INTERACTIVE_DELETE environment variable and can only be used after KUBECTL_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?

Added a new command line argument `--interactive` to kubectl. The new command line argument lets a user confirm deletion requests per resource interactively.

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

Alpha implementation of KEP-3895: kubernetes/enhancements#3895

@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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 16, 2022
@k8s-ci-robot k8s-ci-robot added area/kubectl area/test sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Dec 16, 2022
@ardaguclu
Copy link
Member Author

/triage accepted
/priority backlog

/hold
until review

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Dec 16, 2022
@ardaguclu
Copy link
Member Author

@sftim
Copy link
Contributor

sftim commented Dec 17, 2022

Hi. I think this release note would work better

/release-note-edit Added a new command line argument --confirm to kubectl. The new command line argument lets a user confirm deletion requests per resource interactively.

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.

Copy link
Member

@brianpursley brianpursley left a 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.

staging/src/k8s.io/kubectl/pkg/cmd/delete/delete.go Outdated Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/delete/delete.go Outdated Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/delete/delete_test.go Outdated Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/delete/delete.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Feb 27, 2023
@ardaguclu
Copy link
Member Author

Failure is unrelated;

/test pull-kubernetes-node-e2e-containerd

staging/src/k8s.io/kubectl/pkg/cmd/delete/delete.go Outdated Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/delete/delete.go Outdated Show resolved Hide resolved
@@ -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.")
Copy link
Contributor

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

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 29, 2023
@ardaguclu
Copy link
Member Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 29, 2023
@dipankardas011
Copy link
Contributor

Hi everyone, seen a lot of conversation regarding this issue
I have a thought that what if we don't validate or get if the resource is available or not rather than we can directly use the users input and prompt the above (sorry if this is want being worked on) also this will be much easier to add as it will lead to lower number of changes other than cli

@dipankardas011
Copy link
Contributor

also another query what if admin wants this interactive things as always on what are we planning for that?

@ardaguclu
Copy link
Member Author

also another query what if admin wants this interactive things as always on what are we planning for that?

Thanks for dropping your comments @dipankardas011. This will be possible, when kuberc feature is landed(see kubernetes/enhancements#3104)

@ardaguclu
Copy link
Member Author

@soltysh could you PTAL?. It is changed to align with the KEP.

Copy link
Contributor

@soltysh soltysh left a 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().
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit 😉

Suggested change
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)
Copy link
Contributor

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.

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

LGTM label has been added.

Git tree hash: 2ba5de33583bfd8a95f56658cbafc769ccb42274

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@soltysh
Copy link
Contributor

soltysh commented Jul 11, 2023

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 11, 2023
@k8s-ci-robot
Copy link
Contributor

@ardaguclu: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-e2e-kind-ipv6 98a6fbd link unknown /test pull-kubernetes-e2e-kind-ipv6

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.

@ardaguclu
Copy link
Member Author

/test pull-kubernetes-e2e-kind-ipv6

@k8s-ci-robot k8s-ci-robot merged commit 3267dd9 into kubernetes:master Jul 11, 2023
8 of 13 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Jul 11, 2023
@ardaguclu ardaguclu deleted the delete-confirm-flag branch July 11, 2023 13:08
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. area/kubectl area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add new interactive flag into delete command
9 participants