Skip to content

Commit c0857e1

Browse files
committed
use slices.Equal for subnet comparison
Signed-off-by: Mikkel Oscar Lyderik Larsen <[email protected]>
1 parent 7bf903b commit c0857e1

File tree

3 files changed

+7
-25
lines changed

3 files changed

+7
-25
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/sirupsen/logrus v1.9.3
1414
github.com/stretchr/testify v1.9.0
1515
github.com/zalando/skipper v0.21.36
16+
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
1617
gopkg.in/alecthomas/kingpin.v2 v2.2.6
1718
k8s.io/api v0.27.12
1819
k8s.io/apimachinery v0.27.12
@@ -70,7 +71,6 @@ require (
7071
go.uber.org/atomic v1.11.0 // indirect
7172
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
7273
golang.org/x/crypto v0.21.0 // indirect
73-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
7474
golang.org/x/net v0.22.0 // indirect
7575
golang.org/x/oauth2 v0.18.0 // indirect
7676
golang.org/x/sys v0.18.0 // indirect

worker.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/zalando-incubator/kube-ingress-aws-controller/certs"
2020
"github.com/zalando-incubator/kube-ingress-aws-controller/kubernetes"
2121
"github.com/zalando-incubator/kube-ingress-aws-controller/problem"
22+
"golang.org/x/exp/slices"
2223
)
2324

2425
type loadBalancer struct {
@@ -455,8 +456,10 @@ func matchIngressesToLoadBalancers(
455456
// Ignore NLBs with a wrong set of subnets
456457
if lb.loadBalancerType == aws.LoadBalancerTypeNetwork {
457458
subnets := subnetsByScheme(lb.scheme)
459+
sort.Strings(subnets)
460+
sort.Strings(lb.stack.Subnets)
458461

459-
if !equalSlices[string](lb.stack.Subnets, subnets) {
462+
if !slices.Equal[[]string](lb.stack.Subnets, subnets) {
460463
continue
461464
}
462465
}
@@ -721,25 +724,3 @@ func cniEventHandler(ctx context.Context, targetCNIcfg *aws.TargetCNIconfig,
721724
}
722725
}
723726
}
724-
725-
func equalSlices[T comparable](a, b []T) bool {
726-
if len(a) != len(b) {
727-
return false
728-
}
729-
730-
for _, aElem := range a {
731-
found := false
732-
for _, bElem := range b {
733-
if aElem == bElem {
734-
found = true
735-
break
736-
}
737-
}
738-
739-
if !found {
740-
return false
741-
}
742-
}
743-
744-
return true
745-
}

worker_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/zalando-incubator/kube-ingress-aws-controller/certs"
2424
"github.com/zalando-incubator/kube-ingress-aws-controller/kubernetes"
2525
"github.com/zalando/skipper/dataclients/kubernetes/kubernetestest"
26+
"golang.org/x/exp/slices"
2627
"k8s.io/apimachinery/pkg/util/wait"
2728

2829
"github.com/zalando-incubator/kube-ingress-aws-controller/aws/fake"
@@ -1386,7 +1387,7 @@ func TestMatchIngressesToLoadbalancers(t *testing.T) {
13861387
continue
13871388
}
13881389

1389-
if lb.stack != nil && equalSlices[string](lb.stack.Subnets, []string{"a", "b", "c"}) {
1390+
if lb.stack != nil && slices.Equal[string](lb.stack.Subnets, []string{"a", "b", "c"}) {
13901391
require.Len(t, lb.ingresses, 0)
13911392
} else {
13921393
require.Len(t, lb.ingresses, 1)

0 commit comments

Comments
 (0)