diff --git a/endpoint/endpoint.go b/endpoint/endpoint.go index d2106ff356..a45f61ac42 100644 --- a/endpoint/endpoint.go +++ b/endpoint/endpoint.go @@ -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 diff --git a/source/crd.go b/source/crd.go index 10be3fccea..d15b176edc 100644 --- a/source/crd.go +++ b/source/crd.go @@ -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 } diff --git a/source/crd_test.go b/source/crd_test.go index 736e25f1a1..968ba8ad32 100644 --- a/source/crd_test.go +++ b/source/crd_test.go @@ -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:customer-service@example.org!" _sip._udp.example.org.`, `102 10 "S" "SIP+D2T" "!^.*$!sip:customer-service@example.org!" _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:customer-service@example.org!" _sip._udp.example.org`, `102 10 "S" "SIP+D2T" "!^.*$!sip:customer-service@example.org!" _sip._tcp.example.org`}, + RecordType: endpoint.RecordTypeNAPTR, + RecordTTL: 180, + }, + }, + expectEndpoints: false, + expectError: false, + }, } { ti := ti t.Run(ti.title, func(t *testing.T) {