Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sync-catalog] Fix NodePort register service with wrong internal IP when multiple internal IPs are reported on the node #619

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
kolorful marked this conversation as resolved.
Show resolved Hide resolved
}
}

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
kolorful marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
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