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

generate A (instead of CNAME) records for <IP>.nip.io targets #2049

Closed
Closed
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
22 changes: 21 additions & 1 deletion source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const (
controllerAnnotationValue = "dns-controller"
// The annotation used for defining the desired hostname
internalHostnameAnnotationKey = "external-dns.alpha.kubernetes.io/internal-hostname"
// Suffix .nip.io of <IP>.nip.io names that we resolve to <IP> locally
nipIoSuffix = ".nip.io"
)

// Provider-specific annotations
Expand Down Expand Up @@ -189,9 +191,22 @@ func suitableType(target string) string {
if net.ParseIP(target) != nil {
return endpoint.RecordTypeA
}
if parseNipIoIP(target) != "" {
return endpoint.RecordTypeA
}
return endpoint.RecordTypeCNAME
}

func parseNipIoIP(target string) string {
if strings.HasSuffix(target, nipIoSuffix) {
ip := target[0:(len(target) - len(nipIoSuffix))]
if net.ParseIP(ip) != nil {
return ip
}
}
return ""
}

// endpointsForHostname returns the endpoint objects for each host-target combination.
func endpointsForHostname(hostname string, targets endpoint.Targets, ttl endpoint.TTL, providerSpecific endpoint.ProviderSpecific, setIdentifier string) []*endpoint.Endpoint {
var endpoints []*endpoint.Endpoint
Expand All @@ -202,7 +217,12 @@ func endpointsForHostname(hostname string, targets endpoint.Targets, ttl endpoin
for _, t := range targets {
switch suitableType(t) {
case endpoint.RecordTypeA:
aTargets = append(aTargets, t)
realIP := parseNipIoIP(t)
if realIP != "" {
aTargets = append(aTargets, realIP)
} else {
aTargets = append(aTargets, t)
}
default:
cnameTargets = append(cnameTargets, t)
}
Expand Down