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

Use DeleteOptions.PropagationPolicy instead of OrphanDependents (deprecated) in kubectl #59851

Merged

Conversation

nilebox
Copy link

@nilebox nilebox commented Feb 14, 2018

What this PR does / why we need it:
Replaces the deprecated DeleteOptions.OrphanDependents deletion option with DeleteOptions.PropagationPolicy. It will improve the cascade deletion by using Foreground GC deletion instead of the old OrphanDependents: false which has a confusing behavior (leaves orphans if children has finalizers set).

Which issue(s) this PR fixes:
Fixes #59850

Special notes for your reviewer:

Release note:

Use DeleteOptions.PropagationPolicy instead of OrphanDependents in kubectl 

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 14, 2018
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 14, 2018
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 14, 2018
@nilebox nilebox force-pushed the kubectl-foreground-deletion branch from 1f41571 to 18bd17b Compare February 14, 2018 05:05
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 14, 2018
@nilebox nilebox force-pushed the kubectl-foreground-deletion branch 2 times, most recently from 03cedb4 to 84b24b9 Compare February 14, 2018 05:25
@nilebox
Copy link
Author

nilebox commented Feb 14, 2018

/assign @liggitt

falseVar := false
deleteOptions := &metav1.DeleteOptions{OrphanDependents: &falseVar}
policy := metav1.DeletePropagationForeground
deleteOptions := &metav1.DeleteOptions{PropagationPolicy: &policy}
Copy link
Member

Choose a reason for hiding this comment

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

Why not background deletion?

Copy link
Author

@nilebox nilebox Feb 14, 2018

Choose a reason for hiding this comment

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

@liggitt as I noted in #59850, I would like blockOwnerDeletion: true flag to be respected by default deletion with kubectl delete command. As far as I understand, with background deletion the owner will be deleted immediately regardless of whether there are dependents with blockOwnerDeletion: true flag or not.
Also, I think that with kubectl --cascade=true seeing the owner gone only after all dependents deleted is a more straightforward UX.

falseVar := false
deleteOptions := &metav1.DeleteOptions{OrphanDependents: &falseVar}
policy := metav1.DeletePropagationForeground
deleteOptions := &metav1.DeleteOptions{PropagationPolicy: &policy}
Copy link
Member

Choose a reason for hiding this comment

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

Same question, why not background?

Copy link
Author

Choose a reason for hiding this comment

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

The reasoning is the same as for generic deletion. Is there a specific reason for deleting ReplicationController immediately?

Copy link
Member

Choose a reason for hiding this comment

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

At this point, the reaper has called scaler.Scale to stop all the dependent pods, so you can set the policy to "background" to delete the owner immediately. Moving away from OrphanDependents is good, as the field is marked deprecated.

Or, you can remove the reapers, and rely on the garbage collector (GC) to do the foreground deletion. The behavior will be different in that:

  1. the GC deletion waits for all the dependent objects to be deleted before deleting the replicaset, not limiting to pods;
  2. the GC deletion waits for the dependents to be deleted from etcd; while the scalers only wait for the pods to be in the NotReady state. GC's behavior is better, because for objects like pods, only the deletion from etcd indicates the occupied resources are released.
  3. GC cascadingly deletes dependents' dependents; reapers don't.

Moving away from reapers requires more discussion in the sig-cli, and can be done in another PR.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the context, will change it to "background" there.

return body == nil && expectedOrphanDependents == nil
func hasExpectedPropagationPolicy(body io.ReadCloser, policy *metav1.DeletionPropagation) bool {
if body == nil || policy == nil {
return body == nil && policy == nil
}
var parsedBody metav1.DeleteOptions
rawBody, _ := ioutil.ReadAll(body)
json.Unmarshal(rawBody, &parsedBody)
Copy link
Member

Choose a reason for hiding this comment

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

No error handling on these two lines. Maybe fix it as a separate commit while at it?

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe its ok...

Copy link
Author

Choose a reason for hiding this comment

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

I think it's fine - it's part of a unit test which will break if anything is wrong with the body.

@nilebox
Copy link
Author

nilebox commented Feb 21, 2018

/assign @caesarxuchao

@caesarxuchao
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed 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 Feb 21, 2018
@nilebox nilebox force-pushed the kubectl-foreground-deletion branch from 33e74b9 to be952d6 Compare February 22, 2018 03:33
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 22, 2018
@nilebox nilebox force-pushed the kubectl-foreground-deletion branch 2 times, most recently from f5fc75e to eb03996 Compare February 22, 2018 04:36
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 22, 2018
@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels May 17, 2018
@soltysh soltysh mentioned this pull request May 17, 2018
@deads2k
Copy link
Contributor

deads2k commented May 17, 2018

/retest

@smarterclayton
Copy link
Contributor

/hold

Just looking at this, it looks like this makes kubectl delete for the majority of resources change from "completes and the object is deleted" to "you will now race with the GC". That means kubectl delete && kubectl create no longer works correctly for anything that isn't 'pod' or 'namespace'. Is that correct?

I'm in favor of this change, but to do it we need to make kubectl delete not break, which implies wait as discussed above. wait should be the default - if we need to gather consensus to also make pod and namespace wait I'd be happy to arrange for that.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 17, 2018
@nilebox
Copy link
Author

nilebox commented May 17, 2018

/test pull-kubernetes-e2e-gce
/test pull-kubernetes-unit

@nilebox
Copy link
Author

nilebox commented May 17, 2018

@smarterclayton ok, I'll change default for -wait to be set by default in #63695

@soltysh
Copy link
Contributor

soltysh commented May 18, 2018

@smarterclayton I agree with your approach to --wait but I don't want to do it here since first I want to see this code cleaned up. This includes this PR and #63979. Only then we can add nice and clean --wait functionality, which will happen in #63695 like Nail mentioned earlier. If we include it here, the code will be a mess, and I don't want to see that. I have a list of items that are required for 1.11 and --wait is already there.

@soltysh
Copy link
Contributor

soltysh commented May 18, 2018

Let's wait for #64034 and then you'll have to rebase your PR on top of that. We'll get nice generic --wait mechanism which will help me with #63979.

@nilebox nilebox force-pushed the kubectl-foreground-deletion branch from 44b3ed9 to 3b5afd8 Compare May 23, 2018 07:01
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 23, 2018
@nilebox
Copy link
Author

nilebox commented May 23, 2018

@soltysh #64034 is merged, I rebased this PR. should not be marked with do-not-merge/hold anymore I believe? Also need to re-add lgtm after rebase.

@nilebox
Copy link
Author

nilebox commented May 23, 2018

/retest

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels May 23, 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.

/lgtm
/hold cancel

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nilebox, seans3, 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

@nilebox
Copy link
Author

nilebox commented May 23, 2018

/retest

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented May 23, 2018

@nilebox: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-unit b92940f link /test pull-kubernetes-unit

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.

@soltysh
Copy link
Contributor

soltysh commented May 23, 2018

/retest

@k8s-github-robot
Copy link

Automatic merge from submit-queue. 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. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. 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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use propagationPolicy: Foreground in kubectl by default