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

change DefaultGarbageCollectionPolicy to DeleteDependents for workloads controllers #55148

Conversation

dixudx
Copy link
Member

@dixudx dixudx commented Nov 6, 2017

What this PR does / why we need it:
As part of the apps/v1 GA effort (kubernetes/enhancements#353) for v1.9. For core controllers, like Deployment, DaemonSet, ReplicaSet, and StatefulSet, changing the DefaultGarbageCollectionPolicy from OrphanDependents to DeleteDependents will make these objects consistent with the default behavior for all new objects.

For legacy API versions, the DefaultGarbageCollectionPolicy remains OrphanDependents.

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

Special notes for your reviewer:
/cc @enisoc @caesarxuchao @kow3ns
/assign @kubernetes/sig-apps-api-reviews

Release note:

The default garbage collection policy for Deployment, DaemonSet, StatefulSet, and ReplicaSet has changed from OrphanDependents to DeleteDependents when the deletion is requested through an `apps/v1` endpoint. Clients using older endpoints will be unaffected. This change is only at the REST API level and is independent of the default behavior of particular clients (e.g. this does not affect the default for the kubectl `--cascade` flag).

If you upgrade your client-go libs and use the `AppsV1()` interface, please note that the default garbage collection behavior is changed.

@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API 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 Nov 6, 2017
@dixudx
Copy link
Member Author

dixudx commented Nov 6, 2017

/unassign @derekwaynecarr @eparis
/assign @smarterclayton @janetkuo

Copy link
Member

@enisoc enisoc left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up so quickly! It looks like what I had in mind. Can you just add strategy tests and integration tests like in #50719?

if requestInfo, found := genericapirequest.RequestInfoFrom(ctx); found {
groupVersion := schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
switch groupVersion {
case extensionsv1beta1.SchemeGroupVersion, appsv1beta1.SchemeGroupVersion, appsv1beta2.SchemeGroupVersion:
Copy link
Member

Choose a reason for hiding this comment

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

You can leave out extensions/v1beta1 for StatefulSet, since it never existed there.

if requestInfo, found := genericapirequest.RequestInfoFrom(ctx); found {
groupVersion := schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
switch groupVersion {
case extensionsv1beta1.SchemeGroupVersion, appsv1beta1.SchemeGroupVersion, appsv1beta2.SchemeGroupVersion:
Copy link
Member

Choose a reason for hiding this comment

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

You can leave out apps/v1beta1 for DaemonSet, since it never existed there.

if requestInfo, found := genericapirequest.RequestInfoFrom(ctx); found {
groupVersion := schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
switch groupVersion {
case extensionsv1beta1.SchemeGroupVersion, appsv1beta1.SchemeGroupVersion, appsv1beta2.SchemeGroupVersion:
Copy link
Member

Choose a reason for hiding this comment

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

You can leave out apps/v1beta1 for ReplicaSet, since it never existed there.

Copy link
Member

@kow3ns kow3ns left a comment

Choose a reason for hiding this comment

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

Generally LGTM but could use some unit tests.

@mbohlool
Copy link
Contributor

mbohlool commented Nov 6, 2017

/cc @mml

@k8s-ci-robot k8s-ci-robot requested a review from mml November 6, 2017 21:10
@dixudx dixudx force-pushed the controller_defaultGC_DeleteDependents branch from fa8eac8 to 3ce2bac Compare November 7, 2017 05:52
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 7, 2017
@dixudx
Copy link
Member Author

dixudx commented Nov 7, 2017

@enisoc @kow3ns Updated. PTAL. Thanks.

@dixudx dixudx force-pushed the controller_defaultGC_DeleteDependents branch from 3ce2bac to 6facef9 Compare November 7, 2017 06:06
@caesarxuchao
Copy link
Member

@dixudx @enisoc @kow3ns this came up in our team meeting today. @lavalamp raised concerns for upgrading/downgrading the cluster. I think what he meant was that if the apiserver was downgraded to an old version, but the controller manager was not downgraded yet, was it possible that the controller manager got confused because the old apiserver didn't do cascading deletion for apps/v1/replicaset? I don't have any specific objection, but I agree that we need to think the implication through.

@enisoc
Copy link
Member

enisoc commented Nov 7, 2017

if the apiserver was downgraded to an old version, but the controller manager was not downgraded yet, was it possible that the controller manager got confused because the old apiserver didn't do cascading deletion for apps/v1/replicaset?

If I'm understanding the scenario correctly, I think it should be ok. We aren't changing anything in the GC itself (the part that lives in controller manager). We're only changing the finalizers added by apiserver at the moment when a DELETE request comes in.

If a DELETE comes through apps/v1 after apiserver is upgraded, it sets the right finalizers for cascading. After that, the behavior of GC should depend only on the finalizers on the object (I don't see anywhere that GC fails to send an explicit DeletionPropagation policy), so downgrading apiserver during this process shouldn't have any effect.

If a DELETE comes through apps/v1 after apiserver is downgraded, it will fail because apps/v1 doesn't exist there. This is the same as any time we add a new version; it's not related to whether we change the default GC policy.

Copy link
Member

@enisoc enisoc left a comment

Choose a reason for hiding this comment

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

The unit tests look good, but I'd like to have at least one integration test before we merge to prove this works.

Can you test that the expected finalizers get added when you delete via apps/v1beta2 vs apps/v1? To avoid racing with actual deletion, you can add your own made up finalizer that you don't remove until after you've verified the other expected values.

genericapirequest.RequestInfo{
APIGroup: "apps",
APIVersion: "v1beta1",
Resource: "statefulset",
Copy link
Member

Choose a reason for hiding this comment

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

nit: It doesn't affect the current code, but for the sake of realism I think the Resource names should be plural.

@dixudx dixudx force-pushed the controller_defaultGC_DeleteDependents branch from 6facef9 to f70da82 Compare November 8, 2017 07:42
@dixudx
Copy link
Member Author

dixudx commented Nov 8, 2017

Can you test that the expected finalizers get added when you delete via apps/v1beta2 vs apps/v1?

@enisoc Did find a bug. shouldDeleteDependents will not return true if we set default GC policy to DeleteDependents. Already fixed together with this PR.

@dixudx dixudx force-pushed the controller_defaultGC_DeleteDependents branch from f70da82 to 178f0cd Compare November 8, 2017 08:41
@janetkuo
Copy link
Member

Another comment on release note:

The default garbage collection policy for Deployment, DaemonSet, StatefulSet, and ReplicaSet has changed from OrphanDependents to DeleteDependents when the deletion is requested through an `apps/v1` endpoint.

apps/v1 is new in this release (1.9), so there's no need to mention previous behavior. Mentioning current behavior is enough.

Is OrphanDependents or DeleteDependents visible to users? Do we need to mention it at all, or should we instead say something like "dependent objects are deleted by default unless DeleteOptions is specified otherwise"?

We need to update documents (e.g. https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/#setting-the-cascading-deletion-policy) once this is merged.

@dixudx
Copy link
Member Author

dixudx commented Nov 21, 2017

ping @janetkuo @enisoc @caesarxuchao Updated. PTAL. Thanks.

@dixudx
Copy link
Member Author

dixudx commented Nov 21, 2017

apps/v1 is new in this release (1.9), so there's no need to mention previous behavior. Mentioning current behavior is enough.

@janetkuo SGTM.
@enisoc Any comments?

t.Fatalf("Failed to verify the finalizer: %v", err)
}

// remove fakeFinalizer
Copy link
Member

Choose a reason for hiding this comment

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

Use updateRS just like above, so this gets retried on conflict. It's fine to do the update via extensions/v1beta1.

return false, err
}
t.Logf("getting the fianlizer: %s", newRS.Finalizers)
return newRS.DeletionTimestamp != nil && reflect.DeepEqual(newRS.Finalizers, []string{fakeFinalizer}), nil
Copy link
Member

Choose a reason for hiding this comment

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

It's better to fail if any new finalizers were added, rather than continue polling:

if newRS.DeletionTimestamp == nil {
  return false, nil
}
if got, want := newRS.Finalizers, []string{fakeFinalizer}; !reflect.DeepEqual(got, want) {
  return false, fmt.Errorf("Finalizers = %+v; want %+v", got, want)
}
return true, nil

@enisoc
Copy link
Member

enisoc commented Nov 21, 2017

/assign @liggitt
for approval

@dixudx dixudx force-pushed the controller_defaultGC_DeleteDependents branch from e389936 to 344fe56 Compare November 22, 2017 02:10
@dixudx
Copy link
Member Author

dixudx commented Nov 22, 2017

@enisoc @liggitt @janetkuo Updated. PTAL. Thanks

@enisoc
Copy link
Member

enisoc commented Nov 22, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 22, 2017
@liggitt
Copy link
Member

liggitt commented Nov 22, 2017

/approve

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 22, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dixudx, enisoc, liggitt

Associated issue: 353

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

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@jberkus
Copy link

jberkus commented Nov 22, 2017

/priority critical-urgent

/remove-priority important-soon

adjusting priorities for code freeze

@k8s-ci-robot k8s-ci-robot added priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. and removed priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. labels Nov 22, 2017
@k8s-github-robot
Copy link

[MILESTONENOTIFIER] Milestone Pull Request Current

@dixudx @enisoc @janetkuo @liggitt @smarterclayton

Note: This pull request is marked as priority/critical-urgent, and must be updated every 1 day during code freeze.

Example update:

ACK.  In progress
ETA: DD/MM/YYYY
Risks: Complicated fix required
Pull Request Labels
  • sig/apps: Pull Request will be escalated to these SIGs if needed.
  • priority/critical-urgent: Never automatically move pull request out of a release milestone; continually escalate to contributor and SIG through all available channels.
  • kind/cleanup: Adding tests, refactoring, fixing old bugs.
Help

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 52767, 55065, 55148, 56228, 56221). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 00b2d95 into kubernetes:master Nov 23, 2017
@dixudx dixudx deleted the controller_defaultGC_DeleteDependents branch November 23, 2017 05:09
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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/apps Categorizes an issue or PR as relevant to SIG Apps. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet