Skip to content

Commit b3fe7f2

Browse files
Revert "IPv6 internal node IPs are usable externally"
This reverts commit 683663e.
1 parent 20271b7 commit b3fe7f2

File tree

8 files changed

+153
-66
lines changed

8 files changed

+153
-66
lines changed

docs/tutorials/nodes.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
This tutorial describes how to configure ExternalDNS to use the cluster nodes as source.
44
Using nodes (`--source=node`) as source is possible to synchronize a DNS zone with the nodes of a cluster.
55

6-
The node source adds an `A` record per each node `externalIP` (if not found, any IPv4 `internalIP` is used instead).
7-
It also adds an `AAAA` record per each node IPv6 `internalIP`.
8-
The TTL of the records can be set with the `external-dns.alpha.kubernetes.io/ttl` node annotation.
6+
The node source adds `A` and `AAAA` record per each node `externalIP` (if not found, node's `internalIP`s are used).
7+
The TTL record can be set with the `external-dns.alpha.kubernetes.io/ttl` node annotation.
98

109
## Manifest (for cluster without RBAC enabled)
1110

source/compatibility.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ func legacyEndpointsFromDNSControllerNodePortService(svc *v1.Service, sc *servic
158158
}
159159
for _, address := range node.Status.Addresses {
160160
recordType := suitableType(address.Address)
161-
// IPv6 addresses are labeled as NodeInternalIP despite being usable externally as well.
162-
if isExternal && (address.Type == v1.NodeExternalIP || (address.Type == v1.NodeInternalIP && recordType == endpoint.RecordTypeAAAA)) {
161+
if isExternal && address.Type == v1.NodeExternalIP {
163162
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, recordType, address.Address))
164163
}
165164
if isInternal && address.Type == v1.NodeInternalIP {

source/node.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,13 @@ func (ns *nodeSource) nodeAddresses(node *v1.Node) ([]string, error) {
169169
v1.NodeExternalIP: {},
170170
v1.NodeInternalIP: {},
171171
}
172-
var ipv6Addresses []string
173172

174173
for _, addr := range node.Status.Addresses {
175174
addresses[addr.Type] = append(addresses[addr.Type], addr.Address)
176-
// IPv6 addresses are labeled as NodeInternalIP despite being usable externally as well.
177-
if addr.Type == v1.NodeInternalIP && suitableType(addr.Address) == endpoint.RecordTypeAAAA {
178-
ipv6Addresses = append(ipv6Addresses, addr.Address)
179-
}
180175
}
181176

182177
if len(addresses[v1.NodeExternalIP]) > 0 {
183-
return append(addresses[v1.NodeExternalIP], ipv6Addresses...), nil
178+
return addresses[v1.NodeExternalIP], nil
184179
}
185180

186181
if len(addresses[v1.NodeInternalIP]) > 0 {

source/node_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func testNodeSourceEndpoints(t *testing.T) {
159159
title: "node with fqdn template returns two endpoints with dual-stack IP addresses and expanded hostname",
160160
fqdnTemplate: "{{.Name}}.example.org",
161161
nodeName: "node1",
162-
nodeAddresses: []v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "1.2.3.4"}, {Type: v1.NodeInternalIP, Address: "2001:DB8::8"}},
162+
nodeAddresses: []v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "1.2.3.4"}, {Type: v1.NodeExternalIP, Address: "2001:DB8::8"}},
163163
expected: []*endpoint.Endpoint{
164164
{RecordType: "A", DNSName: "node1.example.org", Targets: endpoint.Targets{"1.2.3.4"}},
165165
{RecordType: "AAAA", DNSName: "node1.example.org", Targets: endpoint.Targets{"2001:DB8::8"}},
@@ -176,7 +176,7 @@ func testNodeSourceEndpoints(t *testing.T) {
176176
{
177177
title: "node with both external, internal, and IPv6 IP returns endpoints with external IPs",
178178
nodeName: "node1",
179-
nodeAddresses: []v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "1.2.3.4"}, {Type: v1.NodeInternalIP, Address: "2.3.4.5"}, {Type: v1.NodeInternalIP, Address: "2001:DB8::8"}},
179+
nodeAddresses: []v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "1.2.3.4"}, {Type: v1.NodeInternalIP, Address: "2.3.4.5"}, {Type: v1.NodeExternalIP, Address: "2001:DB8::8"}},
180180
expected: []*endpoint.Endpoint{
181181
{RecordType: "A", DNSName: "node1", Targets: endpoint.Targets{"1.2.3.4"}},
182182
{RecordType: "AAAA", DNSName: "node1", Targets: endpoint.Targets{"2001:DB8::8"}},

source/pod.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,8 @@ func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
110110
if len(targets) == 0 {
111111
node, _ := ps.nodeInformer.Lister().Get(pod.Spec.NodeName)
112112
for _, address := range node.Status.Addresses {
113-
recordType := suitableType(address.Address)
114-
// IPv6 addresses are labeled as NodeInternalIP despite being usable externally as well.
115-
if address.Type == corev1.NodeExternalIP || (address.Type == corev1.NodeInternalIP && recordType == endpoint.RecordTypeAAAA) {
116-
addToEndpointMap(endpointMap, domain, recordType, address.Address)
113+
if address.Type == corev1.NodeExternalIP {
114+
addToEndpointMap(endpointMap, domain, suitableType(address.Address), address.Address)
117115
}
118116
}
119117
} else {
@@ -137,10 +135,8 @@ func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
137135
for _, domain := range domainList {
138136
node, _ := ps.nodeInformer.Lister().Get(pod.Spec.NodeName)
139137
for _, address := range node.Status.Addresses {
140-
recordType := suitableType(address.Address)
141-
// IPv6 addresses are labeled as NodeInternalIP despite being usable externally as well.
142-
if address.Type == corev1.NodeExternalIP || (address.Type == corev1.NodeInternalIP && recordType == endpoint.RecordTypeAAAA) {
143-
addToEndpointMap(endpointMap, domain, recordType, address.Address)
138+
if address.Type == corev1.NodeExternalIP {
139+
addToEndpointMap(endpointMap, domain, suitableType(address.Address), address.Address)
144140
}
145141
}
146142
}

source/pod_test.go

Lines changed: 99 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ func TestPodSource(t *testing.T) {
185185
"",
186186
"",
187187
[]*endpoint.Endpoint{
188-
{DNSName: "a.foo.example.org", Targets: endpoint.Targets{"2001:DB8::1", "2001:DB8::2"}, RecordType: endpoint.RecordTypeAAAA},
189-
{DNSName: "internal.a.foo.example.org", Targets: endpoint.Targets{"2001:DB8::1", "2001:DB8::2"}, RecordType: endpoint.RecordTypeAAAA},
188+
{DNSName: "a.foo.example.org", Targets: endpoint.Targets{"2001:DB8::1", "2001:DB8::2", "2001:DB8::2"}, RecordType: endpoint.RecordTypeAAAA},
189+
{DNSName: "internal.a.foo.example.org", Targets: endpoint.Targets{"2001:DB8::1", "2001:DB8::2", "2001:DB8::3", "2001:DB8::4"}, RecordType: endpoint.RecordTypeAAAA},
190190
},
191191
false,
192192
[]*corev1.Node{
@@ -196,7 +196,7 @@ func TestPodSource(t *testing.T) {
196196
},
197197
Status: corev1.NodeStatus{
198198
Addresses: []corev1.NodeAddress{
199-
{Type: corev1.NodeInternalIP, Address: "2001:DB8::1"},
199+
{Type: corev1.NodeExternalIP, Address: "2001:DB8::1"},
200200
},
201201
},
202202
},
@@ -206,7 +206,18 @@ func TestPodSource(t *testing.T) {
206206
},
207207
Status: corev1.NodeStatus{
208208
Addresses: []corev1.NodeAddress{
209-
{Type: corev1.NodeInternalIP, Address: "2001:DB8::2"},
209+
{Type: corev1.NodeExternalIP, Address: "2001:DB8::2"},
210+
{Type: corev1.NodeInternalIP, Address: "2001:DB8::3"},
211+
},
212+
},
213+
},
214+
{
215+
ObjectMeta: metav1.ObjectMeta{
216+
Name: "my-node3",
217+
},
218+
Status: corev1.NodeStatus{
219+
Addresses: []corev1.NodeAddress{
220+
{Type: corev1.NodeInternalIP, Address: "2001:DB8::4"},
210221
},
211222
},
212223
},
@@ -246,15 +257,49 @@ func TestPodSource(t *testing.T) {
246257
PodIP: "2001:DB8::2",
247258
},
248259
},
260+
{
261+
ObjectMeta: metav1.ObjectMeta{
262+
Name: "my-pod3",
263+
Namespace: "kube-system",
264+
Annotations: map[string]string{
265+
internalHostnameAnnotationKey: "internal.a.foo.example.org",
266+
hostnameAnnotationKey: "a.foo.example.org",
267+
},
268+
},
269+
Spec: corev1.PodSpec{
270+
HostNetwork: true,
271+
NodeName: "my-node2",
272+
},
273+
Status: corev1.PodStatus{
274+
PodIP: "2001:DB8::3",
275+
},
276+
},
277+
{
278+
ObjectMeta: metav1.ObjectMeta{
279+
Name: "my-pod4",
280+
Namespace: "kube-system",
281+
Annotations: map[string]string{
282+
internalHostnameAnnotationKey: "internal.a.foo.example.org",
283+
hostnameAnnotationKey: "a.foo.example.org",
284+
},
285+
},
286+
Spec: corev1.PodSpec{
287+
HostNetwork: true,
288+
NodeName: "my-node3",
289+
},
290+
Status: corev1.PodStatus{
291+
PodIP: "2001:DB8::4",
292+
},
293+
},
249294
},
250295
},
251296
{
252297
"create IPv6 records based on pod's external and internal IPs using DNS Controller annotations",
253298
"",
254299
"kops-dns-controller",
255300
[]*endpoint.Endpoint{
256-
{DNSName: "a.foo.example.org", Targets: endpoint.Targets{"2001:DB8::1", "2001:DB8::2"}, RecordType: endpoint.RecordTypeAAAA},
257-
{DNSName: "internal.a.foo.example.org", Targets: endpoint.Targets{"2001:DB8::1", "2001:DB8::2"}, RecordType: endpoint.RecordTypeAAAA},
301+
{DNSName: "a.foo.example.org", Targets: endpoint.Targets{"2001:DB8::1", "2001:DB8::2", "2001:DB8::2"}, RecordType: endpoint.RecordTypeAAAA},
302+
{DNSName: "internal.a.foo.example.org", Targets: endpoint.Targets{"2001:DB8::1", "2001:DB8::2", "2001:DB8::3", "2001:DB8::4"}, RecordType: endpoint.RecordTypeAAAA},
258303
},
259304
false,
260305
[]*corev1.Node{
@@ -264,7 +309,7 @@ func TestPodSource(t *testing.T) {
264309
},
265310
Status: corev1.NodeStatus{
266311
Addresses: []corev1.NodeAddress{
267-
{Type: corev1.NodeInternalIP, Address: "2001:DB8::1"},
312+
{Type: corev1.NodeExternalIP, Address: "2001:DB8::1"},
268313
},
269314
},
270315
},
@@ -274,7 +319,18 @@ func TestPodSource(t *testing.T) {
274319
},
275320
Status: corev1.NodeStatus{
276321
Addresses: []corev1.NodeAddress{
277-
{Type: corev1.NodeInternalIP, Address: "2001:DB8::2"},
322+
{Type: corev1.NodeExternalIP, Address: "2001:DB8::2"},
323+
{Type: corev1.NodeInternalIP, Address: "2001:DB8::3"},
324+
},
325+
},
326+
},
327+
{
328+
ObjectMeta: metav1.ObjectMeta{
329+
Name: "my-node3",
330+
},
331+
Status: corev1.NodeStatus{
332+
Addresses: []corev1.NodeAddress{
333+
{Type: corev1.NodeInternalIP, Address: "2001:DB8::4"},
278334
},
279335
},
280336
},
@@ -314,6 +370,40 @@ func TestPodSource(t *testing.T) {
314370
PodIP: "2001:DB8::2",
315371
},
316372
},
373+
{
374+
ObjectMeta: metav1.ObjectMeta{
375+
Name: "my-pod3",
376+
Namespace: "kube-system",
377+
Annotations: map[string]string{
378+
kopsDNSControllerInternalHostnameAnnotationKey: "internal.a.foo.example.org",
379+
kopsDNSControllerHostnameAnnotationKey: "a.foo.example.org",
380+
},
381+
},
382+
Spec: corev1.PodSpec{
383+
HostNetwork: true,
384+
NodeName: "my-node2",
385+
},
386+
Status: corev1.PodStatus{
387+
PodIP: "2001:DB8::3",
388+
},
389+
},
390+
{
391+
ObjectMeta: metav1.ObjectMeta{
392+
Name: "my-pod4",
393+
Namespace: "kube-system",
394+
Annotations: map[string]string{
395+
kopsDNSControllerInternalHostnameAnnotationKey: "internal.a.foo.example.org",
396+
kopsDNSControllerHostnameAnnotationKey: "a.foo.example.org",
397+
},
398+
},
399+
Spec: corev1.PodSpec{
400+
HostNetwork: true,
401+
NodeName: "my-node3",
402+
},
403+
Status: corev1.PodStatus{
404+
PodIP: "2001:DB8::4",
405+
},
406+
},
317407
},
318408
},
319409
{
@@ -406,7 +496,7 @@ func TestPodSource(t *testing.T) {
406496
Status: corev1.NodeStatus{
407497
Addresses: []corev1.NodeAddress{
408498
{Type: corev1.NodeExternalIP, Address: "54.10.11.1"},
409-
{Type: corev1.NodeInternalIP, Address: "2001:DB8::1"},
499+
{Type: corev1.NodeExternalIP, Address: "2001:DB8::1"},
410500
{Type: corev1.NodeInternalIP, Address: "10.0.1.1"},
411501
},
412502
},

source/service.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func (sc *serviceSource) extractHeadlessEndpoints(svc *v1.Service, hostname stri
307307
return endpoints
308308
}
309309
for _, address := range node.Status.Addresses {
310-
if address.Type == v1.NodeExternalIP || (address.Type == v1.NodeInternalIP && suitableType(address.Address) == endpoint.RecordTypeAAAA) {
310+
if address.Type == v1.NodeExternalIP {
311311
targets = append(targets, address.Address)
312312
log.Debugf("Generating matching endpoint %s with NodeExternalIP %s", headlessDomain, address.Address)
313313
}
@@ -579,7 +579,6 @@ func (sc *serviceSource) extractNodePortTargets(svc *v1.Service) (endpoint.Targe
579579
var (
580580
internalIPs endpoint.Targets
581581
externalIPs endpoint.Targets
582-
ipv6IPs endpoint.Targets
583582
nodes []*v1.Node
584583
err error
585584
)
@@ -650,22 +649,19 @@ func (sc *serviceSource) extractNodePortTargets(svc *v1.Service) (endpoint.Targe
650649
externalIPs = append(externalIPs, address.Address)
651650
case v1.NodeInternalIP:
652651
internalIPs = append(internalIPs, address.Address)
653-
if suitableType(address.Address) == endpoint.RecordTypeAAAA {
654-
ipv6IPs = append(ipv6IPs, address.Address)
655-
}
656652
}
657653
}
658654
}
659655

660656
access := getAccessFromAnnotations(svc.Annotations)
661657
if access == "public" {
662-
return append(externalIPs, ipv6IPs...), nil
658+
return externalIPs, nil
663659
}
664660
if access == "private" {
665661
return internalIPs, nil
666662
}
667663
if len(externalIPs) > 0 {
668-
return append(externalIPs, ipv6IPs...), nil
664+
return externalIPs, nil
669665
}
670666
return internalIPs, nil
671667
}

0 commit comments

Comments
 (0)