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

--force only takes effect when --grace-period=0 #61378

Merged
merged 1 commit into from Mar 22, 2018

Conversation

ChiuWang
Copy link
Contributor

@ChiuWang ChiuWang commented Mar 20, 2018

kubectl delete should warn when force is specified without --grace-period=0

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #61374

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 20, 2018
@ChiuWang
Copy link
Contributor Author

/assign @smarterclayton @janetkuo

@@ -218,6 +218,10 @@ func (o *DeleteOptions) Validate(cmd *cobra.Command) error {
o.WaitForDeletion = true
o.GracePeriod = 1
}
} else {
if o.ForceDeletion {
return fmt.Errorf("--force should be specified with --grace-period=0")
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to print warnings instead of errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dixudx Done.

@@ -218,6 +218,10 @@ func (o *DeleteOptions) Validate(cmd *cobra.Command) error {
o.WaitForDeletion = true
o.GracePeriod = 1
}
} else {
if o.ForceDeletion {
Copy link
Member

Choose a reason for hiding this comment

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

nit: just use else if

@janetkuo
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 20, 2018
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.

I'd prefer to update the command description, flag description and examples with information about the need for using both rather than throwing a warning at user.

@ChiuWang
Copy link
Contributor Author

@soltysh I will update the description part, but the warning seems necessary as well.

@soltysh
Copy link
Contributor

soltysh commented Mar 20, 2018

@soltysh I will update the description part, but the warning seems necessary as well.

ok

@janetkuo
Copy link
Member

janetkuo commented Mar 20, 2018

Suggest changing flag description as follows:

--force: Only used when grace-period=0. If true, immediately remove resources from API and bypass graceful deletion. Note that immediate deletion of some resources may result in inconsistency or data loss and requires confirmation.

--grace-period: Period of time in seconds given to the resource to terminate gracefully. Ignored if negative. Set to 1 for immediate shutdown. Can only be set to 0 when --force is true (force deletion).

cc @smarterclayton to review the flag description.

I also agree that a warning is necessary, since kubectl delete --force acts the same as kubectl delete, which may be surprising to users who explicitly specify delete --force.

@@ -218,6 +218,8 @@ func (o *DeleteOptions) Validate(cmd *cobra.Command) error {
o.WaitForDeletion = true
o.GracePeriod = 1
}
} else if o.ForceDeletion {
fmt.Fprintf(o.ErrOut, "warning: --force should be specified with --grace-period=0")
Copy link
Member

Choose a reason for hiding this comment

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

warning: --force is ignored because --grace-period is not 0.\n

To make it clear that --force doesn't do anything here and a normal delete operation is sent.

@@ -218,6 +218,8 @@ func (o *DeleteOptions) Validate(cmd *cobra.Command) error {
o.WaitForDeletion = true
o.GracePeriod = 1
}
} else if o.ForceDeletion {
Copy link
Member

@janetkuo janetkuo Mar 20, 2018

Choose a reason for hiding this comment

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

There's a function printDeletion that prints "resource foo deleted" after deletion operation is sent successfully.

Would you change the operation string to "force deleted" when o.GracePeriod == 0? So that kubectl delete pod foo --grace-period=0 --force prints pod "foo" force deleted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@janetkuo Modified.
cc @soltysh

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 21, 2018
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 21, 2018
@ChiuWang ChiuWang force-pushed the delete_force branch 2 times, most recently from 9c237cf to 4e6a430 Compare March 21, 2018 08:28
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, I'll leave it for Janet or Clayton for final approval

@janetkuo
Copy link
Member

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: charrywanganthony, janetkuo

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 Mar 21, 2018
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 61378, 60915, 61499, 61507, 61478). If you want to cherry-pick this change to another branch, please follow the instructions here.

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. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. 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.

kubectl delete --force doesn't work as expected
7 participants