Skip to content

Commit

Permalink
Merge #36002
Browse files Browse the repository at this point in the history
36002: roachprod: use tmpfile for dns update r=dt a=dt

I didn't observe a local case where racing procs complained but using a tempfile should make it impossible just in case.

Release note: none.

Co-authored-by: David Taylor <tinystatemachine@gmail.com>
  • Loading branch information
craig[bot] and dt committed Mar 21, 2019
2 parents dfa23c0 + 29926a3 commit 80fec62
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/cmd/roachprod/vm/gce/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ func writeStartupScript(extraMountOpts string) (string, error) {
return tmpfile.Name(), nil
}

var dnsImportFile = os.ExpandEnv("$HOME/.roachprod/dns.bind")

// SyncDNS replaces the configured DNS zone with the supplied hosts.
func SyncDNS(names vm.List) error {
if Subdomain == "" {
Expand All @@ -149,19 +147,26 @@ func SyncDNS(names vm.List) error {
return nil
}

f, err := os.Create(dnsImportFile)
f, err := ioutil.TempFile(os.ExpandEnv("$HOME/.roachprod/"), "dns.bind")
if err != nil {
return err
}
defer f.Close()
defer func() {
if err := os.Remove(f.Name()); err != nil {
fmt.Fprintf(os.Stderr, "removing %s failed: %v", f.Name(), err)
}
}()
for _, vm := range names {
fmt.Fprintf(f, "%s 60 IN A %s\n", vm.Name, vm.PublicIP)
}
f.Close()

args := []string{"--project", dnsProject, "dns", "record-sets", "import",
"-z", dnsZone, "--delete-all-existing", "--zone-file-format", dnsImportFile}
"-z", dnsZone, "--delete-all-existing", "--zone-file-format", f.Name()}
cmd := exec.Command("gcloud", args...)
output, err := cmd.CombinedOutput()

return errors.Wrapf(err, "Command: gcloud %s\nOutput: %s", args, output)
}

Expand Down

0 comments on commit 80fec62

Please sign in to comment.