Skip to content

Commit c9b82fc

Browse files
committed
roachprod: add A records during cluster create
Patch the lookup logic to handle A records in addition to SRV records and make the update/create record logic work with public records. Epic: none Release note: None
1 parent 9d6ff92 commit c9b82fc

File tree

5 files changed

+36
-24
lines changed

5 files changed

+36
-24
lines changed

pkg/roachprod/install/services.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (c *SyncedCluster) discoverServices(
154154
mu := syncutil.Mutex{}
155155
records := make([]vm.DNSRecord, 0)
156156
err := vm.FanOutDNS(c.VMs, func(dnsProvider vm.DNSProvider, _ vm.List) error {
157-
r, lookupErr := dnsProvider.LookupSRVRecords(ctx, serviceDNSName(dnsProvider, virtualClusterName, serviceType, c.Name))
157+
r, lookupErr := dnsProvider.LookupRecords(ctx, vm.SRV, serviceDNSName(dnsProvider, virtualClusterName, serviceType, c.Name))
158158
if lookupErr != nil {
159159
return lookupErr
160160
}

pkg/roachprod/vm/dns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type DNSProvider interface {
5151
// subdomain. The protocol is usually "tcp" and the subdomain is usually the
5252
// cluster name. The service is a combination of the virtual cluster name and
5353
// type of service.
54-
LookupSRVRecords(ctx context.Context, name string) ([]DNSRecord, error)
54+
LookupRecords(ctx context.Context, recordType DNSType, name string) ([]DNSRecord, error)
5555
// ListRecords lists all DNS records managed for the zone.
5656
ListRecords(ctx context.Context) ([]DNSRecord, error)
5757
// DeleteSRVRecordsBySubdomain deletes all DNS SRV records with the given subdomain.

pkg/roachprod/vm/gce/dns.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,12 @@ func (n *dnsProvider) CreateRecords(ctx context.Context, records ...vm.DNSRecord
131131
}
132132

133133
for name, recordGroup := range recordsByName {
134+
// We assume that all records in a group have the same name, type, and ttl.
135+
// TODO(herko): Add error checking to ensure that the above is the case.
136+
firstRecord := recordGroup[0]
137+
134138
err := n.withRecordLock(name, func() error {
135-
existingRecords, err := n.lookupSRVRecords(ctx, name)
139+
existingRecords, err := n.lookupRecords(ctx, firstRecord.Type, name)
136140
if err != nil {
137141
return err
138142
}
@@ -151,9 +155,6 @@ func (n *dnsProvider) CreateRecords(ctx context.Context, records ...vm.DNSRecord
151155
combinedRecords[record.Data] = record
152156
}
153157

154-
// We assume that all records in a group have the same name, type, and ttl.
155-
// TODO(herko): Add error checking to ensure that the above is the case.
156-
firstRecord := recordGroup[0]
157158
data := maps.Keys(combinedRecords)
158159
sort.Strings(data)
159160
zone := n.managedZone
@@ -194,24 +195,26 @@ func (n *dnsProvider) CreateRecords(ctx context.Context, records ...vm.DNSRecord
194195
}
195196

196197
// LookupSRVRecords implements the vm.DNSProvider interface.
197-
func (n *dnsProvider) LookupSRVRecords(ctx context.Context, name string) ([]vm.DNSRecord, error) {
198+
func (n *dnsProvider) LookupRecords(
199+
ctx context.Context, recordType vm.DNSType, name string,
200+
) ([]vm.DNSRecord, error) {
198201
var records []vm.DNSRecord
199202
var err error
200203
err = n.withRecordLock(name, func() error {
201-
if config.FastDNS {
204+
if config.FastDNS && recordType == vm.SRV {
202205
rIdx := randutil.FastUint32() % uint32(len(n.resolvers))
203206
records, err = n.fastLookupSRVRecords(ctx, n.resolvers[rIdx], name, true)
204207
return err
205208
}
206-
records, err = n.lookupSRVRecords(ctx, name)
209+
records, err = n.lookupRecords(ctx, recordType, name)
207210
return err
208211
})
209212
return records, err
210213
}
211214

212215
// ListRecords implements the vm.DNSProvider interface.
213216
func (n *dnsProvider) ListRecords(ctx context.Context) ([]vm.DNSRecord, error) {
214-
return n.listSRVRecords(ctx, "", dnsMaxResults)
217+
return n.listRecords(ctx, vm.SRV, "", dnsMaxResults)
215218
}
216219

217220
func (n *dnsProvider) deleteRecords(
@@ -253,7 +256,7 @@ func (n *dnsProvider) DeletePublicRecordsByName(ctx context.Context, names ...st
253256
// DeleteRecordsBySubdomain implements the vm.DNSProvider interface.
254257
func (n *dnsProvider) DeleteSRVRecordsBySubdomain(ctx context.Context, subdomain string) error {
255258
suffix := fmt.Sprintf("%s.%s.", subdomain, n.Domain())
256-
records, err := n.listSRVRecords(ctx, suffix, dnsMaxResults)
259+
records, err := n.listRecords(ctx, vm.SRV, suffix, dnsMaxResults)
257260
if err != nil {
258261
return err
259262
}
@@ -287,13 +290,15 @@ func (n *dnsProvider) Domain() string {
287290
// network problems. For lookups, we prefer this to using the gcloud command as
288291
// it is faster, and preferable when service information is being queried
289292
// regularly.
290-
func (n *dnsProvider) lookupSRVRecords(ctx context.Context, name string) ([]vm.DNSRecord, error) {
293+
func (n *dnsProvider) lookupRecords(
294+
ctx context.Context, recordType vm.DNSType, name string,
295+
) ([]vm.DNSRecord, error) {
291296
// Check the cache first.
292297
if cachedRecords, ok := n.getCache(name); ok {
293298
return cachedRecords, nil
294299
}
295300
// Lookup the records, if no records are found in the cache.
296-
records, err := n.listSRVRecords(ctx, name, dnsMaxResults)
301+
records, err := n.listRecords(ctx, recordType, name, dnsMaxResults)
297302
if err != nil {
298303
return nil, err
299304
}
@@ -310,16 +315,21 @@ func (n *dnsProvider) lookupSRVRecords(ctx context.Context, name string) ([]vm.D
310315
return filteredRecords, nil
311316
}
312317

313-
// listSRVRecords returns all SRV records that match the given filter from Google Cloud DNS.
318+
// listRecords returns all records that match the given filter from Google Cloud DNS.
314319
// The data field of the records could be a comma-separated list of values if multiple
315320
// records are returned for the same name.
316-
func (n *dnsProvider) listSRVRecords(
317-
ctx context.Context, filter string, limit int,
321+
func (n *dnsProvider) listRecords(
322+
ctx context.Context, recordType vm.DNSType, filter string, limit int,
318323
) ([]vm.DNSRecord, error) {
324+
zone := n.managedZone
325+
if recordType == vm.A {
326+
zone = n.publicZone
327+
}
328+
319329
args := []string{"--project", n.dnsProject, "dns", "record-sets", "list",
320330
"--limit", strconv.Itoa(limit),
321331
"--page-size", strconv.Itoa(limit),
322-
"--zone", n.managedZone,
332+
"--zone", zone,
323333
"--format", "json",
324334
}
325335
if filter != "" {
@@ -348,11 +358,11 @@ func (n *dnsProvider) listSRVRecords(
348358
if record.Kind != "dns#resourceRecordSet" {
349359
continue
350360
}
351-
if record.RecordType != string(vm.SRV) {
361+
if record.RecordType != string(recordType) {
352362
continue
353363
}
354364
for _, data := range record.RRDatas {
355-
records = append(records, vm.CreateDNSRecord(record.Name, vm.SRV, data, record.TTL))
365+
records = append(records, vm.CreateDNSRecord(record.Name, recordType, data, record.TTL))
356366
}
357367
}
358368
return records, nil

pkg/roachprod/vm/local/dns.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ func (n *dnsProvider) CreateRecords(_ context.Context, records ...vm.DNSRecord)
5858
return n.saveRecords(entries)
5959
}
6060

61-
// LookupSRVRecords is part of the vm.DNSProvider interface.
62-
func (n *dnsProvider) LookupSRVRecords(_ context.Context, name string) ([]vm.DNSRecord, error) {
61+
// LookupRecords is part of the vm.DNSProvider interface.
62+
func (n *dnsProvider) LookupRecords(
63+
_ context.Context, recordType vm.DNSType, name string,
64+
) ([]vm.DNSRecord, error) {
6365
records, err := n.loadRecords()
6466
if err != nil {
6567
return nil, err
6668
}
6769
var matchingRecords []vm.DNSRecord
6870
for _, record := range records {
69-
if record.Name == name && record.Type == vm.SRV {
71+
if record.Name == name && record.Type == recordType {
7072
matchingRecords = append(matchingRecords, record)
7173
}
7274
}

pkg/roachprod/vm/local/dns_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestLookupRecords(t *testing.T) {
4848
}...)
4949

5050
t.Run("lookup system", func(t *testing.T) {
51-
records, err := p.LookupSRVRecords(ctx, "_system-sql._tcp.local.local-zone")
51+
records, err := p.LookupRecords(ctx, vm.SRV, "_system-sql._tcp.local.local-zone")
5252
require.NoError(t, err)
5353
require.Equal(t, 3, len(records))
5454
for _, r := range records {
@@ -58,7 +58,7 @@ func TestLookupRecords(t *testing.T) {
5858
})
5959

6060
t.Run("parse SRV data", func(t *testing.T) {
61-
records, err := p.LookupSRVRecords(ctx, "_tenant-1-sql._tcp.local.local-zone")
61+
records, err := p.LookupRecords(ctx, vm.SRV, "_tenant-1-sql._tcp.local.local-zone")
6262
require.NoError(t, err)
6363
require.Equal(t, 1, len(records))
6464
data, err := records[0].ParseSRVRecord()

0 commit comments

Comments
 (0)