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 <adrianc@nvidia.com>
  • Loading branch information
adrianchiris committed Feb 19, 2024
1 parent dc8c040 commit 74729fa
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 @@ -168,11 +169,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 74729fa

Please sign in to comment.