Skip to content

Commit

Permalink
Add support for NS records in the Linode provider
Browse files Browse the repository at this point in the history
  • Loading branch information
julsemaan committed Oct 14, 2023
1 parent d7cec32 commit 5571746
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
15 changes: 11 additions & 4 deletions provider/linode/linode.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,13 @@ func (p *LinodeProvider) submitChanges(ctx context.Context, changes LinodeChange
return nil
}

func getWeight() *int {
func getWeight(recordType linodego.DomainRecordType) *int {
weight := 1

// NS records do not support having weight
if recordType == linodego.RecordTypeNS {
weight = 0
}
return &weight
}

Expand Down Expand Up @@ -331,7 +336,7 @@ func (p *LinodeProvider) ApplyChanges(ctx context.Context, changes *plan.Changes
Target: target,
Name: getStrippedRecordName(zone, ep),
Type: recordType,
Weight: getWeight(),
Weight: getWeight(recordType),
Port: getPort(),
Priority: getPriority(),
TTLSec: int(ep.RecordTTL),
Expand Down Expand Up @@ -395,7 +400,7 @@ func (p *LinodeProvider) ApplyChanges(ctx context.Context, changes *plan.Changes
Target: target,
Name: getStrippedRecordName(zone, ep),
Type: recordType,
Weight: getWeight(),
Weight: getWeight(recordType),
Port: getPort(),
Priority: getPriority(),
TTLSec: int(ep.RecordTTL),
Expand All @@ -419,7 +424,7 @@ func (p *LinodeProvider) ApplyChanges(ctx context.Context, changes *plan.Changes
Target: target,
Name: getStrippedRecordName(zone, ep),
Type: recordType,
Weight: getWeight(),
Weight: getWeight(recordType),
Port: getPort(),
Priority: getPriority(),
TTLSec: int(ep.RecordTTL),
Expand Down Expand Up @@ -515,6 +520,8 @@ func convertRecordType(recordType string) (linodego.DomainRecordType, error) {
return linodego.RecordTypeTXT, nil
case "SRV":
return linodego.RecordTypeSRV, nil
case "NS":
return linodego.RecordTypeNS, nil
default:
return "", fmt.Errorf("invalid Record Type: %s", recordType)
}
Expand Down
16 changes: 10 additions & 6 deletions provider/linode/linode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func TestLinodeConvertRecordType(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, linodego.RecordTypeSRV, record)

record, err = convertRecordType("NS")
require.NoError(t, err)
assert.Equal(t, linodego.RecordTypeNS, record)

_, err = convertRecordType("INVALID")
require.Error(t, err)
}
Expand Down Expand Up @@ -333,7 +337,7 @@ func TestLinodeApplyChanges(t *testing.T) {
11,
linodego.DomainRecordUpdateOptions{
Type: "A", Name: "", Target: "targetFoo",
Priority: getPriority(), Weight: getWeight(), Port: getPort(), TTLSec: 300,
Priority: getPriority(), Weight: getWeight(linodego.RecordTypeA), Port: getPort(), TTLSec: 300,
},
).Return(&linodego.DomainRecord{}, nil).Once()

Expand All @@ -343,7 +347,7 @@ func TestLinodeApplyChanges(t *testing.T) {
2,
linodego.DomainRecordCreateOptions{
Type: "A", Name: "create", Target: "targetBar",
Priority: getPriority(), Weight: getWeight(), Port: getPort(), TTLSec: 0,
Priority: getPriority(), Weight: getWeight(linodego.RecordTypeA), Port: getPort(), TTLSec: 0,
},
).Return(&linodego.DomainRecord{}, nil).Once()

Expand All @@ -353,7 +357,7 @@ func TestLinodeApplyChanges(t *testing.T) {
2,
linodego.DomainRecordCreateOptions{
Type: "A", Name: "", Target: "targetBar",
Priority: getPriority(), Weight: getWeight(), Port: getPort(), TTLSec: 0,
Priority: getPriority(), Weight: getWeight(linodego.RecordTypeA), Port: getPort(), TTLSec: 0,
},
).Return(&linodego.DomainRecord{}, nil).Once()

Expand Down Expand Up @@ -423,7 +427,7 @@ func TestLinodeApplyChangesTargetAdded(t *testing.T) {
11,
linodego.DomainRecordUpdateOptions{
Type: "A", Name: "", Target: "targetA",
Priority: getPriority(), Weight: getWeight(), Port: getPort(),
Priority: getPriority(), Weight: getWeight(linodego.RecordTypeA), Port: getPort(),
},
).Return(&linodego.DomainRecord{}, nil).Once()

Expand All @@ -433,7 +437,7 @@ func TestLinodeApplyChangesTargetAdded(t *testing.T) {
1,
linodego.DomainRecordCreateOptions{
Type: "A", Name: "", Target: "targetB",
Priority: getPriority(), Weight: getWeight(), Port: getPort(),
Priority: getPriority(), Weight: getWeight(linodego.RecordTypeA), Port: getPort(),
},
).Return(&linodego.DomainRecord{}, nil).Once()

Expand Down Expand Up @@ -482,7 +486,7 @@ func TestLinodeApplyChangesTargetRemoved(t *testing.T) {
12,
linodego.DomainRecordUpdateOptions{
Type: "A", Name: "", Target: "targetB",
Priority: getPriority(), Weight: getWeight(), Port: getPort(),
Priority: getPriority(), Weight: getWeight(linodego.RecordTypeA), Port: getPort(),
},
).Return(&linodego.DomainRecord{}, nil).Once()

Expand Down

0 comments on commit 5571746

Please sign in to comment.