diff --git a/source/gateway.go b/source/gateway.go index 3ef3e8287..338253757 100644 --- a/source/gateway.go +++ b/source/gateway.go @@ -272,11 +272,6 @@ func (sc *gatewaySource) endpointsFromGateway(hostnames []string, gateway networ providerSpecific, setIdentifier := getProviderSpecificAnnotations(annotations) - // Skip endpoints if we do not want entries from annotations - if !sc.ignoreHostnameAnnotation { - hostnames = append(hostnames, getHostnamesFromAnnotations(annotations)...) - } - for _, host := range hostnames { endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier)...) } @@ -305,6 +300,11 @@ func (sc *gatewaySource) hostNamesFromGateway(gateway networkingv1alpha3.Gateway } } } + + if !sc.ignoreHostnameAnnotation { + hostnames = append(hostnames, getHostnamesFromAnnotations(gateway.Annotations)...) + } + return hostnames, nil } diff --git a/source/gateway_test.go b/source/gateway_test.go index 9a4584710..12addfbba 100644 --- a/source/gateway_test.go +++ b/source/gateway_test.go @@ -1094,6 +1094,43 @@ func testGatewayEndpoints(t *testing.T) { }, expected: []*endpoint.Endpoint{}, }, + { + title: "gateways with wildcard host and hostname annotation", + targetNamespace: "", + lbServices: []fakeIngressGatewayService{ + { + ips: []string{"1.2.3.4"}, + }, + }, + configItems: []fakeGatewayConfig{ + { + name: "fake1", + namespace: "", + annotations: map[string]string{ + hostnameAnnotationKey: "fake1.dns-through-hostname.com", + }, + dnsnames: [][]string{{"*"}}, + }, + { + name: "fake2", + namespace: "", + annotations: map[string]string{ + hostnameAnnotationKey: "fake2.dns-through-hostname.com", + }, + dnsnames: [][]string{{"some-namespace/*"}}, + }, + }, + expected: []*endpoint.Endpoint{ + { + DNSName: "fake1.dns-through-hostname.com", + Targets: endpoint.Targets{"1.2.3.4"}, + }, + { + DNSName: "fake2.dns-through-hostname.com", + Targets: endpoint.Targets{"1.2.3.4"}, + }, + }, + }, } { t.Run(ti.title, func(t *testing.T) {