@@ -34,6 +34,7 @@ import (
3434 "k8s.io/apimachinery/pkg/types"
3535 "k8s.io/apimachinery/pkg/util/intstr"
3636 "k8s.io/client-go/kubernetes/fake"
37+ "sigs.k8s.io/external-dns/internal/testutils"
3738
3839 "sigs.k8s.io/external-dns/endpoint"
3940)
@@ -1732,6 +1733,156 @@ func TestTransformerInIstioGatewaySource(t *testing.T) {
17321733 }, rService .Spec .Selector )
17331734}
17341735
1736+ func TestSingleGatewayMultipleServicesPointingToSameLoadBalancer (t * testing.T ) {
1737+ fakeKubeClient := fake .NewClientset ()
1738+ fakeIstioClient := istiofake .NewSimpleClientset ()
1739+
1740+ gw := & networkingv1beta1.Gateway {
1741+ ObjectMeta : metav1.ObjectMeta {
1742+ Name : "argocd" ,
1743+ Namespace : "argocd" ,
1744+ },
1745+ Spec : istionetworking.Gateway {
1746+ Servers : []* istionetworking.Server {
1747+ {
1748+ Hosts : []string {"example.org" },
1749+ Tls : & istionetworking.ServerTLSSettings {
1750+ HttpsRedirect : true ,
1751+ },
1752+ },
1753+ {
1754+ Hosts : []string {"example.org" },
1755+ Tls : & istionetworking.ServerTLSSettings {
1756+ ServerCertificate : IstioGatewayIngressSource ,
1757+ Mode : istionetworking .ServerTLSSettings_SIMPLE ,
1758+ },
1759+ },
1760+ },
1761+ Selector : map [string ]string {
1762+ "istio" : "ingressgateway" ,
1763+ },
1764+ },
1765+ }
1766+
1767+ services := []* v1.Service {
1768+ {
1769+ ObjectMeta : metav1.ObjectMeta {
1770+ Name : "istio-ingressgateway" ,
1771+ Namespace : "default" ,
1772+ Labels : map [string ]string {
1773+ "app" : "istio-ingressgateway" ,
1774+ "istio" : "ingressgateway" ,
1775+ },
1776+ },
1777+ Spec : v1.ServiceSpec {
1778+ Type : v1 .ServiceTypeLoadBalancer ,
1779+ ClusterIP : "10.118.223.3" ,
1780+ ClusterIPs : []string {"10.118.223.3" },
1781+ ExternalTrafficPolicy : v1 .ServiceExternalTrafficPolicyCluster ,
1782+ IPFamilies : []v1.IPFamily {v1 .IPv4Protocol },
1783+ IPFamilyPolicy : testutils .ToPtr (v1 .IPFamilyPolicySingleStack ),
1784+ Ports : []v1.ServicePort {
1785+ {
1786+ Name : "http2" ,
1787+ Port : 80 ,
1788+ Protocol : v1 .ProtocolTCP ,
1789+ TargetPort : intstr .FromInt32 (8080 ),
1790+ NodePort : 30127 ,
1791+ },
1792+ },
1793+ Selector : map [string ]string {
1794+ "app" : "istio-ingressgateway" ,
1795+ "istio" : "ingressgateway" ,
1796+ },
1797+ SessionAffinity : v1 .ServiceAffinityNone ,
1798+ },
1799+ Status : v1.ServiceStatus {
1800+ LoadBalancer : v1.LoadBalancerStatus {
1801+ Ingress : []v1.LoadBalancerIngress {
1802+ {
1803+ IP : "34.66.66.77" ,
1804+ IPMode : testutils .ToPtr (v1 .LoadBalancerIPModeVIP ),
1805+ },
1806+ },
1807+ },
1808+ },
1809+ },
1810+ {
1811+ ObjectMeta : metav1.ObjectMeta {
1812+ Name : "istio-ingressgatewayudp" ,
1813+ Namespace : "default" ,
1814+ Labels : map [string ]string {
1815+ "app" : "istio-ingressgatewayudp" ,
1816+ "istio" : "ingressgateway" ,
1817+ },
1818+ },
1819+ Spec : v1.ServiceSpec {
1820+ Type : v1 .ServiceTypeLoadBalancer ,
1821+ ClusterIP : "10.118.220.130" ,
1822+ ClusterIPs : []string {"10.118.220.130" },
1823+ ExternalTrafficPolicy : v1 .ServiceExternalTrafficPolicyCluster ,
1824+ IPFamilies : []v1.IPFamily {v1 .IPv4Protocol },
1825+ IPFamilyPolicy : testutils .ToPtr (v1 .IPFamilyPolicySingleStack ),
1826+ Ports : []v1.ServicePort {
1827+ {
1828+ Name : "upd-dns" ,
1829+ Port : 53 ,
1830+ Protocol : v1 .ProtocolUDP ,
1831+ TargetPort : intstr .FromInt32 (5353 ),
1832+ NodePort : 30873 ,
1833+ },
1834+ },
1835+ Selector : map [string ]string {
1836+ "app" : "istio-ingressgatewayudp" ,
1837+ "istio" : "ingressgateway" ,
1838+ },
1839+ SessionAffinity : v1 .ServiceAffinityNone ,
1840+ },
1841+ Status : v1.ServiceStatus {
1842+ LoadBalancer : v1.LoadBalancerStatus {
1843+ Ingress : []v1.LoadBalancerIngress {
1844+ {
1845+ IP : "34.66.66.77" ,
1846+ IPMode : testutils .ToPtr (v1 .LoadBalancerIPModeVIP ),
1847+ },
1848+ },
1849+ },
1850+ },
1851+ },
1852+ }
1853+
1854+ assert .NotNil (t , services )
1855+
1856+ for _ , svc := range services {
1857+ _ , err := fakeKubeClient .CoreV1 ().Services (svc .Namespace ).Create (t .Context (), svc , metav1.CreateOptions {})
1858+ require .NoError (t , err )
1859+ }
1860+
1861+ _ , err := fakeIstioClient .NetworkingV1beta1 ().Gateways (gw .Namespace ).Create (t .Context (), gw , metav1.CreateOptions {})
1862+ require .NoError (t , err )
1863+
1864+ src , err := NewIstioGatewaySource (
1865+ t .Context (),
1866+ fakeKubeClient ,
1867+ fakeIstioClient ,
1868+ "" ,
1869+ "" ,
1870+ "" ,
1871+ false ,
1872+ false ,
1873+ )
1874+ require .NoError (t , err )
1875+ require .NotNil (t , src )
1876+
1877+ got , err := src .Endpoints (t .Context ())
1878+ require .NoError (t , err )
1879+
1880+ validateEndpoints (t , got , []* endpoint.Endpoint {
1881+ endpoint .NewEndpoint ("example.org" , endpoint .RecordTypeA , "34.66.66.77" ).WithLabel (endpoint .ResourceLabelKey , "gateway/argocd/argocd" ),
1882+ endpoint .NewEndpoint ("example.org" , endpoint .RecordTypeA , "34.66.66.77" ).WithLabel (endpoint .ResourceLabelKey , "gateway/argocd/argocd" ),
1883+ })
1884+ }
1885+
17351886// gateway specific helper functions
17361887func newTestGatewaySource (loadBalancerList []fakeIngressGatewayService , ingressList []fakeIngress ) (* gatewaySource , error ) {
17371888 fakeKubernetesClient := fake .NewClientset ()
0 commit comments