Skip to content

Commit

Permalink
Merge pull request #48112 from caesarxuchao/automated-cherry-pick-of-…
Browse files Browse the repository at this point in the history
…#44058-upstream-release-1.7

Automatic merge from submit-queue

Automated cherry pick of #44058

Cherry pick of #44058 on release-1.7.

#44058: revert 45764
  • Loading branch information
Kubernetes Submit Queue authored Jun 27, 2017
2 parents dc45986 + b9da399 commit b4d1ea1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
14 changes: 3 additions & 11 deletions pkg/controller/controller_ref_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,24 +341,16 @@ func (m *ReplicaSetControllerRefManager) ClaimReplicaSets(sets []*extensions.Rep
return claimed, utilerrors.NewAggregate(errlist)
}

// AdoptReplicaSet sends a patch to take control of the ReplicaSet and also
// sets the finalizers to foregroundDeletion. It returns the error if
// the patching fails.
// AdoptReplicaSet sends a patch to take control of the ReplicaSet. It returns
// the error if the patching fails.
func (m *ReplicaSetControllerRefManager) AdoptReplicaSet(rs *extensions.ReplicaSet) error {
if err := m.canAdopt(); err != nil {
return fmt.Errorf("can't adopt ReplicaSet %v/%v (%v): %v", rs.Namespace, rs.Name, rs.UID, err)
}
// Note that ValidateOwnerReferences() will reject this patch if another
// OwnerReference exists with controller=true.
addControllerPatch := fmt.Sprintf(
`{
"metadata":
{
"ownerReferences": [{"apiVersion":"%s","kind":"%s","name":"%s","uid":"%s","controller":true,"blockOwnerDeletion":true}],
"uid":"%s",
"finalizers": ["foregroundDeletion"]
}
}`,
`{"metadata":{"ownerReferences":[{"apiVersion":"%s","kind":"%s","name":"%s","uid":"%s","controller":true,"blockOwnerDeletion":true}],"uid":"%s"}}`,
m.controllerKind.GroupVersion(), m.controllerKind.Kind,
m.controller.GetName(), m.controller.GetUID(), rs.UID)
return m.rsControl.PatchReplicaSet(rs.Namespace, rs.Name, []byte(addControllerPatch))
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/deployment/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ func (dc *DeploymentController) getNewReplicaSet(d *extensions.Deployment, rsLis
Name: d.Name + "-" + podTemplateSpecHash,
Namespace: d.Namespace,
OwnerReferences: []metav1.OwnerReference{*newControllerRef(d)},
Finalizers: []string{metav1.FinalizerDeleteDependents},
},
Spec: extensions.ReplicaSetSpec{
Replicas: new(int32),
Expand Down
20 changes: 16 additions & 4 deletions pkg/controller/garbagecollector/garbagecollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,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 @@ -375,9 +375,21 @@ 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 set propagationPolicy based on existing finalizers.
var policy metav1.DeletionPropagation
switch {
case hasOrphanFinalizer(latest):
// if an existing orphan finalizer is already on the object, honor it.
policy = metav1.DeletePropagationOrphan
case hasDeleteDependentsFinalizer(latest):
// if an existing foreground finalizer is already on the object, honor it.
policy = metav1.DeletePropagationForeground
default:
// otherwise, default to background.
policy = metav1.DeletePropagationBackground
}
glog.V(2).Infof("delete object %s with propagation policy %s", item.identity, policy)
return gc.deleteObject(item.identity, &policy)
}
}

Expand Down

0 comments on commit b4d1ea1

Please sign in to comment.