Skip to content

Commit

Permalink
chore: add SliceEqual util function
Browse files Browse the repository at this point in the history
  • Loading branch information
feiskyer committed Jun 16, 2022
1 parent 4893026 commit 0baefc7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/provider/azure_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
servicehelpers "k8s.io/cloud-provider/service/helpers"
"k8s.io/klog/v2"
utilnet "k8s.io/utils/net"
"k8s.io/utils/strings/slices"

azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
"sigs.k8s.io/cloud-provider-azure/pkg/consts"
Expand Down Expand Up @@ -3180,7 +3179,7 @@ func findSecurityRule(rules []network.SecurityRule, rule network.SecurityRule) b
if !strings.EqualFold(to.String(existingRule.DestinationAddressPrefix), to.String(rule.DestinationAddressPrefix)) {
continue
}
if !slices.Equal(to.StringSlice(existingRule.DestinationAddressPrefixes), to.StringSlice(rule.DestinationAddressPrefixes)) {
if !SliceEqual(to.StringSlice(existingRule.DestinationAddressPrefixes), to.StringSlice(rule.DestinationAddressPrefixes)) {
continue
}
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/provider/azure_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,19 @@ func sameContentInSlices(s1 []string, s2 []string) bool {
}
return true
}

// SliceEqual reports whether two slices are equal: the same length and all
// elements equal. If the lengths are different, Equal returns false.
// Otherwise, the elements are compared in index order, and the
// comparison stops at the first unequal pair.
func SliceEqual(s1, s2 []string) bool {
if len(s1) != len(s2) {
return false
}
for i, n := range s1 {
if n != s2[i] {
return false
}
}
return true
}

0 comments on commit 0baefc7

Please sign in to comment.