diff --git a/source/ingressroute.go b/source/ingressroute.go index 036846ef0..cf4504446 100644 --- a/source/ingressroute.go +++ b/source/ingressroute.go @@ -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 diff --git a/source/ingressroute_test.go b/source/ingressroute_test.go index 8edcc1d97..e2ddbe5da 100644 --- a/source/ingressroute_test.go +++ b/source/ingressroute_test.go @@ -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 { @@ -1062,8 +1072,9 @@ type fakeIngressRoute struct { name string annotations map[string]string - host string - invalid bool + 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, },