diff --git a/source/source.go b/source/source.go index 132f40dcd9..210fe7532b 100644 --- a/source/source.go +++ b/source/source.go @@ -21,7 +21,7 @@ import ( "context" "fmt" "math" - "net" + "net/netip" "reflect" "strconv" "strings" @@ -257,9 +257,10 @@ func getTargetsFromTargetAnnotation(annotations map[string]string) endpoint.Targ // suitableType returns the DNS resource record type suitable for the target. // In this case type A for IPs and type CNAME for everything else. func suitableType(target string) string { - if net.ParseIP(target) != nil && net.ParseIP(target).To4() != nil { + netIP, err := netip.ParseAddr(target) + if err == nil && netIP.Is4() { return endpoint.RecordTypeA - } else if net.ParseIP(target) != nil && net.ParseIP(target).To16() != nil { + } else if err == nil && netIP.Is6() { return endpoint.RecordTypeAAAA } return endpoint.RecordTypeCNAME @@ -390,6 +391,6 @@ func waitForDynamicCacheSync(ctx context.Context, factory dynamicInformerFactory // isIPv6String returns if ip is IPv6. func isIPv6String(ip string) bool { - netIP := net.ParseIP(ip) - return netIP != nil && netIP.To4() == nil + netIP, err := netip.ParseAddr(ip) + return err == nil && netIP.Is6() }