Skip to content

Commit

Permalink
fix: internal ipv6 being used as external
Browse files Browse the repository at this point in the history
This change undoes a check for internal IPv6 addresses to be used when
ExternalIP has been requested.
  • Loading branch information
TroyKomodo committed Oct 15, 2024
1 parent 59b2438 commit c735e76
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 22 deletions.
6 changes: 2 additions & 4 deletions source/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,9 @@ func legacyEndpointsFromDNSControllerNodePortService(svc *v1.Service, sc *servic
}
for _, address := range node.Status.Addresses {
recordType := suitableType(address.Address)
// IPv6 addresses are labeled as NodeInternalIP despite being usable externally as well.
if isExternal && (address.Type == v1.NodeExternalIP || (address.Type == v1.NodeInternalIP && recordType == endpoint.RecordTypeAAAA)) {
if isExternal && address.Type == v1.NodeExternalIP {
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, recordType, address.Address))
}
if isInternal && address.Type == v1.NodeInternalIP {
} else if isInternal && address.Type == v1.NodeInternalIP {
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, recordType, address.Address))
}
}
Expand Down
9 changes: 0 additions & 9 deletions source/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,9 @@ func (ns *nodeSource) nodeAddresses(node *v1.Node) ([]string, error) {
v1.NodeExternalIP: {},
v1.NodeInternalIP: {},
}
var ipv6Addresses []string

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

if len(addresses[v1.NodeExternalIP]) > 0 {
return append(addresses[v1.NodeExternalIP], ipv6Addresses...), nil
}

if len(addresses[v1.NodeInternalIP]) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions source/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
for _, address := range node.Status.Addresses {
recordType := suitableType(address.Address)
// IPv6 addresses are labeled as NodeInternalIP despite being usable externally as well.
if address.Type == corev1.NodeExternalIP || (address.Type == corev1.NodeInternalIP && recordType == endpoint.RecordTypeAAAA) {
if address.Type == corev1.NodeExternalIP {
addToEndpointMap(endpointMap, domain, recordType, address.Address)
}
}
Expand All @@ -139,7 +139,7 @@ func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
for _, address := range node.Status.Addresses {
recordType := suitableType(address.Address)
// IPv6 addresses are labeled as NodeInternalIP despite being usable externally as well.
if address.Type == corev1.NodeExternalIP || (address.Type == corev1.NodeInternalIP && recordType == endpoint.RecordTypeAAAA) {
if address.Type == corev1.NodeExternalIP {
addToEndpointMap(endpointMap, domain, recordType, address.Address)
}
}
Expand Down
10 changes: 3 additions & 7 deletions source/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (sc *serviceSource) extractHeadlessEndpoints(svc *v1.Service, hostname stri
return endpoints
}
for _, address := range node.Status.Addresses {
if address.Type == v1.NodeExternalIP || (address.Type == v1.NodeInternalIP && suitableType(address.Address) == endpoint.RecordTypeAAAA) {
if address.Type == v1.NodeExternalIP {
targets = append(targets, address.Address)
log.Debugf("Generating matching endpoint %s with NodeExternalIP %s", headlessDomain, address.Address)
}
Expand Down Expand Up @@ -579,7 +579,6 @@ func (sc *serviceSource) extractNodePortTargets(svc *v1.Service) (endpoint.Targe
var (
internalIPs endpoint.Targets
externalIPs endpoint.Targets
ipv6IPs endpoint.Targets
nodes []*v1.Node
err error
)
Expand Down Expand Up @@ -650,22 +649,19 @@ func (sc *serviceSource) extractNodePortTargets(svc *v1.Service) (endpoint.Targe
externalIPs = append(externalIPs, address.Address)
case v1.NodeInternalIP:
internalIPs = append(internalIPs, address.Address)
if suitableType(address.Address) == endpoint.RecordTypeAAAA {
ipv6IPs = append(ipv6IPs, address.Address)
}
}
}
}

access := getAccessFromAnnotations(svc.Annotations)
if access == "public" {
return append(externalIPs, ipv6IPs...), nil
return externalIPs, nil
}
if access == "private" {
return internalIPs, nil
}
if len(externalIPs) > 0 {
return append(externalIPs, ipv6IPs...), nil
return externalIPs, nil
}
return internalIPs, nil
}
Expand Down

0 comments on commit c735e76

Please sign in to comment.