Allow hostnames to be specified by annotations for gateways with wildcard hosts

This commit is contained in:
Andrew Haines 2020-06-11 20:02:17 +01:00
parent 734cb7c4ae
commit d69d191ea2
No known key found for this signature in database
GPG Key ID: 8435B896683B974A
2 changed files with 42 additions and 5 deletions

View File

@ -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
}

View File

@ -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) {