Skip to content

Commit

Permalink
cascading background deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Xu committed Apr 4, 2017
1 parent 95289ff commit 4cd9d04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
9 changes: 5 additions & 4 deletions pkg/controller/garbagecollector/garbagecollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (gc *GarbageCollector) attemptToDeleteItem(item *node) error {
break
}
}
glog.V(2).Infof("at least one owner of object %s has FinalizerDeletingDependents, and the object itself has dependents, so it is going to be deleted with Foreground", item.identity)
glog.V(2).Infof("at least one owner of object %s has FinalizerDeletingDependents, and the object itself has dependents, so it is going to be deleted in Foreground", item.identity)
// the deletion event will be observed by the graphBuilder, so the item
// will be processed again in processDeletingDependentsItem. If it
// doesn't have dependents, the function will remove the
Expand All @@ -358,9 +358,10 @@ func (gc *GarbageCollector) attemptToDeleteItem(item *node) error {
default:
// item doesn't have any solid owner, so it needs to be garbage
// collected. Also, none of item's owners is waiting for the deletion of
// the dependents, so GC deletes item with Default.
glog.V(2).Infof("delete object %s with Default", item.identity)
return gc.deleteObject(item.identity, nil)
// the dependents, so GC deletes item in Background.
glog.V(2).Infof("delete object %s in Background", item.identity)
policy := metav1.DeletePropagationBackground
return gc.deleteObject(item.identity, &policy)
}
}

Expand Down
21 changes: 14 additions & 7 deletions test/e2e/garbage_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,24 @@ func newOwnerRC(f *framework.Framework, name string, replicas int32) *v1.Replica
}
}

// verifyRemainingDeploymentsAndReplicaSets verifies if the number
// of the remaining deployment and rs are deploymentNum and rsNum.
// verifyDeploymentRSPods verifies if the number
// of the remaining deployment, rs and pods are deploymentNum, rsNum and podNum.
// It returns error if the communication with the API server fails.
func verifyRemainingDeploymentsAndReplicaSets(
func verifyDeploymentRSPods(
f *framework.Framework,
clientSet clientset.Interface,
deployment *v1beta1.Deployment,
deploymentNum, rsNum int,
deploymentNum, rsNum int, podNum int,
) (bool, error) {
var ret = true
pods, err := clientSet.Core().Pods(f.Namespace.Name).List(metav1.ListOptions{})
if err != nil {
return false, fmt.Errorf("Failed to list pods: %v", err)
}
if len(pods.Items) != podNum {
ret = false
By(fmt.Sprintf("expected %d pods, got %d pods", podNum, len(pods.Items)))
}
rs, err := clientSet.Extensions().ReplicaSets(f.Namespace.Name).List(metav1.ListOptions{})
if err != nil {
return false, fmt.Errorf("Failed to list rs: %v", err)
Expand Down Expand Up @@ -397,7 +405,7 @@ var _ = framework.KubeDescribe("Garbage collector", func() {
}
By("wait for all rs to be garbage collected")
err = wait.PollImmediate(500*time.Millisecond, 1*time.Minute, func() (bool, error) {
return verifyRemainingDeploymentsAndReplicaSets(f, clientSet, deployment, 0, 0)
return verifyDeploymentRSPods(f, clientSet, deployment, 0, 0, 0)
})
if err == wait.ErrWaitTimeout {
err = fmt.Errorf("Failed to wait for all rs to be garbage collected: %v", err)
Expand All @@ -407,7 +415,6 @@ var _ = framework.KubeDescribe("Garbage collector", func() {
} else {
framework.Failf("remaining rs are: %#v", remainingRSs)
}

}

gatherMetrics(f)
Expand Down Expand Up @@ -446,7 +453,7 @@ var _ = framework.KubeDescribe("Garbage collector", func() {
}
By("wait for 2 Minute to see if the garbage collector mistakenly deletes the rs")
err = wait.PollImmediate(5*time.Second, 2*time.Minute, func() (bool, error) {
return verifyRemainingDeploymentsAndReplicaSets(f, clientSet, deployment, 0, 1)
return verifyDeploymentRSPods(f, clientSet, deployment, 0, 1, 2)
})
if err != nil {
err = fmt.Errorf("Failed to wait to see if the garbage collecter mistakenly deletes the rs: %v", err)
Expand Down

0 comments on commit 4cd9d04

Please sign in to comment.