Skip to content

Commit 4dc15d9

Browse files
authored
Merge pull request #4212 from jstudler/master
Fixing NAPTR support
2 parents 8d3eb3a + 45579e1 commit 4dc15d9

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

endpoint/endpoint.go

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ const (
4444
RecordTypePTR = "PTR"
4545
// RecordTypeMX is a RecordType enum value
4646
RecordTypeMX = "MX"
47+
// RecordTypeNAPTR is a RecordType enum value
48+
RecordTypeNAPTR = "NAPTR"
4749
)
4850

4951
// TTL is a structure defining the TTL of a DNS record

source/crd.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ func (cs *crdSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
190190

191191
illegalTarget := false
192192
for _, target := range ep.Targets {
193-
if strings.HasSuffix(target, ".") {
193+
if ep.RecordType != "NAPTR" && strings.HasSuffix(target, ".") {
194+
illegalTarget = true
195+
break
196+
}
197+
if ep.RecordType == "NAPTR" && !strings.HasSuffix(target, ".") {
194198
illegalTarget = true
195199
break
196200
}

source/crd_test.go

+63
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,69 @@ func testCRDSourceEndpoints(t *testing.T) {
404404
expectEndpoints: true,
405405
expectError: false,
406406
},
407+
{
408+
title: "Create NAPTR record",
409+
registeredAPIVersion: "test.k8s.io/v1alpha1",
410+
apiVersion: "test.k8s.io/v1alpha1",
411+
registeredKind: "DNSEndpoint",
412+
kind: "DNSEndpoint",
413+
namespace: "foo",
414+
registeredNamespace: "foo",
415+
labels: map[string]string{"test": "that"},
416+
labelFilter: "test=that",
417+
endpoints: []*endpoint.Endpoint{
418+
{
419+
DNSName: "example.org",
420+
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.`},
421+
RecordType: endpoint.RecordTypeNAPTR,
422+
RecordTTL: 180,
423+
},
424+
},
425+
expectEndpoints: true,
426+
expectError: false,
427+
},
428+
{
429+
title: "illegal target CNAME",
430+
registeredAPIVersion: "test.k8s.io/v1alpha1",
431+
apiVersion: "test.k8s.io/v1alpha1",
432+
registeredKind: "DNSEndpoint",
433+
kind: "DNSEndpoint",
434+
namespace: "foo",
435+
registeredNamespace: "foo",
436+
labels: map[string]string{"test": "that"},
437+
labelFilter: "test=that",
438+
endpoints: []*endpoint.Endpoint{
439+
{
440+
DNSName: "example.org",
441+
Targets: endpoint.Targets{"foo.example.org."},
442+
RecordType: endpoint.RecordTypeCNAME,
443+
RecordTTL: 180,
444+
},
445+
},
446+
expectEndpoints: false,
447+
expectError: false,
448+
},
449+
{
450+
title: "illegal target NAPTR",
451+
registeredAPIVersion: "test.k8s.io/v1alpha1",
452+
apiVersion: "test.k8s.io/v1alpha1",
453+
registeredKind: "DNSEndpoint",
454+
kind: "DNSEndpoint",
455+
namespace: "foo",
456+
registeredNamespace: "foo",
457+
labels: map[string]string{"test": "that"},
458+
labelFilter: "test=that",
459+
endpoints: []*endpoint.Endpoint{
460+
{
461+
DNSName: "example.org",
462+
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`},
463+
RecordType: endpoint.RecordTypeNAPTR,
464+
RecordTTL: 180,
465+
},
466+
},
467+
expectEndpoints: false,
468+
expectError: false,
469+
},
407470
} {
408471
ti := ti
409472
t.Run(ti.title, func(t *testing.T) {

0 commit comments

Comments
 (0)