@@ -76,6 +76,22 @@ func canonicalizeDomainNames(domains []string) []string {
7676 return cDomains
7777}
7878
79+ func canonicalizeDomainNamesForMX (domains []string ) []string {
80+ var cDomains []string
81+
82+ for _ , d := range domains {
83+ parts := strings .Split (d , " " )
84+ if len (parts ) == 2 {
85+ // If the format does not conform to the expected one, play it safe and just pass the value on.
86+ // Otherwise, canonicalize the hostname.
87+ d = fmt .Sprintf ("%s %s" , parts [0 ], canonicalizeDomainName (parts [1 ]))
88+ }
89+
90+ cDomains = append (cDomains , canonicalizeDomainName (d ))
91+ }
92+ return cDomains
93+ }
94+
7995// converts domain name to FQDN
8096func canonicalizeDomainName (d string ) string {
8197 if ! strings .HasSuffix (d , "." ) {
@@ -158,7 +174,7 @@ func (p designateProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, e
158174
159175func (p designateProvider ) supportedRecordType (recordType string ) bool {
160176 switch recordType {
161- case endpoint .RecordTypeA , endpoint .RecordTypeTXT , endpoint .RecordTypeCNAME , endpoint .RecordTypeNS :
177+ case endpoint .RecordTypeA , endpoint .RecordTypeTXT , endpoint .RecordTypeCNAME , endpoint .RecordTypeNS , endpoint . RecordTypeMX :
162178 return true
163179 default :
164180 return false
@@ -205,6 +221,9 @@ func addEndpoint(ep *endpoint.Endpoint, recordSets map[string]*recordSet, oldEnd
205221 if ep .RecordType == endpoint .RecordTypeCNAME || ep .RecordType == endpoint .RecordTypeNS {
206222 targets = canonicalizeDomainNames (targets )
207223 }
224+ if ep .RecordType == endpoint .RecordTypeMX {
225+ targets = canonicalizeDomainNamesForMX (targets )
226+ }
208227 for _ , t := range targets {
209228 rs .names [t ] = ! delete
210229 }
0 commit comments