From 557174635ac79aa0ce1768fc7ee652fd8ac82b56 Mon Sep 17 00:00:00 2001 From: Julien Semaan Date: Fri, 13 Oct 2023 14:17:37 -0400 Subject: [PATCH] Add support for NS records in the Linode provider --- provider/linode/linode.go | 15 +++++++++++---- provider/linode/linode_test.go | 16 ++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/provider/linode/linode.go b/provider/linode/linode.go index b37615d03c..20495b7335 100644 --- a/provider/linode/linode.go +++ b/provider/linode/linode.go @@ -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 } @@ -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), @@ -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), @@ -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), @@ -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) } diff --git a/provider/linode/linode_test.go b/provider/linode/linode_test.go index 3be994fe74..9f33ff00e4 100644 --- a/provider/linode/linode_test.go +++ b/provider/linode/linode_test.go @@ -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) } @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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()