mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 17:46:57 +02:00
Remove duplication of external ips when ExternalTrafficPolicy set to … (#1744)
* Remove duplication of target ips for NodePort services with ExternalTrafficPolicy=Local * Removed trailing lines
This commit is contained in:
parent
8c3220b527
commit
53c0cf951d
@ -13,6 +13,7 @@
|
|||||||
- Fix index out of range when hostname has no dots (#1756) @chemasan
|
- Fix index out of range when hostname has no dots (#1756) @chemasan
|
||||||
- Fixes test coverage with coveralls (#1755) @jgrumboe
|
- Fixes test coverage with coveralls (#1755) @jgrumboe
|
||||||
- Add tutorial for GKE with workload identity (#1765) @ddgenome
|
- Add tutorial for GKE with workload identity (#1765) @ddgenome
|
||||||
|
- Fix NodePort with externaltrafficpolicy targets duplication @codearky
|
||||||
|
|
||||||
## v0.7.3 - 2020-08-05
|
## v0.7.3 - 2020-08-05
|
||||||
|
|
||||||
|
@ -511,6 +511,7 @@ func (sc *serviceSource) extractNodePortTargets(svc *v1.Service) (endpoint.Targe
|
|||||||
|
|
||||||
switch svc.Spec.ExternalTrafficPolicy {
|
switch svc.Spec.ExternalTrafficPolicy {
|
||||||
case v1.ServiceExternalTrafficPolicyTypeLocal:
|
case v1.ServiceExternalTrafficPolicyTypeLocal:
|
||||||
|
nodesMap := map[*v1.Node]struct{}{}
|
||||||
labelSelector, err := metav1.ParseToLabelSelector(labels.Set(svc.Spec.Selector).AsSelectorPreValidated().String())
|
labelSelector, err := metav1.ParseToLabelSelector(labels.Set(svc.Spec.Selector).AsSelectorPreValidated().String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -531,7 +532,10 @@ func (sc *serviceSource) extractNodePortTargets(svc *v1.Service) (endpoint.Targe
|
|||||||
log.Debugf("Unable to find node where Pod %s is running", v.Spec.Hostname)
|
log.Debugf("Unable to find node where Pod %s is running", v.Spec.Hostname)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
nodes = append(nodes, node)
|
if _, ok := nodesMap[node]; !ok {
|
||||||
|
nodesMap[node] = *new(struct{})
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -1545,6 +1545,52 @@ func TestNodePortServices(t *testing.T) {
|
|||||||
[]int{1},
|
[]int{1},
|
||||||
[]v1.PodPhase{v1.PodRunning},
|
[]v1.PodPhase{v1.PodRunning},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"annotated NodePort services with ExternalTrafficPolicy=Local and multiple pods on a single node return an endpoint with unique IP addresses of the cluster's nodes where pods is running only",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"testing",
|
||||||
|
"foo",
|
||||||
|
v1.ServiceTypeNodePort,
|
||||||
|
v1.ServiceExternalTrafficPolicyTypeLocal,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
false,
|
||||||
|
map[string]string{},
|
||||||
|
map[string]string{
|
||||||
|
hostnameAnnotationKey: "foo.example.org.",
|
||||||
|
},
|
||||||
|
nil,
|
||||||
|
[]*endpoint.Endpoint{
|
||||||
|
{DNSName: "_30192._tcp.foo.example.org", Targets: endpoint.Targets{"0 50 30192 foo.example.org"}, RecordType: endpoint.RecordTypeSRV},
|
||||||
|
{DNSName: "foo.example.org", Targets: endpoint.Targets{"54.10.11.2"}, RecordType: endpoint.RecordTypeA},
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
[]*v1.Node{{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
},
|
||||||
|
Status: v1.NodeStatus{
|
||||||
|
Addresses: []v1.NodeAddress{
|
||||||
|
{Type: v1.NodeExternalIP, Address: "54.10.11.1"},
|
||||||
|
{Type: v1.NodeInternalIP, Address: "10.0.1.1"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node2",
|
||||||
|
},
|
||||||
|
Status: v1.NodeStatus{
|
||||||
|
Addresses: []v1.NodeAddress{
|
||||||
|
{Type: v1.NodeExternalIP, Address: "54.10.11.2"},
|
||||||
|
{Type: v1.NodeInternalIP, Address: "10.0.1.2"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
[]string{"pod-0", "pod-1"},
|
||||||
|
[]int{1, 1},
|
||||||
|
[]v1.PodPhase{v1.PodRunning, v1.PodRunning},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.title, func(t *testing.T) {
|
t.Run(tc.title, func(t *testing.T) {
|
||||||
// Create a Kubernetes testing client
|
// Create a Kubernetes testing client
|
||||||
|
Loading…
Reference in New Issue
Block a user