Merge pull request #4212 from jstudler/master

Fixing NAPTR support
This commit is contained in:
Kubernetes Prow Robot 2024-02-29 10:00:59 -08:00 committed by GitHub
commit 4dc15d917e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 70 additions and 1 deletions

View File

@ -44,6 +44,8 @@ const (
RecordTypePTR = "PTR" RecordTypePTR = "PTR"
// RecordTypeMX is a RecordType enum value // RecordTypeMX is a RecordType enum value
RecordTypeMX = "MX" RecordTypeMX = "MX"
// RecordTypeNAPTR is a RecordType enum value
RecordTypeNAPTR = "NAPTR"
) )
// TTL is a structure defining the TTL of a DNS record // TTL is a structure defining the TTL of a DNS record

View File

@ -190,7 +190,11 @@ func (cs *crdSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
illegalTarget := false illegalTarget := false
for _, target := range ep.Targets { 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 illegalTarget = true
break break
} }

View File

@ -404,6 +404,69 @@ func testCRDSourceEndpoints(t *testing.T) {
expectEndpoints: true, expectEndpoints: true,
expectError: false, 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 ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {