Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NS records in the Linode provider #3987

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading