-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Fix cascading delete #48138
Fix cascading delete #48138
Conversation
Hi @FengyunPan. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with I understand the commands that are listed here. 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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: FengyunPan Assign the PR to them by writing No associated issue. Update pull-request body to add a reference to an issue, or get approval with 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 |
/unassign |
/assign @nikhiljindal @caesarxuchao |
Sorry, i'll take a look after release 1.7 ships. |
if err != nil { | ||
c.tl.Fatalf("Error deleting federated %s %q: %v", c.kind, namespacedName, err) | ||
} | ||
|
||
deletingInCluster := (orphanDependents != nil && *orphanDependents == false) | ||
deletingInCluster := defaultPropagationPolicy != nil && *defaultPropagationPolicy == "Foreground" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. && *defaultPropagationPolicy == metav1.DeletePropagationForeground
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thank you.
cee5f16
to
78ed5d5
Compare
/ok-to-test |
@@ -186,8 +186,10 @@ func NewDeploymentController(federationClient fedclientset.Interface) *Deploymen | |||
}, | |||
func(client kubeclientset.Interface, obj runtime.Object) error { | |||
rs := obj.(*extensionsv1.Deployment) | |||
orphanDependents := false | |||
err := client.Extensions().Deployments(rs.Namespace).Delete(rs.Name, &metav1.DeleteOptions{OrphanDependents: &orphanDependents}) | |||
defaultPropagationPolicy := metav1.DeletePropagationForeground |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe s/defaultPropagationPolicy/policy? I don't see why it's called "default".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nikhiljindal is the federation control plane going to support both "foreground" and "background" gc? If so, an option should be passed into this function.
Actually if the federation control plane is going to support "background" GC, it could still deletes underlying resources with "ForegroundPropagtionPolicy", it only needs to remove the federation resource immediately. That's a separate issue anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orphanDependents := false
client.Extensions().Deployments(rs.Namespace).Delete(rs.Name, metav1.DeleteOptions{OrphanDependents: &orphanDependents})
Actually, the code can't cascade the deletion of deployment's pods. I will check it later.
@FengyunPan i don't think this claim is true. The underlying objects are deleted with orphan=false, so they and their dependents will be garbage collected, in the background. That said, i think using |
The 'kubectl delete deployment xxx' work fine, it called "m.RESTClient.Delete(). |
There should be comment on the types. The failed cascading deletion was fixed by #44058. |
78ed5d5
to
eed5b96
Compare
@caesarxuchao Thank you, I have update the comment and PR. |
orphanedDependents := true | ||
testCases := map[string]*bool{ | ||
"Resource should not be deleted from underlying clusters when OrphanDependents is true": &orphanedDependents, | ||
"Resource should not be deleted from underlying clusters when OrphanDependents is nil": nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you remove this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, sorry, after reading the federation code again, I find that the federation apiserver use DeletionOptions.OrphanDependents to delete federation-resource and cluster-resource, so update the case until federation-apiserver don't use OrphanDependents.
One nit, otherwise lgtm. |
0a7176f
to
3260752
Compare
// May need extra time to delete both federation and cluster resources | ||
waitTimeout = c.clusterWaitTimeout | ||
} | ||
waitTimeout := ForeverTimeout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the right clusterWaitTimeout in
return crudtester.NewFederatedTypeCRUDTester(logger, adapter, clusterClients, DefaultWaitInterval, wait.ForeverTestTimeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I will update it.
} | ||
waitTimeout := ForeverTimeout | ||
//if deletingInCluster { | ||
// // May need extra time to delete both federation and cluster resources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete unused code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -155,7 +160,7 @@ func (c *FederatedTypeCRUDTester) CheckDelete(obj pkgruntime.Object, orphanDepen | |||
return false, err | |||
}) | |||
if err != nil { | |||
c.tl.Fatalf("Error deleting federated %s %q: %v", c.kind, qualifiedName, err) | |||
c.tl.Fatalf("Error deleting federated %s %q in %s: %v", c.kind, qualifiedName, waitTimeout, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%s seconds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The waitTimeout contains unit.
// and deletion helper does a cascading deletion. | ||
// If user deletes the resource with nil DeleteOptions or DeletionOptions.OrphanDependents = true, | ||
// then the federation controllerManager just delete fed-resource. | ||
// if user deletes the resource with DeletionOptions.OrphanDependents = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be OrphanDependents = false here instead of true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, done.
// DeletionOptions.OrphanDependents = true then the apiserver removes the orphan finalizer | ||
// and deletion helper does a cascading deletion. | ||
// If user deletes the resource with nil DeleteOptions or DeletionOptions.OrphanDependents = true, | ||
// then the federation controllerManager just delete fed-resource. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
controllerManager -> controller manager.
delete -> deletes
fed-resource -> federation resource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for fixing it
// then the federation controllerManager just delete fed-resource. | ||
// if user deletes the resource with DeletionOptions.OrphanDependents = true, | ||
// then the federation apiserver removes the orphan finalizer and deletion helper | ||
// does a cascading deletion(delete fed-resource and delete cluster-resource). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does a cascading deletion (deletes federation resource and cluster resources).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@nikhiljindal Deleting federation deployment and cluster deployment(contains rs and pod) is my PR's purpose. Actrually, after deleting federation deployment with OrphanDependents = false, the pods of federation deployment was left behind. Is it need to add Foreground PropagationPolicy into DeleteOptions? |
aah thanks for explaining that. I looked at the code again and we are only changing the DELETE request that is sent to clusters, we are now setting PropagationPolicy to Foreground. This is not changing the DELETE request that is sent to federation apiserver by federation controller, hence my comment above is not valid. This looks good to me. Will add lgtm label, once the open comments have been fixed. |
8e958ef
to
2f8bd9e
Compare
2f8bd9e
to
b763678
Compare
3913acb
to
5a98fbc
Compare
/test pull-kubernetes-unit |
/retest |
5a98fbc
to
1fffdee
Compare
@nikhiljindal Hi, can you help me? I just use PropagationPolicy for deleting cluster resource and didn't update the deletion of federation resource. Why the test case times out? |
Which test case is timing out? Before this change, deletion of dependent resources in underlying clusters was happening in background. For ex: while deleting federated deployment, federated controller was deleting deployment from underlying cluster such that it does not wait for replicasets and pods to be deleted (they were being deleted later in the background, without blocking deployment deletion). With this change, deployment deletion in underlying cluster will wait for replicasets and pods deletion. So it is expected to take some more time than before. |
@nikhiljindal This case is timing out: k8s.io/kubernetes/test/integration/federation -run TestFederationCRUD I change more time for this case later. |
10c4242
to
c537d32
Compare
After deleting federation deployment with OrphanDependents=false, the pods of federation deployment was left behind. Kubernetes 1.6 adds a PropagationPolicy to the delete options, obsoleting the previous OrphanDependents boolean. This PR sets PropagationPolicy=foreground instead of OrphanDependents=false when federation controller manager delete cluster resource.
c537d32
to
3c3d638
Compare
/test pull-kubernetes-bazel |
/retest |
@FengyunPan: The following test failed, say
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. |
@FengyunPan PR needs rebase |
This PR hasn't been active in 90 days. Closing this PR. Please reopen if you would like to work towards merging this change, if/when the PR is ready for the next round of review. cc @FengyunPan @caesarxuchao @colhom @nikhiljindal You can add 'keep-open' label to prevent this from happening again, or add a comment to keep it open another 90 days |
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://github.com/kubernetes/kubernetes/wiki/CLA-FAQ to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
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. |
Kubernetes 1.6 adds a PropagationPolicy to the delete options,
obsoleting the previous OrphanDependents boolean. This PR sets
PropagationPolicy=foreground instead of OrphanDependents=false
when federation controller manager delete cluster resource.
@caesarxuchao ptal
Release note: