Skip to content

Commit 18216cd

Browse files
authored
implement TTL support (#36)
1 parent 263535e commit 18216cd

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

internal/designate/provider/provider.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (p designateProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, e
143143
return nil
144144
}
145145

146-
ep := endpoint.NewEndpoint(recordSet.Name, recordSet.Type, recordSet.Records...)
146+
ep := endpoint.NewEndpointWithTTL(recordSet.Name, recordSet.Type, endpoint.TTL(recordSet.TTL), recordSet.Records...)
147147
ep.Labels[designateRecordSetID] = recordSet.ID
148148
ep.Labels[designateZoneID] = recordSet.ZoneID
149149
ep.Labels[designateOriginalRecords] = strings.Join(recordSet.Records, "\000")
@@ -166,6 +166,7 @@ type recordSet struct {
166166
recordType string
167167
zoneID string
168168
recordSetID string
169+
ttl int
169170
names map[string]bool
170171
}
171172

@@ -178,6 +179,7 @@ func addEndpoint(ep *endpoint.Endpoint, recordSets map[string]*recordSet, oldEnd
178179
dnsName: canonicalizeDomainName(ep.DNSName),
179180
recordType: ep.RecordType,
180181
names: make(map[string]bool),
182+
ttl: int(ep.RecordTTL),
181183
}
182184
}
183185

@@ -288,6 +290,7 @@ func (p designateProvider) upsertRecordSet(ctx context.Context, rs *recordSet, m
288290
Name: rs.dnsName,
289291
Type: rs.recordType,
290292
Records: records,
293+
TTL: rs.ttl,
291294
}
292295
log.Infof("Creating records: %s/%s: %s", rs.dnsName, rs.recordType, strings.Join(records, ","))
293296
if p.dryRun {
@@ -302,10 +305,9 @@ func (p designateProvider) upsertRecordSet(ctx context.Context, rs *recordSet, m
302305
}
303306
return p.client.DeleteRecordSet(ctx, rs.zoneID, rs.recordSetID)
304307
} else {
305-
ttl := 0
306308
opts := recordsets.UpdateOpts{
307309
Records: records,
308-
TTL: &ttl,
310+
TTL: &rs.ttl,
309311
}
310312
log.Infof("Updating records: %s/%s: %s", rs.dnsName, rs.recordType, strings.Join(records, ","))
311313
if p.dryRun {

internal/designate/provider/provider_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ func TestDesignateRecords(t *testing.T) {
238238
rs14ID, _ := client.CreateRecordSet(ctx, zone1ID, recordsets.CreateOpts{
239239
Name: "ftp.example.com.",
240240
Type: endpoint.RecordTypeA,
241+
TTL: 120,
241242
Records: []string{"10.1.1.2"},
242243
})
243244

@@ -281,6 +282,7 @@ func TestDesignateRecords(t *testing.T) {
281282
DNSName: "ftp.example.com",
282283
RecordType: endpoint.RecordTypeA,
283284
Targets: endpoint.Targets{"10.1.1.2"},
285+
RecordTTL: 120,
284286
Labels: map[string]string{
285287
designateRecordSetID: rs14ID,
286288
designateZoneID: zone1ID,
@@ -321,7 +323,7 @@ out:
321323
continue out
322324
}
323325
}
324-
t.Errorf("unexpected endpoint %s/%s -> %s", ep.DNSName, ep.RecordType, ep.Targets)
326+
t.Errorf("unexpected endpoint %s/%s (TTL: %d) -> %s", ep.DNSName, ep.RecordType, ep.RecordTTL, ep.Targets)
325327
}
326328
if len(expected) != 0 {
327329
t.Errorf("not all expected endpoints were returned. Remained: %v", expected)
@@ -353,7 +355,7 @@ func testDesignateCreateRecords(t *testing.T, client *fakeDesignateClient) []*re
353355
})
354356

355357
if err != nil {
356-
t.Fatal("failed to prefil records")
358+
t.Fatal("failed to prefill records")
357359
}
358360

359361
endpoints := []*endpoint.Endpoint{
@@ -373,6 +375,7 @@ func testDesignateCreateRecords(t *testing.T, client *fakeDesignateClient) []*re
373375
DNSName: "ftp.example.com",
374376
RecordType: endpoint.RecordTypeA,
375377
Targets: endpoint.Targets{"10.1.1.2"},
378+
RecordTTL: 120,
376379
Labels: map[string]string{},
377380
},
378381
{
@@ -411,6 +414,7 @@ func testDesignateCreateRecords(t *testing.T, client *fakeDesignateClient) []*re
411414
Name: "ftp.example.com.",
412415
Type: endpoint.RecordTypeA,
413416
Records: []string{"10.1.1.2"},
417+
TTL: 120,
414418
ZoneID: "zone-1",
415419
},
416420
{
@@ -473,6 +477,7 @@ func testDesignateUpdateRecords(t *testing.T, client *fakeDesignateClient) []*re
473477
DNSName: "ftp.example.com",
474478
RecordType: endpoint.RecordTypeA,
475479
Targets: endpoint.Targets{"10.1.1.2"},
480+
RecordTTL: 120,
476481
Labels: map[string]string{
477482
designateZoneID: "zone-1",
478483
designateRecordSetID: expected[2].ID,
@@ -495,6 +500,7 @@ func testDesignateUpdateRecords(t *testing.T, client *fakeDesignateClient) []*re
495500
DNSName: "ftp.example.com",
496501
RecordType: endpoint.RecordTypeA,
497502
Targets: endpoint.Targets{"10.3.3.1"},
503+
RecordTTL: 60,
498504
Labels: map[string]string{
499505
designateZoneID: "zone-1",
500506
designateRecordSetID: expected[2].ID,

0 commit comments

Comments
 (0)