Skip to content

Commit

Permalink
Group By Endpoint names per Hosted Zone on AWS
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocaylent committed Mar 3, 2024
1 parent 7c7a1c3 commit 9307374
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ func sortChangesByActionNameType(cs Route53Changes) Route53Changes {
// changesByZone separates a multi-zone change into a single change per zone.
func changesByZone(zones map[string]*route53.HostedZone, changeSet Route53Changes) map[string]Route53Changes {
changes := make(map[string]Route53Changes)
visitedHostnames := make(map[string]map[string]map[string]bool)
visitedHostnames := make(map[string]map[string]bool)

for _, z := range zones {
changes[aws.StringValue(z.Id)] = Route53Changes{}
Expand All @@ -994,16 +994,18 @@ func changesByZone(zones map[string]*route53.HostedZone, changeSet Route53Change
continue
}
for _, z := range zones {
// Initialize the map for the Current Zone & Record Type if it doesn't exist
if visitedHostnames[aws.StringValue(z.Id)][*c.ResourceRecordSet.Type] == nil {
visitedHostnames[aws.StringValue(z.Id)][*c.ResourceRecordSet.Type] = make(map[string]bool)
log.Debugf("Creating key for %s to zone %s with type %s", hostname, aws.StringValue(z.Id), *c.ResourceRecordSet.Type)
key := fmt.Sprintf("%s_%s", hostname, *c.ResourceRecordSet.Type)
log.Debugf("Key Output: %s", key)
// Initialize the map for the current zone if it doesn't exist
if visitedHostnames[aws.StringValue(z.Id)] == nil {
visitedHostnames[aws.StringValue(z.Id)] = make(map[string]bool)
}

if visitedHostnames[aws.StringValue(z.Id)][*c.ResourceRecordSet.Type][hostname] {
log.Debugf("Skipping duplicate %s to zone %s [Id: %s] RecordType: %s", hostname, aws.StringValue(z.Name), aws.StringValue(z.Id), *c.ResourceRecordSet.Type)
if visitedHostnames[aws.StringValue(z.Id)][key] {
log.Debugf("Skipping duplicate %s to zone %s [Id: %s] Type: %s", hostname, aws.StringValue(z.Name), aws.StringValue(z.Id), *c.ResourceRecordSet.Type)
continue
}

if c.ResourceRecordSet.AliasTarget != nil && aws.StringValue(c.ResourceRecordSet.AliasTarget.HostedZoneId) == sameZoneAlias {
// alias record is to be created; target needs to be in the same zone as endpoint
// if it's not, this will fail
Expand All @@ -1019,8 +1021,8 @@ func changesByZone(zones map[string]*route53.HostedZone, changeSet Route53Change
}
}
changes[aws.StringValue(z.Id)] = append(changes[aws.StringValue(z.Id)], c)
visitedHostnames[aws.StringValue(z.Id)][*c.ResourceRecordSet.Type][hostname] = true
log.Debugf("Adding %s to zone %s [Id: %s] RecordType: %s", hostname, aws.StringValue(z.Name), aws.StringValue(z.Id), *c.ResourceRecordSet.Type)
visitedHostnames[aws.StringValue(z.Id)][key] = true
log.Debugf("Adding %s to zone %s [Id: %s] Type: %s", hostname, aws.StringValue(z.Name), aws.StringValue(z.Id), *c.ResourceRecordSet.Type)
}
}

Expand Down

0 comments on commit 9307374

Please sign in to comment.