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

Fixing NAPTR support #4212

Merged
merged 4 commits into from
Feb 29, 2024
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
2 changes: 2 additions & 0 deletions endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const (
RecordTypePTR = "PTR"
// RecordTypeMX is a RecordType enum value
RecordTypeMX = "MX"
// RecordTypeNAPTR is a RecordType enum value
RecordTypeNAPTR = "NAPTR"
)

// TTL is a structure defining the TTL of a DNS record
Expand Down
6 changes: 5 additions & 1 deletion source/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ func (cs *crdSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error

illegalTarget := false
for _, target := range ep.Targets {
if strings.HasSuffix(target, ".") {
if ep.RecordType != "NAPTR" && strings.HasSuffix(target, ".") {
illegalTarget = true
break
}
if ep.RecordType == "NAPTR" && !strings.HasSuffix(target, ".") {
illegalTarget = true
break
}
Expand Down
63 changes: 63 additions & 0 deletions source/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,69 @@ func testCRDSourceEndpoints(t *testing.T) {
expectEndpoints: true,
expectError: false,
},
{
title: "Create NAPTR record",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
labelFilter: "test=that",
endpoints: []*endpoint.Endpoint{
{
DNSName: "example.org",
Targets: endpoint.Targets{`100 10 "S" "SIP+D2U" "!^.*$!sip:[email protected]!" _sip._udp.example.org.`, `102 10 "S" "SIP+D2T" "!^.*$!sip:[email protected]!" _sip._tcp.example.org.`},
RecordType: endpoint.RecordTypeNAPTR,
RecordTTL: 180,
},
},
expectEndpoints: true,
expectError: false,
},
{
title: "illegal target CNAME",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
labelFilter: "test=that",
endpoints: []*endpoint.Endpoint{
{
DNSName: "example.org",
Targets: endpoint.Targets{"foo.example.org."},
RecordType: endpoint.RecordTypeCNAME,
RecordTTL: 180,
},
},
expectEndpoints: false,
expectError: false,
},
{
title: "illegal target NAPTR",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
labelFilter: "test=that",
endpoints: []*endpoint.Endpoint{
{
DNSName: "example.org",
Targets: endpoint.Targets{`100 10 "S" "SIP+D2U" "!^.*$!sip:[email protected]!" _sip._udp.example.org`, `102 10 "S" "SIP+D2T" "!^.*$!sip:[email protected]!" _sip._tcp.example.org`},
RecordType: endpoint.RecordTypeNAPTR,
RecordTTL: 180,
},
},
expectEndpoints: false,
expectError: false,
},
} {
ti := ti
t.Run(ti.title, func(t *testing.T) {
Expand Down
Loading