diff --git a/control-plane/catalog/to-consul/resource.go b/control-plane/catalog/to-consul/resource.go index 75b4f57ff7..9fd0b5cfc0 100644 --- a/control-plane/catalog/to-consul/resource.go +++ b/control-plane/catalog/to-consul/resource.go @@ -553,6 +553,12 @@ func (t *ServiceResource) generateRegistrations(key string) { r.Service.Address = address.Address t.consulMap[key] = append(t.consulMap[key], &r) + // Only consider the first address that matches. In some cases + // there will be multiple addresses like when using AWS CNI. + // In those cases, Kubernetes will ensure eth0 is always the first + // address in the list. + // See https://github.com/kubernetes/kubernetes/blob/b559434c02f903dbcd46ee7d6c78b216d3f0aca0/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go#L1462-L1464 + break } } @@ -568,6 +574,12 @@ func (t *ServiceResource) generateRegistrations(key string) { r.Service.Address = address.Address t.consulMap[key] = append(t.consulMap[key], &r) + // Only consider the first address that matches. In some cases + // there will be multiple addresses like when using AWS CNI. + // In those cases, Kubernetes will ensure eth0 is always the first + // address in the list. + // See https://github.com/kubernetes/kubernetes/blob/b559434c02f903dbcd46ee7d6c78b216d3f0aca0/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go#L1462-L1464 + break } } } diff --git a/control-plane/catalog/to-consul/resource_test.go b/control-plane/catalog/to-consul/resource_test.go index e8c5e505bb..5dc0f5e04a 100644 --- a/control-plane/catalog/to-consul/resource_test.go +++ b/control-plane/catalog/to-consul/resource_test.go @@ -1527,6 +1527,7 @@ func createNodes(t *testing.T, client *fake.Clientset) (*apiv1.Node, *apiv1.Node Addresses: []apiv1.NodeAddress{ {Type: apiv1.NodeExternalIP, Address: "1.2.3.4"}, {Type: apiv1.NodeInternalIP, Address: "4.5.6.7"}, + {Type: apiv1.NodeInternalIP, Address: "7.8.9.10"}, }, }, } @@ -1542,6 +1543,7 @@ func createNodes(t *testing.T, client *fake.Clientset) (*apiv1.Node, *apiv1.Node Addresses: []apiv1.NodeAddress{ {Type: apiv1.NodeExternalIP, Address: "2.3.4.5"}, {Type: apiv1.NodeInternalIP, Address: "3.4.5.6"}, + {Type: apiv1.NodeInternalIP, Address: "6.7.8.9"}, }, }, }