Skip to content

Commit

Permalink
Send intial sync event to sriovnetworknodepolicy controller
Browse files Browse the repository at this point in the history
Since default policy is not created by operator we should trigger
an initial reconcile to allow the creation of sriovnetworknodestate
objects as webhook uses these objects to validate policy.

Signed-off-by: adrianc <[email protected]>
  • Loading branch information
adrianchiris committed Feb 7, 2024
1 parent b456304 commit 32dcfce
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions controllers/sriovnetworknodepolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

utils "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vars"
Expand Down Expand Up @@ -164,11 +165,23 @@ func (r *SriovNetworkNodePolicyReconciler) SetupWithManager(mgr ctrl.Manager) er
Info("Enqueuing sync for delete event", "resource", e.Object.GetName())
qHandler(q)
},
GenericFunc: func(ctx context.Context, e event.GenericEvent, q workqueue.RateLimitingInterface) {
log.Log.WithName("SriovNetworkNodePolicy").
Info("Enqueuing sync for generic event", "resource", e.Object.GetName())
qHandler(q)
},
}

// send initial sync event to trigger reconcile when controller is started
var eventChan = make(chan event.GenericEvent, 1)
eventChan <- event.GenericEvent{Object: &sriovnetworkv1.SriovNetworkNodePolicy{
ObjectMeta: metav1.ObjectMeta{Name: nodePolicySyncEventName, Namespace: ""}}}
close(eventChan)

return ctrl.NewControllerManagedBy(mgr).
For(&sriovnetworkv1.SriovNetworkNodePolicy{}).
Watches(&sriovnetworkv1.SriovNetworkNodePolicy{}, delayedEventHandler).
WatchesRawSource(&source.Channel{Source: eventChan}, delayedEventHandler).
Complete(r)
}

Expand Down

0 comments on commit 32dcfce

Please sign in to comment.