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

[GarbageCollector] Add orphaning finalizer logic to GC #25599

Merged
merged 1 commit into from
May 26, 2016

Conversation

caesarxuchao
Copy link
Member

@caesarxuchao caesarxuchao commented May 13, 2016

If the `--enable-garbage-collector` (alpha feature) is set when starting the apiserver and the controller manager, sending deletion request with `DeleteOptions.OrphanDependents=true` will instruct the garbage collector to orphan the object's dependents, that is, to not delete the dependents.
  • Added the orphaning finalizer logic to GC
  • Added the generic finalizer logic to the APIServer
  • Added the logic that handles DeleteOptions.OrphanDependents to the APIServer

Design doc is at https://github.com/kubernetes/kubernetes/blob/master/docs/proposals/garbage-collection.md

@lavalamp @gmarek @kubernetes/sig-api-machinery


This change is Reviewable

@caesarxuchao caesarxuchao added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label May 13, 2016
@caesarxuchao caesarxuchao force-pushed the orphaning-finalizer branch from c6ca084 to d90165a Compare May 13, 2016 23:37
@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note-label-needed labels May 13, 2016
@@ -395,7 +395,7 @@ func ValidateObjectMetaUpdate(newMeta, oldMeta *api.ObjectMeta, fldPath *field.P
allErrs = append(allErrs, ValidateImmutableField(newMeta.Namespace, oldMeta.Namespace, fldPath.Child("namespace"))...)
allErrs = append(allErrs, ValidateImmutableField(newMeta.UID, oldMeta.UID, fldPath.Child("uid"))...)
allErrs = append(allErrs, ValidateImmutableField(newMeta.CreationTimestamp, oldMeta.CreationTimestamp, fldPath.Child("creationTimestamp"))...)
allErrs = append(allErrs, ValidateImmutableField(newMeta.Finalizers, oldMeta.Finalizers, fldPath.Child("finalizers"))...)
// allErrs = append(allErrs, ValidateImmutableField(newMeta.Finalizers, oldMeta.Finalizers, fldPath.Child("finalizers"))...)
Copy link
Member Author

Choose a reason for hiding this comment

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

I'll remove the line.

Copy link
Member

Choose a reason for hiding this comment

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

remove?

@thockin thockin assigned lavalamp and unassigned thockin May 14, 2016
@caesarxuchao caesarxuchao force-pushed the orphaning-finalizer branch from d90165a to 592eb83 Compare May 15, 2016 23:53
@caesarxuchao caesarxuchao changed the title Add orphaning finalizer logic to GC [WIP] Add orphaning finalizer logic to GC May 15, 2016
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 16, 2016
fmt.Println("CHAO: e.oldObj=e.oldObj")
}
if e.oldObj == nil {
if accessor.GetDeletionTimestamp() == nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

This line handles the case where the DeletionTimestamp is set at the first time GC sees it

@caesarxuchao caesarxuchao force-pushed the orphaning-finalizer branch from 3e5a255 to cfb2bdd Compare May 16, 2016 05:12
@caesarxuchao
Copy link
Member Author

Still missing one piece of code: the API server's deletion handler needs to add the orphan finalizer if the deleteOption has Orphaning set.

@caesarxuchao caesarxuchao force-pushed the orphaning-finalizer branch 2 times, most recently from 6452d0f to 85c3284 Compare May 17, 2016 05:15
@caesarxuchao
Copy link
Member Author

One minor problem: the dynamic client cannot decode the v1.Status returned by the API server for Update call, so the gc always retries the maximum times to remove the orphan finalizer from owner's finalziers list. This is causes inefficiency, but doesn't affect the functionality.

@caesarxuchao caesarxuchao force-pushed the orphaning-finalizer branch from 4bd021a to 97ad501 Compare May 17, 2016 08:34
@caesarxuchao
Copy link
Member Author

All tests are passing locally. Some remaining work:

  1. we need to defaults the DeleteOptions.OrphanDependents to true
  2. we need to fix the dynamic client to handle the return of the Update call correctly.

I think 2 is not required for 1.3. 1 may be required, but given that we don't automatically set OwnerReferences, and we gc is default turning off, it might not be that critical. @lavalamp what do you think?

@caesarxuchao caesarxuchao added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels May 24, 2016
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 24, 2016
if delete {
out := e.NewFunc()
glog.V(6).Infof("going to delete %s from regitry, triggered by update", name)
if err := e.Storage.Delete(ctx, key, out, preconditions); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

how does finalized delete interact with graceful delete?

Copy link
Member Author

Choose a reason for hiding this comment

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

The object is deleted here only if the update request empties the finalizers and the DeletionGracePeriods is already set to 0.
So if the request just empties the finalizers, and the DeletionGracePeriods is not 0, then it will be handled as a regular update. The object will be deleted until someone sends a deletion request with DeletionGracePeriod=0.

@caesarxuchao caesarxuchao force-pushed the orphaning-finalizer branch from d45c8d8 to 4964dd3 Compare May 24, 2016 18:49
@@ -255,10 +303,10 @@ func (e *Store) Update(ctx api.Context, name string, objInfo rest.UpdatedObjectI
}

out := e.NewFunc()

var obj runtime.Object
Copy link
Member

Choose a reason for hiding this comment

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

call this deletedObj and only set it in the delete case to make it clear what should be using it outside the func

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@caesarxuchao
Copy link
Member Author

e2e failure is a flake: #26131

utilruntime.HandleError(err)
return false
}
return len(newMeta.Finalizers) == 0 && oldMeta.DeletionGracePeriodSeconds != nil && *oldMeta.DeletionGracePeriodSeconds == 0
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we also check len(oldMeta.Finalizers) > 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, that would make the apiserver non-idempotent. Here is the previous discussion: #25599 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

hmm... then this isn't really checking that this update is removing finalizers, is it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Your statement is correct. My reasoning is: If oldMeta.DeletionGracePeriodSeconds==0, and the object still exists, it could only be that the finalizers were not empty, or the apiserver had crashed, either way we should delete the object now.

…dling DeleteOptions.OrphanDependents in the API server
@caesarxuchao caesarxuchao force-pushed the orphaning-finalizer branch from 4964dd3 to 1665546 Compare May 24, 2016 20:07
@caesarxuchao caesarxuchao removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 24, 2016
@caesarxuchao
Copy link
Member Author

@k8s-oncall. It seems the merge-bot stops checking the labels after rebase, it doesn't remove the needs-rebase label nor the lgtm.

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 24, 2016
@caesarxuchao caesarxuchao added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 24, 2016
@caesarxuchao
Copy link
Member Author

I added back the lgtm after rebase to make sure this PR get in v1.3. @liggitt @lavalamp feel free to remove it if you have more concerns.

@@ -72,6 +72,7 @@ kube-apiserver
--cors-allowed-origins=[]: List of allowed origins for CORS, comma separated. An allowed origin can be a regular expression to support subdomain matching. If this list is empty CORS will not be enabled.
--delete-collection-workers=1: Number of workers spawned for DeleteCollection call. These are used to speed up namespace cleanup.
--deserialization-cache-size=50000: Number of deserialized json objects to cache in memory.
--enable-garbage-collector[=false]: Enables the generic garbage collector. MUST be synced with the corresponding flag of the kube-controller-manager.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to say something about this being an alpha feature and admins should be careful and understand the risks before setting this to true? :)

