Commit 76a95e8c authored by Matt Potter's avatar Matt Potter

refactor to remove loop / use sets.String{}

parent 743cc5d6
...@@ -333,28 +333,23 @@ func findRrset(list []dnsprovider.ResourceRecordSet, rrset dnsprovider.ResourceR ...@@ -333,28 +333,23 @@ func findRrset(list []dnsprovider.ResourceRecordSet, rrset dnsprovider.ResourceR
non-nil error is also returned (possibly along with a partially complete list of resolved endpoints. non-nil error is also returned (possibly along with a partially complete list of resolved endpoints.
*/ */
func getResolvedEndpoints(endpoints []string) ([]string, error) { func getResolvedEndpoints(endpoints []string) ([]string, error) {
resolvedEndpoints := make([]string, 0, len(endpoints)) resolvedEndpoints := sets.String{}
for _, endpoint := range endpoints { for _, endpoint := range endpoints {
if net.ParseIP(endpoint) == nil { if net.ParseIP(endpoint) == nil {
// It's not a valid IP address, so assume it's a DNS name, and try to resolve it, // It's not a valid IP address, so assume it's a DNS name, and try to resolve it,
// replacing its DNS name with its IP addresses in expandedEndpoints // replacing its DNS name with its IP addresses in expandedEndpoints
ipAddrs, err := net.LookupHost(endpoint) ipAddrs, err := net.LookupHost(endpoint)
if err != nil { if err != nil {
return resolvedEndpoints, err return resolvedEndpoints.List(), err
}
for _, ip := range ipAddrs {
resolvedEndpoints = resolvedEndpoints.Union(sets.NewString(ip))
} }
resolvedEndpoints = append(resolvedEndpoints, ipAddrs...)
} else { } else {
resolvedEndpoints = append(resolvedEndpoints, endpoint) resolvedEndpoints = resolvedEndpoints.Union(sets.NewString(endpoint))
}
}
deduped := sets.String{}
for _, endpoint := range resolvedEndpoints {
if !deduped.Has(endpoint) {
deduped.Insert(endpoint)
} }
} }
return deduped.List(), nil return resolvedEndpoints.List(), nil
} }
/* ensureDNSRrsets ensures (idempotently, and with minimum mutations) that all of the DNS resource record sets for dnsName are consistent with endpoints. /* ensureDNSRrsets ensures (idempotently, and with minimum mutations) that all of the DNS resource record sets for dnsName are consistent with endpoints.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment