Skip to content

Conversation

@caesarxuchao
Copy link
Contributor

@caesarxuchao caesarxuchao commented Aug 18, 2016

What's the bug:
When deleting an RC with deleteOptions.OrphanDependents==nil, garbage collector is supposed to treat it as `deleteOptions.OrphanDependents==true", and orphan the pods created by it. But the apiserver is not doing that.

What's in the pr:
Allow each resource to specify the default garbage collection behavior in the registry. For example, RC registry's default GC behavior is Orphan, and Pod registry's default GC behavior is CascadingDeletion.


This change is Reviewable

@caesarxuchao caesarxuchao added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Aug 18, 2016
@caesarxuchao caesarxuchao self-assigned this Aug 18, 2016
@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-label-needed labels Aug 18, 2016
NUM_NODES: $(yaml-quote ${NUM_NODES})
STORAGE_BACKEND: $(yaml-quote ${STORAGE_BACKEND:-})
ENABLE_GARBAGE_COLLECTOR: $(yaml-quote ${ENABLE_GARBAGE_COLLECTOR:-false})
ENABLE_GARBAGE_COLLECTOR: $(yaml-quote ${ENABLE_GARBAGE_COLLECTOR:-})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These will be removed before merge. Just here to run the e2e tests with GC on.

@caesarxuchao
Copy link
Contributor Author

@lavalamp, I only make the RC and RS registry to set OrphanDependents as the default behavior and all tests have passed.
I think we can let the Deployment, Job controller to apply the same default when we convert them to use controllerRef. They are not needed now.

@caesarxuchao caesarxuchao changed the title [WIP][GarbageCollector] Allow per-resource default garbage collection behavior [GarbageCollector] Allow per-resource default garbage collection behavior Aug 18, 2016
@caesarxuchao
Copy link
Contributor Author

@lavalamp it's ready for review. Thanks.

@lavalamp
Copy link
Contributor

Review status: 0 of 10 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed.


cluster/common.sh, line 649 [r1] (raw file):

Previously, caesarxuchao (Chao Xu) wrote…

These will be removed before merge. Just here to run the e2e tests with GC on.

I don't understand why it's needed-- I thought it was on by default? Did it get turned off?

pkg/registry/controller/strategy.go, line 46 [r3] (raw file):

// DefaultGarbageCollectionPolicy returns Orphan because that's the default
// behavior before the server-side garbage collection is implemented.

nits:
s/that's/that was/
s/is/was/


pkg/registry/generic/registry/store.go, line 455 [r3] (raw file):

func shouldUpdateFinalizers(e *Store, accessor meta.Object, options *api.DeleteOptions) (shouldUpdate bool, newFinalizers []string) {
  // check if the object already has the orphan finalizer set.
  alreadyOrphan := false

For clarity, please change to something like the below:

shouldOrphan := false
// Get default orphan policy from this REST object type
if gcStrategy, ok := e.DeleteStrategy.(rest.GarbageCollectionDeleteStrategy); ok {
    if gcStrategy.DefaultGarbageCollectionPolicy() == rest.OrphanDependents {
        shouldOrhpan = true
    }
}
// If a finalizer is set in the object, it overrides the default
hasOrphanFinalizer := false
finalizers := accessor.GetFinalizers()
for _, f := range finalizers {
    if f == api.FinalizerOrphan {
        shouldOrphan = true
        hasOrphanFinalizer = true
        break
    }
    // TODO: update this when we add a finalizer indicating a preference for the other behavior
}
// If an explicit policy was set at deletion time, that overrides both
if options != nil && options.OrphanDependents != nil {
    shouldOrphan = *options.OrphanDependents
}

if shouldOrphan && !hasOrphanFinalizer { /* add the finalizer */ }
if !shouldOrphan && hasOrphanFinalizer { /* remove the finalizer */ }

Comments from Reviewable

@caesarxuchao
Copy link
Contributor Author

Review status: 0 of 10 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed.


cluster/common.sh, line 649 [r1] (raw file):

Previously, lavalamp (Daniel Smith) wrote…

I don't understand why it's needed-- I thought it was on by default? Did it get turned off?

The PR is not merged. wojtek remove the label because of the scalalibity failure.

pkg/registry/generic/registry/store.go, line 455 [r3] (raw file):

Previously, lavalamp (Daniel Smith) wrote…

For clarity, please change to something like the below:

shouldOrphan := false
// Get default orphan policy from this REST object type
if gcStrategy, ok := e.DeleteStrategy.(rest.GarbageCollectionDeleteStrategy); ok {
  if gcStrategy.DefaultGarbageCollectionPolicy() == rest.OrphanDependents {
      shouldOrhpan = true
  }
}
// If a finalizer is set in the object, it overrides the default
hasOrphanFinalizer := false
finalizers := accessor.GetFinalizers()
for _, f := range finalizers {
  if f == api.FinalizerOrphan {
      shouldOrphan = true
      hasOrphanFinalizer = true
      break
  }
  // TODO: update this when we add a finalizer indicating a preference for the other behavior
}
// If an explicit policy was set at deletion time, that overrides both
if options != nil && options.OrphanDependents != nil {
  shouldOrphan = *options.OrphanDependents
}

if shouldOrphan && !hasOrphanFinalizer { /* add the finalizer */ }
if !shouldOrphan && hasOrphanFinalizer { /* remove the finalizer */ }
Thanks! Will do.

Comments from Reviewable

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 19, 2016
@caesarxuchao caesarxuchao force-pushed the per-resource-orphan-behavior branch from aedf6a8 to c87e640 Compare August 19, 2016 01:09
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 19, 2016
@caesarxuchao caesarxuchao force-pushed the per-resource-orphan-behavior branch 2 times, most recently from c8bcbad to 9c1ffd2 Compare August 19, 2016 04:26
@caesarxuchao caesarxuchao added this to the v1.4 milestone Aug 20, 2016
@caesarxuchao
Copy link
Contributor Author

@lavalamp this is needed for 1.4.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 20, 2016
@caesarxuchao caesarxuchao force-pushed the per-resource-orphan-behavior branch from 9c1ffd2 to 67b7c72 Compare August 22, 2016 18:37
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 22, 2016
@k8s-bot
Copy link

k8s-bot commented Aug 22, 2016

GCE e2e build/test passed for commit 67b7c72.

@lavalamp
Copy link
Contributor

:lgtm:


Review status: 0 of 7 files reviewed at latest revision, 2 unresolved discussions.


Comments from Reviewable

@caesarxuchao caesarxuchao added release-note Denotes a PR that will be considered when it comes time to generate release notes. lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed release-note-label-needed labels Aug 22, 2016
@caesarxuchao
Copy link
Contributor Author

Adding the label per previous comment.

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link

k8s-bot commented Aug 23, 2016

GCE e2e build/test passed for commit 67b7c72.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit f297ea9 into kubernetes:master Aug 23, 2016
// DefaultGarbageCollectionPolicy returns Orphan because that was the default
// behavior before the server-side garbage collection was implemented.
func (rcStrategy) DefaultGarbageCollectionPolicy() rest.GarbageCollectionPolicy {
return rest.OrphanDependents
Copy link
Contributor

Choose a reason for hiding this comment

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

Will the policy change if I specify OrphanDependents=false in DeleteOptions now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. DeleteOptions have the highest priority. The existing finalizers on the object has the second highest priority. This default policy has the lowest priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants