@@ -24,6 +24,10 @@ import (
24
24
"sigs.k8s.io/controller-runtime/pkg/runtime/inject"
25
25
)
26
26
27
+ // MapFunc is the signature required for enqueueing requests from a generic function.
28
+ // This type is usually used with EnqueueRequestsFromMapFunc when registering an event handler.
29
+ type MapFunc func (MapObject ) []reconcile.Request
30
+
27
31
// EnqueueRequestsFromMapFunc enqueues Requests by running a transformation function that outputs a collection
28
32
// of reconcile.Requests on each Event. The reconcile.Requests may be for an arbitrary set of objects
29
33
// defined by some user specified transformation of the source Event. (e.g. trigger Reconciler for a set of objects
@@ -34,17 +38,17 @@ import (
34
38
//
35
39
// For UpdateEvents which contain both a new and old object, the transformation function is run on both
36
40
// objects and both sets of Requests are enqueue.
37
- func EnqueueRequestsFromMapFunc (mapFN func ( MapObject ) []reconcile. Request ) EventHandler {
41
+ func EnqueueRequestsFromMapFunc (fn MapFunc ) EventHandler {
38
42
return & enqueueRequestsFromMapFunc {
39
- ToRequests : toRequestsFunc ( mapFN ) ,
43
+ toRequests : fn ,
40
44
}
41
45
}
42
46
43
47
var _ EventHandler = & enqueueRequestsFromMapFunc {}
44
48
45
49
type enqueueRequestsFromMapFunc struct {
46
50
// Mapper transforms the argument into a slice of keys to be reconciled
47
- ToRequests mapper
51
+ toRequests MapFunc
48
52
}
49
53
50
54
// Create implements EventHandler
@@ -69,7 +73,7 @@ func (e *enqueueRequestsFromMapFunc) Generic(evt event.GenericEvent, q workqueue
69
73
}
70
74
71
75
func (e * enqueueRequestsFromMapFunc ) mapAndEnqueue (q workqueue.RateLimitingInterface , object MapObject ) {
72
- for _ , req := range e .ToRequests . Map (object ) {
76
+ for _ , req := range e .toRequests (object ) {
73
77
q .Add (req )
74
78
}
75
79
}
@@ -81,26 +85,10 @@ func (e *enqueueRequestsFromMapFunc) InjectFunc(f inject.Func) error {
81
85
if f == nil {
82
86
return nil
83
87
}
84
- return f (e .ToRequests )
85
- }
86
-
87
- // mapper maps an object to a collection of keys to be enqueued
88
- type mapper interface {
89
- // Map maps an object
90
- Map (MapObject ) []reconcile.Request
88
+ return f (e .toRequests )
91
89
}
92
90
93
91
// MapObject contains information from an event to be transformed into a Request.
94
92
type MapObject struct {
95
93
Object controllerutil.Object
96
94
}
97
-
98
- var _ mapper = toRequestsFunc (nil )
99
-
100
- // toRequestsFunc implements Mapper using a function.
101
- type toRequestsFunc func (MapObject ) []reconcile.Request
102
-
103
- // Map implements Mapper
104
- func (m toRequestsFunc ) Map (i MapObject ) []reconcile.Request {
105
- return m (i )
106
- }
0 commit comments