@caesarxuchao
Copy link
Member Author

@k8s-bot unit test this, issue #25967

@alex-mohr
Copy link
Contributor

alex-mohr commented May 26, 2016

Because submit queue is blocked, I'm going to kick off re-tests of the top 5 PRs in the queue, then merge them if they pass.
@k8s-bot test this please: issue #IGNORE

@caesarxuchao
Copy link
Member Author

caesarxuchao commented May 26, 2016

The node e2e error seems to be a flake:

package gopkg.in/yaml.v2: unrecognized import path "gopkg.in/yaml.v2" (https fetch: Get https://gopkg.in/yaml.v2?go-get=1: net/http: TLS handshake timeout)

@caesarxuchao
Copy link
Member Author

@k8s-bot node e2e test this, issue #IGNORE

@k8s-bot
Copy link

k8s-bot commented May 26, 2016

GCE e2e build/test passed for commit 1665546.

@caesarxuchao
Copy link
Member Author

@alex-mohr all tests passed. Could you merge? Thanks.

@erictune
Copy link
Member

erictune commented Jul 2, 2016

@caesarxuchao Does this PR require action by the user when upgrading from 1.2.x to 1.3.0? (Think about non-developer users.) If so, please edit your first comment to have a release-note block, like in #28132. If it is just an optional feature, please change the label to just release-note. If it is not a complete feature by itself, then apply "release-note-none" label instead.

@caesarxuchao caesarxuchao added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. labels Jul 2, 2016
@caesarxuchao caesarxuchao changed the title Add orphaning finalizer logic to GC [GarbageCollector] Add orphaning finalizer logic to GC Aug 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.