File tree Expand file tree Collapse file tree 3 files changed +30
-15
lines changed Expand file tree Collapse file tree 3 files changed +30
-15
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,22 @@ import (
25
25
"sigs.k8s.io/controller-runtime/pkg/runtime/inject"
26
26
)
27
27
28
+ // FromMapFunc enqueues Requests by running a transformation function that outputs a collection
29
+ // of reconcile.Requests on each Event. The reconcile.Requests may be for an arbitrary set of objects
30
+ // defined by some user specified transformation of the source Event. (e.g. trigger Reconciler for a set of objects
31
+ // in response to a cluster resize event caused by adding or deleting a Node)
32
+ //
33
+ // FromMapFunc is frequently used to fan-out updates from one object to one or more other
34
+ // objects of a differing type.
35
+ //
36
+ // For UpdateEvents which contain both a new and old object, the transformation function is run on both
37
+ // objects and both sets of Requests are enqueue.
38
+ func FromMapFunc (mapFN func (MapObject ) []reconcile.Request ) EventHandler {
39
+ return & EnqueueRequestsFromMapFunc {
40
+ ToRequests : ToRequestsFunc (mapFN ),
41
+ }
42
+ }
43
+
28
44
var _ EventHandler = & EnqueueRequestsFromMapFunc {}
29
45
30
46
// EnqueueRequestsFromMapFunc enqueues Requests by running a transformation function that outputs a collection
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ import (
33
33
// * Use EnqueueRequestForOwner to reconcile the owner of the object the event is for
34
34
// - do this for events for the types the Controller creates. (e.g. ReplicaSets created by a Deployment Controller)
35
35
//
36
- // * Use EnqueueRequestsFromMapFunc to transform an event for an object to a reconcile of an object
36
+ // * Use EnqueueRequestsFromMapFunc or FromMapFunc to transform an event for an object to a reconcile of an object
37
37
// of a different type - do this for events for types the Controller may be interested in, but doesn't create.
38
38
// (e.g. If Foo responds to cluster size events, map Node events to Foo objects.)
39
39
//
Original file line number Diff line number Diff line change @@ -65,20 +65,19 @@ func ExampleEnqueueRequestsFromMapFunc() {
65
65
// controller is a controller.controller
66
66
err := c .Watch (
67
67
& source.Kind {Type : & appsv1.Deployment {}},
68
- & handler.EnqueueRequestsFromMapFunc {
69
- ToRequests : handler .ToRequestsFunc (func (a handler.MapObject ) []reconcile.Request {
70
- return []reconcile.Request {
71
- {NamespacedName : types.NamespacedName {
72
- Name : a .Meta .GetName () + "-1" ,
73
- Namespace : a .Meta .GetNamespace (),
74
- }},
75
- {NamespacedName : types.NamespacedName {
76
- Name : a .Meta .GetName () + "-2" ,
77
- Namespace : a .Meta .GetNamespace (),
78
- }},
79
- }
80
- }),
81
- })
68
+ handler .FromMapFunc (func (a handler.MapObject ) []reconcile.Request {
69
+ return []reconcile.Request {
70
+ {NamespacedName : types.NamespacedName {
71
+ Name : a .Meta .GetName () + "-1" ,
72
+ Namespace : a .Meta .GetNamespace (),
73
+ }},
74
+ {NamespacedName : types.NamespacedName {
75
+ Name : a .Meta .GetName () + "-2" ,
76
+ Namespace : a .Meta .GetNamespace (),
77
+ }},
78
+ }
79
+ }),
80
+ )
82
81
if err != nil {
83
82
// handle it
84
83
}
You can’t perform that action at this time.
0 commit comments