Skip to content

Commit

Permalink
Update to support the TypedEventHandler interface
Browse files Browse the repository at this point in the history
Related upstream change:
 - kubernetes-sigs/controller-runtime#2799
  • Loading branch information
benashz committed Oct 4, 2024
1 parent 83a8217 commit 5101df3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
30 changes: 15 additions & 15 deletions controllers/eventhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ type enqueueRefRequestsHandler struct {
}

func (e *enqueueRefRequestsHandler) Create(ctx context.Context,
evt event.CreateEvent, q workqueue.RateLimitingInterface,
evt event.CreateEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request],
) {
e.enqueue(ctx, q, evt.Object)
}

func (e *enqueueRefRequestsHandler) Update(ctx context.Context,
evt event.UpdateEvent, q workqueue.RateLimitingInterface,
evt event.UpdateEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request],
) {
if evt.ObjectOld == nil {
return
Expand All @@ -73,19 +73,19 @@ func (e *enqueueRefRequestsHandler) Update(ctx context.Context,
}
}

func (e *enqueueRefRequestsHandler) Delete(ctx context.Context,
evt event.DeleteEvent, _ workqueue.RateLimitingInterface,
func (e *enqueueRefRequestsHandler) Delete(_ context.Context,
evt event.DeleteEvent, _ workqueue.TypedRateLimitingInterface[reconcile.Request],
) {
e.refCache.Prune(e.kind, client.ObjectKeyFromObject(evt.Object))
}

func (e *enqueueRefRequestsHandler) Generic(ctx context.Context,
_ event.GenericEvent, _ workqueue.RateLimitingInterface,
func (e *enqueueRefRequestsHandler) Generic(_ context.Context,
_ event.GenericEvent, _ workqueue.TypedRateLimitingInterface[reconcile.Request],
) {
}

func (e *enqueueRefRequestsHandler) enqueue(ctx context.Context,
q workqueue.RateLimitingInterface, o client.Object,
q workqueue.TypedRateLimitingInterface[reconcile.Request], o client.Object,
) {
logger := log.FromContext(ctx).WithName(
"enqueueRefRequestsHandler").
Expand Down Expand Up @@ -138,17 +138,17 @@ type enqueueOnDeletionRequestHandler struct {
}

func (e *enqueueOnDeletionRequestHandler) Create(_ context.Context,
_ event.CreateEvent, _ workqueue.RateLimitingInterface,
_ event.CreateEvent, _ workqueue.TypedRateLimitingInterface[reconcile.Request],
) {
}

func (e *enqueueOnDeletionRequestHandler) Update(_ context.Context,
_ event.UpdateEvent, _ workqueue.RateLimitingInterface,
_ event.UpdateEvent, _ workqueue.TypedRateLimitingInterface[reconcile.Request],
) {
}

func (e *enqueueOnDeletionRequestHandler) Delete(ctx context.Context,
evt event.DeleteEvent, q workqueue.RateLimitingInterface,
evt event.DeleteEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request],
) {
logger := log.FromContext(ctx).WithName("enqueueOnDeletionRequestHandler").
WithValues("ownerGVK", e.gvk)
Expand Down Expand Up @@ -179,7 +179,7 @@ func (e *enqueueOnDeletionRequestHandler) Delete(ctx context.Context,
}

func (e *enqueueOnDeletionRequestHandler) Generic(ctx context.Context,
_ event.GenericEvent, _ workqueue.RateLimitingInterface,
_ event.GenericEvent, _ workqueue.TypedRateLimitingInterface[reconcile.Request],
) {
}

Expand All @@ -189,16 +189,16 @@ type enqueueDelayingSyncEventHandler struct {
enqueueDurationForJitter time.Duration
}

func (e *enqueueDelayingSyncEventHandler) Create(_ context.Context, _ event.CreateEvent, _ workqueue.RateLimitingInterface) {
func (e *enqueueDelayingSyncEventHandler) Create(_ context.Context, _ event.CreateEvent, _ workqueue.TypedRateLimitingInterface[reconcile.Request]) {
}

func (e *enqueueDelayingSyncEventHandler) Update(_ context.Context, _ event.UpdateEvent, _ workqueue.RateLimitingInterface) {
func (e *enqueueDelayingSyncEventHandler) Update(_ context.Context, _ event.UpdateEvent, _ workqueue.TypedRateLimitingInterface[reconcile.Request]) {
}

func (e *enqueueDelayingSyncEventHandler) Delete(_ context.Context, _ event.DeleteEvent, _ workqueue.RateLimitingInterface) {
func (e *enqueueDelayingSyncEventHandler) Delete(_ context.Context, _ event.DeleteEvent, _ workqueue.TypedRateLimitingInterface[reconcile.Request]) {
}

func (e *enqueueDelayingSyncEventHandler) Generic(ctx context.Context, evt event.GenericEvent, q workqueue.RateLimitingInterface) {
func (e *enqueueDelayingSyncEventHandler) Generic(ctx context.Context, evt event.GenericEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
logger := log.FromContext(ctx).WithName("enqueueDelayingSyncEventHandler")
if evt.Object == nil {
logger.Error(nil,
Expand Down
58 changes: 29 additions & 29 deletions controllers/eventhandlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func Test_enqueueRefRequestsHandler_Create(t *testing.T) {
refCache: cache,
createEvents: createEvents,
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
wantAddedAfter: wantAddedAfterValid,
maxRequeueAfter: time.Second * 10,
Expand All @@ -122,7 +122,7 @@ func Test_enqueueRefRequestsHandler_Create(t *testing.T) {
refCache: cache,
createEvents: createEvents,
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
wantAddedAfter: wantAddedAfterValid,
wantRefCache: cache,
Expand All @@ -133,7 +133,7 @@ func Test_enqueueRefRequestsHandler_Create(t *testing.T) {
refCache: cache,
createEvents: createEvents,
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
wantAddedAfter: wantAddedAfterValid,
maxRequeueAfter: time.Second * -1,
Expand All @@ -146,7 +146,7 @@ func Test_enqueueRefRequestsHandler_Create(t *testing.T) {
createEvents: createEvents,
validator: &validatorFunc{},
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
wantValidObjects: []client.Object{
createEvent.Object,
Expand All @@ -162,7 +162,7 @@ func Test_enqueueRefRequestsHandler_Create(t *testing.T) {
createEvents: createEvents,
validator: &validatorFunc{},
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
wantInvalidObjects: []client.Object{
createEvent.Object,
Expand All @@ -178,7 +178,7 @@ func Test_enqueueRefRequestsHandler_Create(t *testing.T) {
},
createEvents: createEvents,
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
},
}
Expand Down Expand Up @@ -250,7 +250,7 @@ func Test_enqueueRefRequestsHandler_Update(t *testing.T) {
refCache: cache,
updateEvents: updateEventsEnqueue,
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
wantAddedAfter: wantAddedAfterValid,
wantRefCache: cache,
Expand All @@ -262,7 +262,7 @@ func Test_enqueueRefRequestsHandler_Update(t *testing.T) {
updateEvents: updateEventsEnqueue,
validator: &validatorFunc{},
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
wantValidObjects: []client.Object{
objectNew,
Expand All @@ -278,7 +278,7 @@ func Test_enqueueRefRequestsHandler_Update(t *testing.T) {
updateEvents: updateEventsEnqueue,
validator: &validatorFunc{},
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
wantInvalidObjects: []client.Object{
objectNew,
Expand All @@ -294,7 +294,7 @@ func Test_enqueueRefRequestsHandler_Update(t *testing.T) {
},
updateEvents: updateEventsEnqueue,
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
},
{
Expand All @@ -303,7 +303,7 @@ func Test_enqueueRefRequestsHandler_Update(t *testing.T) {
refCache: cache,
updateEvents: updateEventsNoEnqueue,
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
},
}
Expand Down Expand Up @@ -353,7 +353,7 @@ func Test_enqueueRefRequestsHandler_Delete(t *testing.T) {
kind: SecretTransformation,
refCache: cache,
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
deleteEvents: []event.DeleteEvent{
{
Expand All @@ -369,7 +369,7 @@ func Test_enqueueRefRequestsHandler_Delete(t *testing.T) {
kind: SecretTransformation,
refCache: cache,
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
deleteEvents: []event.DeleteEvent{
{
Expand All @@ -383,7 +383,7 @@ func Test_enqueueRefRequestsHandler_Delete(t *testing.T) {
kind: SecretTransformation,
refCache: cache,
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
deleteEvents: []event.DeleteEvent{
{
Expand Down Expand Up @@ -469,29 +469,29 @@ func assertEnqueueRefRequestHandler(t *testing.T, ctx context.Context, tt testCa
}
}

var _ workqueue.RateLimitingInterface = &DelegatingQueue{}
var _ workqueue.TypedRateLimitingInterface[reconcile.Request] = &DelegatingQueue{}

type DelegatingQueue struct {
workqueue.Interface
workqueue.TypedRateLimitingInterface[reconcile.Request]
mu sync.Mutex
AddedAfter []any
AddedAfterDuration []time.Duration
}

// AddAfter implements RateLimitingInterface.
func (q *DelegatingQueue) AddAfter(item interface{}, d time.Duration) {
func (q *DelegatingQueue) AddAfter(item reconcile.Request, d time.Duration) {
q.mu.Lock()
defer q.mu.Unlock()
q.AddedAfter = append(q.AddedAfter, item)
q.AddedAfterDuration = append(q.AddedAfterDuration, d)
q.Add(item)
}

func (q *DelegatingQueue) AddRateLimited(item interface{}) {}
func (q *DelegatingQueue) AddRateLimited(item reconcile.Request) {}

func (q *DelegatingQueue) Forget(item interface{}) {}
func (q *DelegatingQueue) Forget(item reconcile.Request) {}

func (q *DelegatingQueue) NumRequeues(item interface{}) int {
func (q *DelegatingQueue) NumRequeues(item reconcile.Request) int {
return 0
}

Expand Down Expand Up @@ -553,7 +553,7 @@ func Test_enqueueOnDeletionRequestHandler_Delete(t *testing.T) {
deleteEventSupported,
},
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
gvk: gvk,
wantAddedAfter: wantAddedAfterValid,
Expand All @@ -567,7 +567,7 @@ func Test_enqueueOnDeletionRequestHandler_Delete(t *testing.T) {
deleteEventSupported,
},
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
gvk: gvk,
wantAddedAfter: wantAddedAfterValid,
Expand All @@ -581,7 +581,7 @@ func Test_enqueueOnDeletionRequestHandler_Delete(t *testing.T) {
deleteEventSupported,
},
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
gvk: gvk,
wantAddedAfter: wantAddedAfterValid,
Expand All @@ -594,7 +594,7 @@ func Test_enqueueOnDeletionRequestHandler_Delete(t *testing.T) {
deleteEventSupported,
},
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
gvk: gvk,
wantAddedAfter: wantAddedAfterValid,
Expand All @@ -607,7 +607,7 @@ func Test_enqueueOnDeletionRequestHandler_Delete(t *testing.T) {
deleteEventUnsupported,
},
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
gvk: gvk,
},
Expand Down Expand Up @@ -671,7 +671,7 @@ func Test_enqueueOnDeletionRequestHandler_Create(t *testing.T) {
createEvent,
},
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
gvk: gvk,
wantAddedAfter: nil,
Expand All @@ -683,7 +683,7 @@ func Test_enqueueOnDeletionRequestHandler_Create(t *testing.T) {
createEventUnsupported,
},
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
gvk: gvk,
wantAddedAfter: nil,
Expand Down Expand Up @@ -767,7 +767,7 @@ func Test_enqueueOnDeletionRequestHandler_Update(t *testing.T) {
updateEvent,
},
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
gvk: gvk,
wantAddedAfter: nil,
Expand All @@ -779,7 +779,7 @@ func Test_enqueueOnDeletionRequestHandler_Update(t *testing.T) {
updateEventUnsupported,
},
q: &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
},
gvk: gvk,
wantAddedAfter: nil,
Expand Down
4 changes: 2 additions & 2 deletions controllers/vaultdynamicsecret_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ func Test_computeRelativeHorizonWithJitter(t *testing.T) {
},
minHorizon: 1 * time.Second,
wantMinHorizon: time.Duration(.8 * float64(time.Second)),
wantMaxHorizon: time.Duration(1 * time.Second),
wantMaxHorizon: 1 * time.Second,
wantInWindow: true,
},
}
Expand Down Expand Up @@ -1157,7 +1157,7 @@ func TestVaultDynamicSecretReconciler_vaultClientCallback(t *testing.T) {
cs := source.Channel(r.SourceCh, handler)

q := &DelegatingQueue{
Interface: workqueue.New(),
TypedRateLimitingInterface: workqueue.NewTypedRateLimitingQueue[reconcile.Request](nil),
}

go func() {
Expand Down

0 comments on commit 5101df3

Please sign in to comment.