Skip to content

Commit bc8d081

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

File tree

4 files changed

+9
-28
lines changed

4 files changed

+9
-28
lines changed

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/sirupsen/logrus v1.9.3
1515
github.com/stretchr/testify v1.9.0
1616
github.com/zalando/skipper v0.21.54
17+
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f
1718
k8s.io/api v0.28.9
1819
k8s.io/apimachinery v0.28.9
1920
k8s.io/client-go v0.28.9
@@ -70,14 +71,12 @@ 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.22.0 // indirect
73-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
7474
golang.org/x/net v0.24.0 // indirect
7575
golang.org/x/oauth2 v0.19.0 // indirect
7676
golang.org/x/sys v0.19.0 // indirect
7777
golang.org/x/term v0.19.0 // indirect
7878
golang.org/x/text v0.14.0 // indirect
7979
golang.org/x/time v0.5.0 // indirect
80-
golang.org/x/tools v0.20.0 // indirect
8180
google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be // indirect
8281
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
8382
google.golang.org/grpc v1.63.2 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
276276
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
277277
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
278278
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
279-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
280-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
279+
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY=
280+
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
281281
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
282282
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
283283
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=

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)