Skip to content

Commit da93795

Browse files
fwieselnotandy
authored andcommitted
Switch Hypervisor from ControllerReference to OwnerReference
ControllerReference is 'for reconciling the owner object on changes to controlled (with a Watch + EnqueueRequestForOwner)'. Since we do not want to reconcile the node on changes to the hypervisor, we are fine with OwnerReference. The WithBlockOwnerDeletion ensures that the node is only deleted, when the hypervisor resource also has been deleted. For now, it is only avoiding a theoretical race conditition of the node coming back before the hypervisor has been removed, and annotations / labels not getting propagated. It also sets the stage for moving the finalizer out of the node, and doing that on the hypervisor resource instead.
1 parent 74a5805 commit da93795

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

internal/controller/hypervisor_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (hv *HypervisorController) Reconcile(ctx context.Context, req ctrl.Request)
153153
})
154154
}
155155

156-
if err := controllerutil.SetControllerReference(node, hypervisor, hv.Scheme); err != nil {
156+
if err := controllerutil.SetOwnerReference(node, hypervisor, hv.Scheme, controllerutil.WithBlockOwnerDeletion(true)); err != nil {
157157
return ctrl.Result{}, fmt.Errorf("failed setting controller reference: %w", err)
158158
}
159159

@@ -180,7 +180,6 @@ func (hv *HypervisorController) SetupWithManager(mgr ctrl.Manager) error {
180180

181181
return ctrl.NewControllerManagedBy(mgr).
182182
For(&corev1.Node{}).
183-
Owns(&kvmv1.Hypervisor{}).
184183
WithEventFilter(novaVirtLabeledPredicate).
185184
Complete(hv)
186185
}

0 commit comments

Comments
 (0)