Skip to content

Commit

Permalink
use slices.Equal for subnet comparison
Browse files Browse the repository at this point in the history
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
  • Loading branch information
mikkeloscar committed Jun 14, 2023
1 parent c2d0eff commit e933c3d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 24 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.4
github.com/zalando/skipper v0.16.6
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
gopkg.in/alecthomas/kingpin.v2 v2.2.6
k8s.io/api v0.22.17
k8s.io/apimachinery v0.22.17
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
27 changes: 4 additions & 23 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/zalando-incubator/kube-ingress-aws-controller/certs"
"github.com/zalando-incubator/kube-ingress-aws-controller/kubernetes"
"github.com/zalando-incubator/kube-ingress-aws-controller/problem"
"golang.org/x/exp/slices"
)

type loadBalancer struct {
Expand Down Expand Up @@ -455,8 +456,10 @@ func matchIngressesToLoadBalancers(
// Ignore NLBs with a wrong set of subnets
if lb.loadBalancerType == aws.LoadBalancerTypeNetwork {
subnets := subnetsByScheme(lb.scheme)
sort.Strings(subnets)
sort.Strings(lb.stack.Subnets)

if !equalSlices[string](lb.stack.Subnets, subnets) {
if !slices.Equal[string](lb.stack.Subnets, subnets) {
continue
}
}
Expand Down Expand Up @@ -721,25 +724,3 @@ func cniEventHandler(ctx context.Context, targetCNIcfg *aws.TargetCNIconfig,
}
}
}

func equalSlices[T comparable](a, b []T) bool {
if len(a) != len(b) {
return false
}

for _, aElem := range a {
found := false
for _, bElem := range b {
if aElem == bElem {
found = true
break
}
}

if !found {
return false
}
}

return true
}
3 changes: 2 additions & 1 deletion worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/zalando-incubator/kube-ingress-aws-controller/certs"
"github.com/zalando-incubator/kube-ingress-aws-controller/kubernetes"
"github.com/zalando/skipper/dataclients/kubernetes/kubernetestest"
"golang.org/x/exp/slices"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/zalando-incubator/kube-ingress-aws-controller/aws/fake"
Expand Down Expand Up @@ -1160,7 +1161,7 @@ func TestMatchIngressesToLoadbalancers(t *testing.T) {
continue
}

if lb.stack != nil && equalSlices[string](lb.stack.Subnets, []string{"a", "b", "c"}) {
if lb.stack != nil && slices.Equal[string](lb.stack.Subnets, []string{"a", "b", "c"}) {
require.Len(t, lb.ingresses, 0)
} else {
require.Len(t, lb.ingresses, 1)
Expand Down

0 comments on commit e933c3d

Please sign in to comment.