Skip to content

Commit

Permalink
fix(google): ensure DNS records have trailing dot before sending
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Linkhorst committed Apr 14, 2017
1 parent 9f712c1 commit 4abb745
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions provider/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package provider

import (
"net"
"strings"

log "github.com/Sirupsen/logrus"
Expand Down Expand Up @@ -291,13 +292,22 @@ func newRecords(endpoints []*endpoint.Endpoint) []*dns.ResourceRecordSet {
// newRecord returns a RecordSet based on the given endpoint.
func newRecord(endpoint *endpoint.Endpoint) *dns.ResourceRecordSet {
return &dns.ResourceRecordSet{
Name: endpoint.DNSName,
Rrdatas: []string{endpoint.Target},
Name: ensureTrailingDot(endpoint.DNSName),
Rrdatas: []string{ensureTrailingDot(endpoint.Target)},
Ttl: 300,
Type: suitableType(endpoint.Target),
}
}

// ensureTrailingDot ensures that the hostname receives a trailing dot if it hasn't already.
func ensureTrailingDot(hostname string) string {
if net.ParseIP(hostname) != nil {
return hostname
}

return strings.TrimSuffix(hostname, ".") + "."
}

// isNotFound returns true if a given error is due to a resource not being found.
func isNotFound(err error) bool {
return strings.Contains(err.Error(), "notFound")
Expand Down

0 comments on commit 4abb745

Please sign in to comment.