Skip to content
This repository has been archived by the owner on Jun 5, 2018. It is now read-only.

Commit

Permalink
Fix deleteDNSRecord
Browse files Browse the repository at this point in the history
Make sure only the desired record is deleted taking into account that
the `Start*` params only assure that `ListResourceRecordSets()` returns
the records whose attributes are lexicographically greater than the
corresponding `Start*` params.
Improve the logging in this method.
  • Loading branch information
santigimeno committed Dec 19, 2017
1 parent 61783f1 commit 1673773
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions ecssd_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,26 @@ func deleteDNSRecord(serviceName string, dockerId string) error {
r53 := route53.New(sess)
srvRecordName := serviceName + "." + DNSName
srvSetIdentifier := configuration.Hostname + ":" + dockerId
log.Infof("Deleting Record %s (%s)", srvRecordName, srvSetIdentifier)
// This API Call looks for the Route53 DNS record for this service and docker ID to get the values to delete
paramsList := &route53.ListResourceRecordSetsInput{
HostedZoneId: aws.String(configuration.HostedZoneId), // Required
MaxItems: aws.String("100"),
StartRecordName: aws.String(srvRecordName),
StartRecordType: aws.String(route53.RRTypeSrv),
HostedZoneId: aws.String(configuration.HostedZoneId), // Required
MaxItems: aws.String("100"),
StartRecordIdentifier: aws.String(srvSetIdentifier),
StartRecordName: aws.String(srvRecordName),
StartRecordType: aws.String(route53.RRTypeSrv)
}
more := true
var recordSetToDelete *route53.ResourceRecordSet
resp, err := r53.ListResourceRecordSets(paramsList)
for more && recordSetToDelete == nil && err == nil {
for _, rrset := range resp.ResourceRecordSets {
if isManagedResourceRecordSet(rrset) && *rrset.SetIdentifier == srvSetIdentifier {
if isManagedResourceRecordSet(rrset) &&
*rrset.SetIdentifier == srvSetIdentifier &&
strings.HasPrefix(*rrset.Name, srvRecordName) &&
*rrset.Type == route53.RRTypeSrv {
recordSetToDelete = rrset
break
}
}

Expand All @@ -361,7 +367,7 @@ func deleteDNSRecord(serviceName string, dockerId string) error {
return err
}
if recordSetToDelete == nil {
log.Error("Route53 record doesn't exist")
log.Errorf("Route53 record %s (%s) doesn't exist", srvRecordName, srvSetIdentifier)
return nil
}

Expand All @@ -381,7 +387,7 @@ func deleteDNSRecord(serviceName string, dockerId string) error {
_, err = r53.ChangeResourceRecordSets(params)
logErrorNoFatal(err)
if err == nil {
log.Info("Record " + srvRecordName + " deleted")
log.Infof("Record %s (%s) deleted", srvRecordName, srvSetIdentifier)
}
return err
}
Expand Down

0 comments on commit 1673773

Please sign in to comment.