Skip to content

Commit

Permalink
Don't assume that finalizers are worked on in a serial manner
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr committed Dec 1, 2017
1 parent 4d5c39e commit 1d7fc12
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,12 @@ func VirtualMachineKeys(vms []*v1.VirtualMachine) []string {
}
return keys
}

func HasFinalizer(object metav1.Object, finalizer string) bool {
for _, f := range object.GetFinalizers() {
if f == finalizer {
return true
}
}
return false
}
3 changes: 3 additions & 0 deletions pkg/controller/controller_ref_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Taken from https://github.com/kubernetes/kubernetes/blob/b28a83a4cf779189d72a87e847441888e7918e5d/pkg/controller/controller_ref_manager.go
and adapted for KubeVirt.
*/

package controller
Expand Down
3 changes: 2 additions & 1 deletion pkg/virt-controller/watch/replicaset.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (c *VMReplicaSet) execute(key string) error {
}

// If the controller is going to be deleted and the orphan finalizer is the next one, release the VMs. Don't update the status
if rs.ObjectMeta.DeletionTimestamp != nil && len(rs.ObjectMeta.Finalizers) > 0 && rs.ObjectMeta.Finalizers[0] == v1.FinalizerOrphanDependents {
if rs.ObjectMeta.DeletionTimestamp != nil && controller.HasFinalizer(rs, v1.FinalizerOrphanDependents) {
return c.orphan(cm, rs, vms)
}

Expand All @@ -231,6 +231,7 @@ func (c *VMReplicaSet) execute(key string) error {

// orphan removes the owner reference of all VMs which are owned by the controller instance.
// Workaround for https://github.com/kubernetes/kubernetes/issues/56348 to make no-cascading deletes possible
// We don't have to remove the finalizer. This part of the gc is not affected by the mentioned bug
func (c *VMReplicaSet) orphan(cm *controller.VirtualMachineControllerRefManager, rs *virtv1.VirtualMachineReplicaSet, vms []*virtv1.VirtualMachine) error {

var wg sync.WaitGroup
Expand Down

0 comments on commit 1d7fc12

Please sign in to comment.