3737
3838func findObjectsForAddressSet (logger logr.Logger , tracedClient client.Client ) handler.MapFunc {
3939 logger = logger .WithName ("LinodeFirewallReconciler" ).WithName ("findObjectsForAddressSet" )
40- return func (ctx context.Context , o client.Object ) []ctrl.Request {
40+ return func (ctx context.Context , obj client.Object ) []ctrl.Request {
4141 ctx , cancel := context .WithTimeout (ctx , reconciler .DefaultMappingTimeout )
4242 defer cancel ()
4343
@@ -56,42 +56,47 @@ func findObjectsForAddressSet(logger logr.Logger, tracedClient client.Client) ha
5656 }
5757 }
5858
59- // construct a set of requests for updating LinodeFirewalls that either reference the
60- // AddressSet in the Inbound and/or OutboundRules
61- requestSet := make (map [reconcile.Request ]struct {})
62- for _ , item := range firewalls .Items {
63- for _ , inboundRule := range item .Spec .InboundRules {
64- for _ , addrSetRef := range inboundRule .AddressSetRefs {
65- if addrSetRef .Name == o .GetName () && addrSetRef .Namespace == o .GetNamespace () {
66- requestSet [reconcile.Request {
67- NamespacedName : types.NamespacedName {
68- Name : item .GetName (),
69- Namespace : item .GetNamespace (),
70- },
71- }] = struct {}{}
72- }
59+ return buildRequests (firewalls .Items , obj )
60+ }
61+ }
62+
63+ // Constructs a unique list of requests for updating LinodeFirewalls that either reference the
64+ // AddressSet in the Inbound and/or OutboundRules
65+ func buildRequests (firewalls []infrav1alpha2.LinodeFirewall , obj client.Object ) []reconcile.Request {
66+ requestSet := make (map [reconcile.Request ]struct {})
67+ for _ , item := range firewalls {
68+ for _ , inboundRule := range item .Spec .InboundRules {
69+ for _ , addrSetRef := range inboundRule .AddressSetRefs {
70+ if addrSetRef .Name == obj .GetName () && addrSetRef .Namespace == obj .GetNamespace () {
71+ requestSet [reconcile.Request {
72+ NamespacedName : types.NamespacedName {
73+ Name : item .GetName (),
74+ Namespace : item .GetNamespace (),
75+ },
76+ }] = struct {}{}
7377 }
7478 }
75- for _ , outboundRule := range item . Spec . OutboundRules {
76- for _ , addrSetRef := range outboundRule . AddressSetRefs {
77- if addrSetRef . Name == o . GetName () && addrSetRef . Namespace == o . GetNamespace () {
78- requestSet [reconcile. Request {
79- NamespacedName : types. NamespacedName {
80- Name : item . GetName (),
81- Namespace : item .GetNamespace (),
82- } ,
83- }] = struct {}{}
84- }
79+ }
80+ for _ , outboundRule := range item . Spec . OutboundRules {
81+ for _ , addrSetRef := range outboundRule . AddressSetRefs {
82+ if addrSetRef . Name == obj . GetName () && addrSetRef . Namespace == obj . GetNamespace () {
83+ requestSet [reconcile. Request {
84+ NamespacedName : types. NamespacedName {
85+ Name : item .GetName (),
86+ Namespace : item . GetNamespace () ,
87+ },
88+ }] = struct {}{}
8589 }
8690 }
8791 }
88-
89- var requests []reconcile.Request
90- for req := range requestSet {
91- requests = append (requests , req )
92- }
93- return requests
9492 }
93+ requests := make ([]reconcile.Request , len (requestSet ))
94+ i := 0
95+ for req := range requestSet {
96+ requests [i ] = req
97+ i += 1
98+ }
99+ return requests
95100}
96101
97102// reconcileFirewall takes the CAPL firewall representation and uses it to either create or update the Cloud Firewall
0 commit comments