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

create an alias when record in a zone another than the target #3338

Merged
merged 1 commit into from
Jun 26, 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/pdns/pdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,18 @@ func NewPDNSProvider(ctx context.Context, config PDNSConfig) (*PDNSProvider, err
func (p *PDNSProvider) convertRRSetToEndpoints(rr pgo.RrSet) (endpoints []*endpoint.Endpoint, _ error) {
endpoints = []*endpoint.Endpoint{}
targets := []string{}
rrType_ := rr.Type_

for _, record := range rr.Records {
// If a record is "Disabled", it's not supposed to be "visible"
if !record.Disabled {
targets = append(targets, record.Content)
}
}

endpoints = append(endpoints, endpoint.NewEndpointWithTTL(rr.Name, rr.Type_, endpoint.TTL(rr.Ttl), targets...))
if rr.Type_ == "ALIAS" {
rrType_ = "CNAME"
}
endpoints = append(endpoints, endpoint.NewEndpointWithTTL(rr.Name, rrType_, endpoint.TTL(rr.Ttl), targets...))
return endpoints, nil
}

Expand Down Expand Up @@ -311,16 +314,20 @@ func (p *PDNSProvider) ConvertEndpointsToZones(eps []*endpoint.Endpoint, changet
// per (ep.DNSName, ep.RecordType) tuple, which holds true for
// external-dns v5.0.0-alpha onwards
records := []pgo.Record{}
RecordType_ := ep.RecordType
for _, t := range ep.Targets {
if ep.RecordType == "CNAME" {
if ep.RecordType == "CNAME" || ep.RecordType == "ALIAS" {
t = provider.EnsureTrailingDot(t)
if t != zone.Name && !strings.HasSuffix(t, "."+zone.Name) {
RecordType_ = "ALIAS"
}
}

records = append(records, pgo.Record{Content: t})
}
rrset := pgo.RrSet{
Name: dnsname,
Type_: ep.RecordType,
Type_: RecordType_,
Records: records,
Changetype: string(changetype),
}
Expand Down
19 changes: 15 additions & 4 deletions provider/pdns/pdns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,19 @@ var (
Type_: "CNAME",
Ttl: 300,
Records: []pgo.Record{
{Content: "example.by.any.other.name.com", Disabled: false, SetPtr: false},
{Content: "example.com.", Disabled: false, SetPtr: false},
},
}

RRSetALIASRecord = pgo.RrSet{
Name: "alias.example.com.",
Type_: "ALIAS",
Ttl: 300,
Records: []pgo.Record{
{Content: "example.by.any.other.name.com.", Disabled: false, SetPtr: false},
},
}

RRSetTXTRecord = pgo.RrSet{
Name: "example.com.",
Type_: "TXT",
Expand Down Expand Up @@ -129,9 +139,10 @@ var (
}

endpointsMixedRecords = []*endpoint.Endpoint{
endpoint.NewEndpointWithTTL("cname.example.com", endpoint.RecordTypeCNAME, endpoint.TTL(300), "example.by.any.other.name.com"),
endpoint.NewEndpointWithTTL("cname.example.com", endpoint.RecordTypeCNAME, endpoint.TTL(300), "example.com"),
endpoint.NewEndpointWithTTL("example.com", endpoint.RecordTypeTXT, endpoint.TTL(300), "'would smell as sweet'"),
endpoint.NewEndpointWithTTL("example.com", endpoint.RecordTypeA, endpoint.TTL(300), "8.8.8.8", "8.8.4.4", "4.4.4.4"),
endpoint.NewEndpointWithTTL("alias.example.com", endpoint.RecordTypeCNAME, endpoint.TTL(300), "example.by.any.other.name.com"),
}

endpointsMultipleZones = []*endpoint.Endpoint{
Expand Down Expand Up @@ -215,7 +226,7 @@ var (
Type_: "Zone",
Url: "/api/v1/servers/localhost/zones/example.com.",
Kind: "Native",
Rrsets: []pgo.RrSet{RRSetCNAMERecord, RRSetTXTRecord, RRSetMultipleRecords},
Rrsets: []pgo.RrSet{RRSetCNAMERecord, RRSetTXTRecord, RRSetMultipleRecords, RRSetALIASRecord},
}

ZoneEmptyToSimplePatch = pgo.Zone{
Expand Down Expand Up @@ -909,7 +920,7 @@ func (suite *NewPDNSProviderTestSuite) TestPDNSConvertEndpointsToZones() {

for _, z := range zlist {
for _, rs := range z.Rrsets {
if "CNAME" == rs.Type_ {
if rs.Type_ == "CNAME" {
for _, r := range rs.Records {
assert.Equal(suite.T(), uint8(0x2e), r.Content[len(r.Content)-1])
}
Expand Down