Skip to content

Commit

Permalink
Fix nomad updating -
Browse files Browse the repository at this point in the history
 - Differently verbose logging
 - Proper handling of when no changes are desired.
  • Loading branch information
gerrowadat committed Nov 5, 2023
1 parent fa3ce74 commit ade1f39
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 14 additions & 3 deletions clouddns.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ func addDomainForZone(name string, domain string) string {
}

func processCloudDnsChange(dnsSpec *CloudDNSSpec, dnsChange *dns.Change) error {
if len(dnsChange.Additions) == 0 && len(dnsChange.Deletions) == 0 {
log.Printf("No DNS changes for Cloud")
return nil
}
call := dnsSpec.svc.Changes.Create(*dnsSpec.project, *dnsSpec.zone, dnsChange)
out, err := call.Do()
if err != nil {
Expand Down Expand Up @@ -157,15 +161,23 @@ func buildNomadDnsChange(dnsSpec *CloudDNSSpec, tasks []TaskInfo, pruneMissing b
}

for _, nr := range nomad_rrs {
in_cloud := false
for _, cr := range cloud_rrs {
if nr.Name == cr.Name && nr.Type == cr.Type {
in_cloud = true
if rrsetsDiffer(nr, cr) {
// pointer in nomad differs from cloud, delete cloud record.
// pointer in nomad differs from cloud.
// Delete cloud record and replace.
log.Printf("Updating %s record in cloud: %s", nr.Type, nr.Name)
ret.Deletions = append(ret.Deletions, cr)
ret.Additions = append(ret.Additions, nr)
}
}
}
ret.Additions = append(ret.Additions, nr)
if !in_cloud {
log.Printf("Adding %s record in cloud: %s", nr.Type, nr.Name)
ret.Additions = append(ret.Additions, nr)
}
}

if pruneMissing {
Expand Down Expand Up @@ -209,7 +221,6 @@ func mergeAnswerToRrsets(rrsets []*dns.ResourceRecordSet, name string, ip string
Type: "A",
}
new_rr.Rrdatas = []string{ip}
fmt.Println("Adding new rrset:", name)
rrsets = append(rrsets, new_rr)
return rrsets
}
Expand Down
2 changes: 2 additions & 0 deletions nomad.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func syncNomad(dnsSpec *CloudDNSSpec, nomadSpec *NomadSpec, dryRun *bool, pruneM
//c := make(<-chan *dns.Change)
jobLocs := getNomadTaskLocations(nomadSpec)

log.Printf("Found %d nomad jobs", len(jobLocs))

change, err := buildNomadDnsChange(dnsSpec, jobLocs, *pruneMissing)
if err != nil {
log.Fatal("Building DNS change from nomad info:", err)
Expand Down

0 comments on commit ade1f39

Please sign in to comment.