Skip to content

Commit

Permalink
Removing comments and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocaylent committed Mar 16, 2024
1 parent 0ca2796 commit 82046cc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
9 changes: 5 additions & 4 deletions endpoint/endpoint.go
Expand Up @@ -297,11 +297,10 @@ func FilterEndpointsByOwnerID(ownerID string, eps []*Endpoint) []*Endpoint {
visited := make(map[EndpointKey]bool)

for _, ep := range eps {
// key := EndpointKey{DNSName: ep.DNSName, RecordType: ep.RecordType, SetIdentifier: ep.SetIdentifier} --< this line passes the unit tests but I think it's wrong
key := ep.Key()
// This function should be the primary key for endpoints but it's only considering DNSName, RecordType & SetIdentifier.
// Using EndpointKey for getting the primary key using DNSName, RecordType & SetIdentifier.
if visited[key] { //Do not contain duplicated endpoints
log.Debugf(`Already loaded endpoint %v `, ep)
log.Debugf(`Skipping duplicated endpoint %v `, ep)
continue
}
if endpointOwner, ok := ep.Labels[OwnerLabelKey]; !ok || endpointOwner != ownerID {
Expand All @@ -310,7 +309,9 @@ func FilterEndpointsByOwnerID(ownerID string, eps []*Endpoint) []*Endpoint {
filtered = append(filtered, ep)
log.Debugf(`Added endpoint %v because owner id matches, found: "%s", required: "%s"`, ep, endpointOwner, ownerID)
}
if (key != EndpointKey{}) {
// Adding validation (skipping empty EndpointKeys)
// Not sure why we have cases when there are empty keys, but we do
if key != (EndpointKey{}) {
visited[key] = true
}
}
Expand Down
18 changes: 0 additions & 18 deletions provider/aws/aws.go
Expand Up @@ -980,7 +980,6 @@ 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]bool)

for _, z := range zones {
changes[aws.StringValue(z.Id)] = Route53Changes{}
Expand All @@ -995,28 +994,12 @@ func changesByZone(zones map[string]*route53.HostedZone, changeSet Route53Change
continue
}
for _, z := range zones {
// IMPORTANT EXPLAIN: I tried to fix this in here but a lot of tests started to fail in cascade.
// Found that nil recordTypes are entering in this function
// So disabling the continue will skip the deletion of duplicated records
// But this is the way we want to go. Also adding more visibility using recordType on Debug
var recordType string
if c.ResourceRecordSet.Type != nil && *c.ResourceRecordSet.Type != "" {
recordType = *c.ResourceRecordSet.Type
} else {
recordType = EmptyRecordType
}
log.Debugf("Creating key for %s to zone %s with type %s", hostname, aws.StringValue(z.Id), recordType)
key := fmt.Sprintf("%s_%s", hostname, recordType)
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)][key] {
log.Debugf("Skipping duplicate %s to zone %s [Id: %s] Type: %s", hostname, aws.StringValue(z.Name), aws.StringValue(z.Id), recordType)
//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 @@ -1032,7 +1015,6 @@ 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)][key] = true
log.Debugf("Adding %s to zone %s [Id: %s] Type: %s", hostname, aws.StringValue(z.Name), aws.StringValue(z.Id), recordType)
}
}
Expand Down

0 comments on commit 82046cc

Please sign in to comment.