Skip to content

Commit b3212c7

Browse files
committed
lint
1 parent 86bb8ae commit b3212c7

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

internal/controller/linodefirewall_controller_helpers.go

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var (
3737

3838
func 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

internal/controller/linodefirewall_controller_helpers_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/google/go-cmp/cmp/cmpopts"
1111
"github.com/linode/linodego"
1212
"github.com/stretchr/testify/assert"
13+
"github.com/stretchr/testify/require"
1314

1415
infrav1alpha2 "github.com/linode/cluster-api-provider-linode/api/v1alpha2"
1516
)
@@ -535,7 +536,7 @@ func TestProcessInboundRule(t *testing.T) {
535536
logger := logr.Logger{}
536537
for _, rule := range tt.firewall.Spec.InboundRules {
537538
err := processInboundRule(context.Background(), k8sClient, logger, rule, tt.firewall, tt.createOpts)
538-
assert.NoError(t, err)
539+
require.NoError(t, err)
539540
if !reflect.DeepEqual(tt.createOpts, tt.want) {
540541
t.Errorf("processInboundRule() = %v, want %v", tt.createOpts, tt.want)
541542
}
@@ -605,7 +606,7 @@ func TestProcessOutboundRule(t *testing.T) {
605606
logger := logr.Logger{}
606607
for _, rule := range tt.firewall.Spec.OutboundRules {
607608
err := processOutboundRule(context.Background(), k8sClient, logger, rule, tt.firewall, tt.createOpts)
608-
assert.NoError(t, err)
609+
require.NoError(t, err)
609610
if !reflect.DeepEqual(tt.createOpts, tt.want) {
610611
t.Errorf("processOutboundRule() = %v, want %v", tt.createOpts, tt.want)
611612
}

0 commit comments

Comments
 (0)