Skip to content

Commit 64d7172

Browse files
chore(source): service add fqdn tests for NodePort/SRV records
Signed-off-by: ivan katliarchuk <[email protected]>
1 parent a4522f0 commit 64d7172

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

source/service_fqdn_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
discoveryv1 "k8s.io/api/discovery/v1"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
"k8s.io/apimachinery/pkg/labels"
25+
"k8s.io/apimachinery/pkg/util/intstr"
2526
"k8s.io/client-go/kubernetes/fake"
2627
"sigs.k8s.io/external-dns/endpoint"
2728
"sigs.k8s.io/external-dns/internal/testutils"
@@ -562,6 +563,66 @@ func TestServiceSourceFqdnTemplatingExamples(t *testing.T) {
562563
{DNSName: "service-two.org.tld", RecordType: endpoint.RecordTypeA, Targets: endpoint.Targets{"10.1.20.40"}},
563564
},
564565
},
566+
{
567+
title: "templating resolve NodePort services with specific port names",
568+
services: []*v1.Service{
569+
{
570+
ObjectMeta: metav1.ObjectMeta{
571+
Namespace: "default",
572+
Name: "service-one",
573+
},
574+
Spec: v1.ServiceSpec{
575+
Type: v1.ServiceTypeNodePort,
576+
ClusterIP: "10.96.41.131", Ports: []v1.ServicePort{
577+
{Name: "http", Port: 80, TargetPort: intstr.FromInt32(8080), NodePort: 30080},
578+
{Name: "debug", Port: 8082, TargetPort: intstr.FromInt32(8082), NodePort: 30082},
579+
},
580+
},
581+
},
582+
{
583+
ObjectMeta: metav1.ObjectMeta{
584+
Namespace: "default",
585+
Name: "service-two",
586+
},
587+
Spec: v1.ServiceSpec{
588+
Type: v1.ServiceTypeClusterIP,
589+
ClusterIP: "10.96.41.132",
590+
Ports: []v1.ServicePort{
591+
{Name: "http", Port: 8080},
592+
{Name: "http2", Port: 8086},
593+
},
594+
},
595+
},
596+
{
597+
ObjectMeta: metav1.ObjectMeta{
598+
Namespace: "default",
599+
Name: "service-three",
600+
},
601+
Spec: v1.ServiceSpec{
602+
Type: v1.ServiceTypeNodePort,
603+
ClusterIP: "10.96.41.133",
604+
Ports: []v1.ServicePort{
605+
{Name: "debug", Port: 8082, TargetPort: intstr.FromInt32(8083), Protocol: v1.ProtocolUDP, NodePort: 30083},
606+
{Name: "minecraft", Port: 2525, TargetPort: intstr.FromInt32(25256), NodePort: 25565},
607+
},
608+
},
609+
},
610+
},
611+
fqdnTemplate: `{{ if eq .Spec.Type "NodePort" }}{{ range .Spec.Ports }}{{ .Name }}.host.tld{{printf "," }}{{end}}{{ end }}`,
612+
expected: []*endpoint.Endpoint{
613+
// TODO: This test shows that there is a bug that needs to be fixed in the external-dns logic. Not a critical issue, as will be filtered out by the source.
614+
{DNSName: "", RecordType: endpoint.RecordTypeA, Targets: endpoint.Targets{"10.96.41.132"}},
615+
{DNSName: "_service-one._tcp", RecordType: endpoint.RecordTypeSRV, Targets: endpoint.Targets{"0 50 30080 ", "0 50 30082 "}}, // TODO: wrong SRV target format
616+
{DNSName: "_service-one._tcp.debug.host.tld", RecordType: endpoint.RecordTypeSRV, Targets: endpoint.Targets{"0 50 30080 debug.host.tld", "0 50 30082 debug.host.tld"}},
617+
{DNSName: "_service-one._tcp.http.host.tld", RecordType: endpoint.RecordTypeSRV, Targets: endpoint.Targets{"0 50 30080 http.host.tld", "0 50 30082 http.host.tld"}},
618+
{DNSName: "_service-three._tcp", RecordType: endpoint.RecordTypeSRV, Targets: endpoint.Targets{"0 50 25565 "}}, // TODO: wrong SRV target format
619+
{DNSName: "_service-three._tcp.debug.host.tld", RecordType: endpoint.RecordTypeSRV, Targets: endpoint.Targets{"0 50 25565 debug.host.tld"}},
620+
{DNSName: "_service-three._tcp.minecraft.host.tld", RecordType: endpoint.RecordTypeSRV, Targets: endpoint.Targets{"0 50 25565 minecraft.host.tld"}},
621+
{DNSName: "_service-three._udp", RecordType: endpoint.RecordTypeSRV, Targets: endpoint.Targets{"0 50 30083 "}}, // TODO: wrong SRV target format
622+
{DNSName: "_service-three._udp.debug.host.tld", RecordType: endpoint.RecordTypeSRV, Targets: endpoint.Targets{"0 50 30083 debug.host.tld"}},
623+
{DNSName: "_service-three._udp.minecraft.host.tld", RecordType: endpoint.RecordTypeSRV, Targets: endpoint.Targets{"0 50 30083 minecraft.host.tld"}},
624+
},
625+
},
565626
} {
566627
t.Run(tt.title, func(t *testing.T) {
567628
kubeClient := fake.NewClientset()

0 commit comments

Comments
 (0)