Skip to content

Commit

Permalink
Merge pull request hashicorp#619 from kolorful/master
Browse files Browse the repository at this point in the history
[sync-catalog] Fix NodePort register service with wrong internal IP when multiple internal IPs are reported on the node
  • Loading branch information
lkysow authored Aug 19, 2021
2 parents 7dd5e08 + 4935a38 commit 3787573
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions control-plane/catalog/to-consul/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions control-plane/catalog/to-consul/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
}
Expand All @@ -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"},
},
},
}
Expand Down

0 comments on commit 3787573

Please sign in to comment.