Support delegate Contour IngressRoutes

This commit is contained in:
Jonas Michel 2019-08-13 13:03:12 -05:00
parent 6c68e1bb24
commit c0c3d25b45
2 changed files with 29 additions and 10 deletions

View File

@ -304,9 +304,10 @@ func (sc *ingressRouteSource) endpointsFromIngressRoute(ingressRoute *contourapi
providerSpecific := getProviderSpecificAnnotations(ingressRoute.Annotations)
host := ingressRoute.Spec.VirtualHost.Fqdn
if host != "" {
endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific)...)
if virtualHost := ingressRoute.Spec.VirtualHost; virtualHost != nil {
if fqdn := virtualHost.Fqdn; fqdn != "" {
endpoints = append(endpoints, endpointsForHostname(fqdn, targets, ttl, providerSpecific)...)
}
}
// Skip endpoints if we do not want entries from annotations

View File

@ -234,6 +234,16 @@ func testEndpointsFromIngressRoute(t *testing.T) {
ingressRoute: fakeIngressRoute{},
expected: []*endpoint.Endpoint{},
},
{
title: "delegate ingressroute",
loadBalancer: fakeLoadBalancerService{
hostnames: []string{"lb.com"},
},
ingressRoute: fakeIngressRoute{
delegate: true,
},
expected: []*endpoint.Endpoint{},
},
} {
t.Run(ti.title, func(t *testing.T) {
if source, err := newTestIngressRouteSource(ti.loadBalancer); err != nil {
@ -1064,6 +1074,7 @@ type fakeIngressRoute struct {
host string
invalid bool
delegate bool
}
func (ir fakeIngressRoute) IngressRoute() *contour.IngressRoute {
@ -1074,17 +1085,24 @@ func (ir fakeIngressRoute) IngressRoute() *contour.IngressRoute {
status = "valid"
}
var spec contour.IngressRouteSpec
if ir.delegate {
spec = contour.IngressRouteSpec{}
} else {
spec = contour.IngressRouteSpec{
VirtualHost: &contour.VirtualHost{
Fqdn: ir.host,
},
}
}
ingressRoute := &contour.IngressRoute{
ObjectMeta: metav1.ObjectMeta{
Namespace: ir.namespace,
Name: ir.name,
Annotations: ir.annotations,
},
Spec: contour.IngressRouteSpec{
VirtualHost: &contour.VirtualHost{
Fqdn: ir.host,
},
},
Spec: spec,
Status: contour.Status{
CurrentStatus: status,
},