Skip to content

Commit

Permalink
remove duplicated address_prefix (openservicemesh#2239)
Browse files Browse the repository at this point in the history
Signed-off-by: addozhang <duwasai@gmail.com>

Co-authored-by: Edu Serra <eduser25@gmail.com>
  • Loading branch information
addozhang and eduser25 authored Jan 4, 2021
1 parent 08efd2a commit 459e353
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pkg/envoy/lds/inmesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,25 @@ func (lb *listenerBuilder) getOutboundFilterChainMatchForService(dstSvc service.
return nil, err
}

contains := func(s []string, t string) bool {
for _, a := range s {
if a == t {
return true
}
}
return false
}

var endpointSet []string
for _, endp := range endpoints {
if !contains(endpointSet, endp.IP.String()) {
endpointSet = append(endpointSet, endp.IP.String())
}
}

for _, ip := range endpointSet {
filterMatch.PrefixRanges = append(filterMatch.PrefixRanges, &xds_core.CidrRange{
AddressPrefix: endp.IP.String(),
AddressPrefix: ip,
PrefixLen: &wrapperspb.UInt32Value{
Value: singleIpv4Mask,
},
Expand Down
27 changes: 27 additions & 0 deletions pkg/envoy/lds/inmesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,33 @@ func TestGetOutboundFilterChainMatchForService(t *testing.T) {
expectedFilterChainMatch: nil,
expectError: true,
},

{
// test case 5
name: "outbound TCP filter chain for service with duplicated endpoints",
endpoints: []endpoint.Endpoint{
{
IP: net.IPv4(192, 168, 10, 1),
Port: 8080,
},
{
IP: net.IPv4(192, 168, 10, 1),
Port: 8090,
},
},
appProtocol: tcpAppProtocol,
expectedFilterChainMatch: &xds_listener.FilterChainMatch{
PrefixRanges: []*xds_core.CidrRange{
{
AddressPrefix: "192.168.10.1",
PrefixLen: &wrapperspb.UInt32Value{
Value: 32,
},
},
},
},
expectError: false,
},
}

for i, tc := range testCases {
Expand Down

0 comments on commit 459e353

Please sign in to comment.