@@ -33,8 +33,8 @@ import (
33
33
var log = logf .RuntimeLog .WithName ("source" ).WithName ("EventHandler" )
34
34
35
35
// NewEventHandler creates a new EventHandler.
36
- func NewEventHandler (ctx context.Context , queue workqueue.RateLimitingInterface , handler handler.EventHandler , predicates []predicate.Predicate ) * EventHandler {
37
- return & EventHandler {
36
+ func NewEventHandler [ T client. Object ] (ctx context.Context , queue workqueue.RateLimitingInterface , handler handler.EventHandler , predicates []predicate.Predicate ) * EventHandler [ T ] {
37
+ return & EventHandler [ T ] {
38
38
ctx : ctx ,
39
39
handler : handler ,
40
40
queue : queue ,
@@ -43,7 +43,7 @@ func NewEventHandler(ctx context.Context, queue workqueue.RateLimitingInterface,
43
43
}
44
44
45
45
// EventHandler adapts a handler.EventHandler interface to a cache.ResourceEventHandler interface.
46
- type EventHandler struct {
46
+ type EventHandler [ T client. Object ] struct {
47
47
// ctx stores the context that created the event handler
48
48
// that is used to propagate cancellation signals to each handler function.
49
49
ctx context.Context
@@ -55,7 +55,7 @@ type EventHandler struct {
55
55
56
56
// HandlerFuncs converts EventHandler to a ResourceEventHandlerFuncs
57
57
// TODO: switch to ResourceEventHandlerDetailedFuncs with client-go 1.27
58
- func (e * EventHandler ) HandlerFuncs () cache.ResourceEventHandlerFuncs {
58
+ func (e * EventHandler [ T ] ) HandlerFuncs () cache.ResourceEventHandlerFuncs {
59
59
return cache.ResourceEventHandlerFuncs {
60
60
AddFunc : e .OnAdd ,
61
61
UpdateFunc : e .OnUpdate ,
@@ -64,11 +64,11 @@ func (e *EventHandler) HandlerFuncs() cache.ResourceEventHandlerFuncs {
64
64
}
65
65
66
66
// OnAdd creates CreateEvent and calls Create on EventHandler.
67
- func (e * EventHandler ) OnAdd (obj interface {}) {
67
+ func (e * EventHandler [ T ] ) OnAdd (obj interface {}) {
68
68
c := event.CreateEvent {}
69
69
70
70
// Pull Object out of the object
71
- if o , ok := obj .(client. Object ); ok {
71
+ if o , ok := obj .(T ); ok {
72
72
c .Object = o
73
73
} else {
74
74
log .Error (nil , "OnAdd missing Object" ,
@@ -89,10 +89,10 @@ func (e *EventHandler) OnAdd(obj interface{}) {
89
89
}
90
90
91
91
// OnUpdate creates UpdateEvent and calls Update on EventHandler.
92
- func (e * EventHandler ) OnUpdate (oldObj , newObj interface {}) {
92
+ func (e * EventHandler [ T ] ) OnUpdate (oldObj , newObj interface {}) {
93
93
u := event.UpdateEvent {}
94
94
95
- if o , ok := oldObj .(client. Object ); ok {
95
+ if o , ok := oldObj .(T ); ok {
96
96
u .ObjectOld = o
97
97
} else {
98
98
log .Error (nil , "OnUpdate missing ObjectOld" ,
@@ -101,7 +101,7 @@ func (e *EventHandler) OnUpdate(oldObj, newObj interface{}) {
101
101
}
102
102
103
103
// Pull Object out of the object
104
- if o , ok := newObj .(client. Object ); ok {
104
+ if o , ok := newObj .(T ); ok {
105
105
u .ObjectNew = o
106
106
} else {
107
107
log .Error (nil , "OnUpdate missing ObjectNew" ,
@@ -122,7 +122,7 @@ func (e *EventHandler) OnUpdate(oldObj, newObj interface{}) {
122
122
}
123
123
124
124
// OnDelete creates DeleteEvent and calls Delete on EventHandler.
125
- func (e * EventHandler ) OnDelete (obj interface {}) {
125
+ func (e * EventHandler [ T ] ) OnDelete (obj interface {}) {
126
126
d := event.DeleteEvent {}
127
127
128
128
// Deal with tombstone events by pulling the object out. Tombstone events wrap the object in a
@@ -131,7 +131,7 @@ func (e *EventHandler) OnDelete(obj interface{}) {
131
131
// This should never happen if we aren't missing events, which we have concluded that we are not
132
132
// and made decisions off of this belief. Maybe this shouldn't be here?
133
133
var ok bool
134
- if _ , ok = obj .(client. Object ); ! ok {
134
+ if _ , ok = obj .(T ); ! ok {
135
135
// If the object doesn't have Metadata, assume it is a tombstone object of type DeletedFinalStateUnknown
136
136
tombstone , ok := obj .(cache.DeletedFinalStateUnknown )
137
137
if ! ok {
@@ -149,7 +149,7 @@ func (e *EventHandler) OnDelete(obj interface{}) {
149
149
}
150
150
151
151
// Pull Object out of the object
152
- if o , ok := obj .(client. Object ); ok {
152
+ if o , ok := obj .(T ); ok {
153
153
d .Object = o
154
154
} else {
155
155
log .Error (nil , "OnDelete missing Object" ,
0 commit comments