diff --git a/pkg/neg/types/types.go b/pkg/neg/types/types.go index d9f353dcf4..0c7144adce 100644 --- a/pkg/neg/types/types.go +++ b/pkg/neg/types/types.go @@ -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 { diff --git a/pkg/neg/types/types_test.go b/pkg/neg/types/types_test.go index 5ce1b0c5d5..66b32255c6 100644 --- a/pkg/neg/types/types_test.go +++ b/pkg/neg/types/types_test.go @@ -665,6 +665,47 @@ 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: ¬Ready}, + }, + }, + Ports: []discovery.EndpointPort{ + { + Name: &testNamedPort, + Port: &port81, + Protocol: &protocolTCP, + }, + }, + }, } endpointsData := EndpointsDataFromEndpointSlices(endpointSlices) @@ -672,7 +713,11 @@ func TestEndpointsDataFromEndpointSlices(t *testing.T) { 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) }