Skip to content

Commit

Permalink
Only process IPv4 Endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
swetharepakula committed Feb 14, 2023
1 parent 45fc392 commit 6d0d5c5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/neg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ func EndpointsDataFromEndpoints(ep *apiv1.Endpoints) []EndpointsData {
func EndpointsDataFromEndpointSlices(slices []*discovery.EndpointSlice) []EndpointsData {
result := make([]EndpointsData, 0, len(slices))
for _, slice := range slices {
if slice.AddressType != discovery.AddressTypeIPv4 {
// Neg Controller can only attach IPv4 endpoints
continue
}
ports := make([]PortData, 0)
addresses := make([]AddressData, 0)
for _, port := range slice.Ports {
Expand Down
45 changes: 45 additions & 0 deletions pkg/neg/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,14 +665,59 @@ func TestEndpointsDataFromEndpointSlices(t *testing.T) {
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: testServiceName + "-2",
Namespace: testServiceNamespace,
},
AddressType: discovery.AddressTypeIPv6,
Endpoints: []discovery.Endpoint{
{
Addresses: []string{"aa:aa:aa:aa:aa:aa"},
NodeName: &instance2,
TargetRef: &v1.ObjectReference{
Namespace: testServiceNamespace,
Name: "pod7",
},
},
{
Addresses: []string{"aa:aa:aa:aa:aa:ab"},
NodeName: &instance4,
TargetRef: &v1.ObjectReference{
Namespace: testServiceNamespace,
Name: "pod8",
},
},
{
Addresses: []string{"aa:aa:aa:aa:aa:ac"},
NodeName: &instance4,
TargetRef: &v1.ObjectReference{
Namespace: testServiceNamespace,
Name: "pod9",
},
Conditions: discovery.EndpointConditions{Ready: &notReady},
},
},
Ports: []discovery.EndpointPort{
{
Name: &testNamedPort,
Port: &port81,
Protocol: &protocolTCP,
},
},
},
}

endpointsData := EndpointsDataFromEndpointSlices(endpointSlices)

if len(endpointsData) != 2 {
t.Errorf("Expected the same number of endpoints subsets and endpoints data, got %d endpoints data for 2 subsets", len(endpointsData))
}
// This test expects that all the valid EPS are at the beginning
for i, slice := range endpointSlices {
if slice.AddressType != discovery.AddressTypeIPv4 {
continue
}
for j, port := range slice.Ports {
ValidatePortData(endpointsData[i].Ports[j], *port.Port, *port.Name, t)
}
Expand Down

0 comments on commit 6d0d5c5

Please sign in to comment.