@@ -276,7 +276,7 @@ func (p *HetznerProvider) fetchZones(ctx context.Context) ([]hdns.Zone, error) {
276276}
277277
278278// ensureZoneIDMappingPresent prepares the zoneIDNameMapper, that associates
279- // each ZoneID with the zone name.
279+ // each ZoneID woth the zone name.
280280func (p * HetznerProvider ) ensureZoneIDMappingPresent (zones []hdns.Zone ) {
281281 zoneIDNameMapper := provider.ZoneIDName {}
282282 for _ , z := range zones {
@@ -330,18 +330,13 @@ func makeEndpointName(domain, entryName, epType string) string {
330330// - A-Records should respect ignored networks and should only contain IPv4
331331// entries.
332332func (p HetznerProvider ) makeEndpointTarget (domain , entryTarget , recordType string ) (string , bool ) {
333- if recordType != "CNAME " {
333+ if domain == " " {
334334 return entryTarget , true
335335 }
336336
337- adjustedTarget := entryTarget
338- if ! strings .HasSuffix (entryTarget , "." ) {
339- adjustedTarget = entryTarget + "."
340- }
341-
342- if strings .HasSuffix (adjustedTarget , "." + domain + "." ) {
343- adjustedTarget = strings .TrimSuffix (adjustedTarget , "." + domain + "." )
344- }
337+ // Trim the trailing dot
338+ adjustedTarget := strings .TrimSuffix (entryTarget , "." )
339+ adjustedTarget = strings .TrimSuffix (adjustedTarget , "." + domain )
345340
346341 return adjustedTarget , true
347342}
@@ -480,7 +475,7 @@ func processCreateActions(
480475 continue
481476 }
482477
483- records := recordsByZoneID [zoneID ]
478+ records := recordsByZoneID [zoneName ]
484479
485480 for _ , ep := range endpoints {
486481 // Warn if there are existing records since we expect to create only new records.
@@ -500,6 +495,9 @@ func processCreateActions(
500495 }
501496
502497 for _ , target := range ep .Targets {
498+ if ep .RecordType == "CNAME" && ! strings .HasSuffix (target , "." ) {
499+ target += "."
500+ }
503501 log .WithFields (log.Fields {
504502 "zoneName" : zoneName ,
505503 "dnsName" : ep .DNSName ,
@@ -585,6 +583,9 @@ func processUpdateActions(
585583
586584 // Generate create and delete actions based on existence of a record for each target.
587585 for _ , target := range ep .Targets {
586+ if ep .RecordType == "CNAME" && ! strings .HasSuffix (target , "." ) {
587+ target += "."
588+ }
588589 if record , ok := matchingRecordsByTarget [target ]; ok {
589590 log .WithFields (log.Fields {
590591 "zoneName" : zoneName ,
0 commit comments