diff --git a/source/ambassador_host.go b/source/ambassador_host.go index 4d8659c29c..c681be54db 100644 --- a/source/ambassador_host.go +++ b/source/ambassador_host.go @@ -167,6 +167,8 @@ func (sc *ambassadorHostSource) endpointsFromHost(ctx context.Context, host *amb providerSpecific := endpoint.ProviderSpecific{} setIdentifier := "" + resource := fmt.Sprintf("host/%s/%s", host.Namespace, host.Name) + annotations := host.Annotations ttl, err := getTTLFromAnnotations(annotations) if err != nil { @@ -176,7 +178,7 @@ func (sc *ambassadorHostSource) endpointsFromHost(ctx context.Context, host *amb if host.Spec != nil { hostname := host.Spec.Hostname if hostname != "" { - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } } diff --git a/source/contour_httpproxy.go b/source/contour_httpproxy.go index 109e50f8d6..be6c7440a7 100644 --- a/source/contour_httpproxy.go +++ b/source/contour_httpproxy.go @@ -170,7 +170,6 @@ func (sc *httpProxySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, } log.Debugf("Endpoints generated from HTTPProxy: %s/%s: %v", hp.Namespace, hp.Name, hpEndpoints) - sc.setResourceLabel(hp, hpEndpoints) endpoints = append(endpoints, hpEndpoints...) } @@ -206,9 +205,11 @@ func (sc *httpProxySource) endpointsFromTemplate(httpProxy *projectcontour.HTTPP providerSpecific, setIdentifier := getProviderSpecificAnnotations(httpProxy.Annotations) + resource := fmt.Sprintf("HTTPProxy/%s/%s", httpProxy.Namespace, httpProxy.Name) + var endpoints []*endpoint.Endpoint for _, hostname := range hostnames { - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } return endpoints, nil } @@ -244,12 +245,6 @@ func (sc *httpProxySource) filterByAnnotations(httpProxies []*projectcontour.HTT return filteredList, nil } -func (sc *httpProxySource) setResourceLabel(httpProxy *projectcontour.HTTPProxy, endpoints []*endpoint.Endpoint) { - for _, ep := range endpoints { - ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("HTTPProxy/%s/%s", httpProxy.Namespace, httpProxy.Name) - } -} - // endpointsFromHTTPProxyConfig extracts the endpoints from a Contour HTTPProxy object func (sc *httpProxySource) endpointsFromHTTPProxy(httpProxy *projectcontour.HTTPProxy) ([]*endpoint.Endpoint, error) { if httpProxy.Status.CurrentStatus != "valid" { @@ -257,8 +252,6 @@ func (sc *httpProxySource) endpointsFromHTTPProxy(httpProxy *projectcontour.HTTP return nil, nil } - var endpoints []*endpoint.Endpoint - ttl, err := getTTLFromAnnotations(httpProxy.Annotations) if err != nil { log.Warn(err) @@ -279,9 +272,13 @@ func (sc *httpProxySource) endpointsFromHTTPProxy(httpProxy *projectcontour.HTTP providerSpecific, setIdentifier := getProviderSpecificAnnotations(httpProxy.Annotations) + resource := fmt.Sprintf("HTTPProxy/%s/%s", httpProxy.Namespace, httpProxy.Name) + + var endpoints []*endpoint.Endpoint + if virtualHost := httpProxy.Spec.VirtualHost; virtualHost != nil { if fqdn := virtualHost.Fqdn; fqdn != "" { - endpoints = append(endpoints, endpointsForHostname(fqdn, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(fqdn, targets, ttl, providerSpecific, setIdentifier, resource)...) } } @@ -289,7 +286,7 @@ func (sc *httpProxySource) endpointsFromHTTPProxy(httpProxy *projectcontour.HTTP if !sc.ignoreHostnameAnnotation { hostnameList := getHostnamesFromAnnotations(httpProxy.Annotations) for _, hostname := range hostnameList { - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } } diff --git a/source/gateway.go b/source/gateway.go index f48834f638..e725b9eceb 100644 --- a/source/gateway.go +++ b/source/gateway.go @@ -228,18 +228,14 @@ func (src *gatewayRouteSource) Endpoints(ctx context.Context) ([]*endpoint.Endpo } // Create endpoints from hostnames and targets. - resourceKey := fmt.Sprintf("%s/%s/%s", kind, meta.Namespace, meta.Name) + resource := fmt.Sprintf("%s/%s/%s", kind, meta.Namespace, meta.Name) providerSpecific, setIdentifier := getProviderSpecificAnnotations(annots) ttl, err := getTTLFromAnnotations(annots) if err != nil { log.Warn(err) } for host, targets := range hostTargets { - eps := endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier) - for _, ep := range eps { - ep.Labels[endpoint.ResourceLabelKey] = resourceKey - } - endpoints = append(endpoints, eps...) + endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...) } log.Debugf("Endpoints generated from %s %s/%s: %v", src.rtKind, meta.Namespace, meta.Name, endpoints) } diff --git a/source/gloo_proxy.go b/source/gloo_proxy.go index cdc7d210ce..cbacecc20e 100644 --- a/source/gloo_proxy.go +++ b/source/gloo_proxy.go @@ -162,7 +162,7 @@ func (gs *glooSource) generateEndpointsFromProxy(ctx context.Context, proxy *pro } providerSpecific, setIdentifier := getProviderSpecificAnnotations(annotations) for _, domain := range virtualHost.Domains { - endpoints = append(endpoints, endpointsForHostname(strings.TrimSuffix(domain, "."), targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(strings.TrimSuffix(domain, "."), targets, ttl, providerSpecific, setIdentifier, "")...) } } } diff --git a/source/ingress.go b/source/ingress.go index cca0ab7f6d..89450a5723 100644 --- a/source/ingress.go +++ b/source/ingress.go @@ -171,7 +171,6 @@ func (sc *ingressSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e } log.Debugf("Endpoints generated from ingress: %s/%s: %v", ing.Namespace, ing.Name, ingEndpoints) - sc.setResourceLabel(ing, ingEndpoints) sc.setDualstackLabel(ing, ingEndpoints) endpoints = append(endpoints, ingEndpoints...) } @@ -201,9 +200,11 @@ func (sc *ingressSource) endpointsFromTemplate(ing *networkv1.Ingress) ([]*endpo providerSpecific, setIdentifier := getProviderSpecificAnnotations(ing.Annotations) + resource := fmt.Sprintf("ingress/%s/%s", ing.Namespace, ing.Name) + var endpoints []*endpoint.Endpoint for _, hostname := range hostnames { - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } return endpoints, nil } @@ -276,12 +277,6 @@ func (sc *ingressSource) filterByIngressClass(ingresses []*networkv1.Ingress) ([ return filteredList, nil } -func (sc *ingressSource) setResourceLabel(ingress *networkv1.Ingress, endpoints []*endpoint.Endpoint) { - for _, ep := range endpoints { - ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("ingress/%s/%s", ingress.Namespace, ingress.Name) - } -} - func (sc *ingressSource) setDualstackLabel(ingress *networkv1.Ingress, endpoints []*endpoint.Endpoint) { val, ok := ingress.Annotations[ALBDualstackAnnotationKey] if ok && val == ALBDualstackAnnotationValue { @@ -307,6 +302,8 @@ func endpointsFromIngress(ing *networkv1.Ingress, ignoreHostnameAnnotation bool, providerSpecific, setIdentifier := getProviderSpecificAnnotations(ing.Annotations) + resource := fmt.Sprintf("ingress/%s/%s", ing.Namespace, ing.Name) + // Gather endpoints defined on hosts sections of the ingress var definedHostsEndpoints []*endpoint.Endpoint // Skip endpoints if we do not want entries from Rules section @@ -315,7 +312,7 @@ func endpointsFromIngress(ing *networkv1.Ingress, ignoreHostnameAnnotation bool, if rule.Host == "" { continue } - definedHostsEndpoints = append(definedHostsEndpoints, endpointsForHostname(rule.Host, targets, ttl, providerSpecific, setIdentifier)...) + definedHostsEndpoints = append(definedHostsEndpoints, endpointsForHostname(rule.Host, targets, ttl, providerSpecific, setIdentifier, resource)...) } } @@ -326,7 +323,7 @@ func endpointsFromIngress(ing *networkv1.Ingress, ignoreHostnameAnnotation bool, if host == "" { continue } - definedHostsEndpoints = append(definedHostsEndpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier)...) + definedHostsEndpoints = append(definedHostsEndpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...) } } } @@ -335,7 +332,7 @@ func endpointsFromIngress(ing *networkv1.Ingress, ignoreHostnameAnnotation bool, var annotationEndpoints []*endpoint.Endpoint if !ignoreHostnameAnnotation { for _, hostname := range getHostnamesFromAnnotations(ing.Annotations) { - annotationEndpoints = append(annotationEndpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + annotationEndpoints = append(annotationEndpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } } diff --git a/source/istio_gateway.go b/source/istio_gateway.go index e3dd6d8d47..4b006a6ab9 100644 --- a/source/istio_gateway.go +++ b/source/istio_gateway.go @@ -181,7 +181,6 @@ func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e } log.Debugf("Endpoints generated from gateway: %s/%s: %v", gateway.Namespace, gateway.Name, gwEndpoints) - sc.setResourceLabel(gateway, gwEndpoints) endpoints = append(endpoints, gwEndpoints...) } @@ -230,12 +229,6 @@ func (sc *gatewaySource) filterByAnnotations(gateways []*networkingv1alpha3.Gate return filteredList, nil } -func (sc *gatewaySource) setResourceLabel(gateway *networkingv1alpha3.Gateway, endpoints []*endpoint.Endpoint) { - for _, ep := range endpoints { - ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("gateway/%s/%s", gateway.Namespace, gateway.Name) - } -} - func parseIngress(ingress string) (namespace, name string, err error) { parts := strings.Split(ingress, "/") if len(parts) == 2 { @@ -329,8 +322,10 @@ func (sc *gatewaySource) endpointsFromGateway(ctx context.Context, hostnames []s providerSpecific, setIdentifier := getProviderSpecificAnnotations(annotations) + resource := fmt.Sprintf("gateway/%s/%s", gateway.Namespace, gateway.Name) + for _, host := range hostnames { - endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...) } return endpoints, nil diff --git a/source/istio_virtualservice.go b/source/istio_virtualservice.go index 64d07b412e..b6c3e212b7 100644 --- a/source/istio_virtualservice.go +++ b/source/istio_virtualservice.go @@ -169,7 +169,6 @@ func (sc *virtualServiceSource) Endpoints(ctx context.Context) ([]*endpoint.Endp } log.Debugf("Endpoints generated from VirtualService: %s/%s: %v", virtualService.Namespace, virtualService.Name, gwEndpoints) - sc.setResourceLabel(virtualService, gwEndpoints) endpoints = append(endpoints, gwEndpoints...) } @@ -230,13 +229,15 @@ func (sc *virtualServiceSource) endpointsFromTemplate(ctx context.Context, virtu providerSpecific, setIdentifier := getProviderSpecificAnnotations(virtualService.Annotations) + resource := fmt.Sprintf("virtualservice/%s/%s", virtualService.Namespace, virtualService.Name) + var endpoints []*endpoint.Endpoint for _, hostname := range hostnames { targets, err := sc.targetsFromVirtualService(ctx, virtualService, hostname) if err != nil { return endpoints, err } - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } return endpoints, nil } @@ -272,12 +273,6 @@ func (sc *virtualServiceSource) filterByAnnotations(virtualservices []*networkin return filteredList, nil } -func (sc *virtualServiceSource) setResourceLabel(virtualservice *networkingv1alpha3.VirtualService, endpoints []*endpoint.Endpoint) { - for _, ep := range endpoints { - ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("virtualservice/%s/%s", virtualservice.Namespace, virtualservice.Name) - } -} - // append a target to the list of targets unless it's already in the list func appendUnique(targets []string, target string) []string { for _, element := range targets { @@ -327,6 +322,8 @@ func (sc *virtualServiceSource) endpointsFromVirtualService(ctx context.Context, providerSpecific, setIdentifier := getProviderSpecificAnnotations(virtualservice.Annotations) + resource := fmt.Sprintf("virtualservice/%s/%s", virtualservice.Namespace, virtualservice.Name) + for _, host := range virtualservice.Spec.Hosts { if host == "" || host == "*" { continue @@ -348,7 +345,7 @@ func (sc *virtualServiceSource) endpointsFromVirtualService(ctx context.Context, } } - endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...) } // Skip endpoints if we do not want entries from annotations @@ -362,7 +359,7 @@ func (sc *virtualServiceSource) endpointsFromVirtualService(ctx context.Context, return endpoints, err } } - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } } diff --git a/source/kong_tcpingress.go b/source/kong_tcpingress.go index 6dac0a60aa..7cd7c1be6f 100644 --- a/source/kong_tcpingress.go +++ b/source/kong_tcpingress.go @@ -146,7 +146,6 @@ func (sc *kongTCPIngressSource) Endpoints(ctx context.Context) ([]*endpoint.Endp } log.Debugf("Endpoints generated from TCPIngress: %s: %v", fullname, ingressEndpoints) - sc.setResourceLabel(tcpIngress, ingressEndpoints) sc.setDualstackLabel(tcpIngress, ingressEndpoints) endpoints = append(endpoints, ingressEndpoints...) } @@ -189,12 +188,6 @@ func (sc *kongTCPIngressSource) filterByAnnotations(tcpIngresses []*TCPIngress) return filteredList, nil } -func (sc *kongTCPIngressSource) setResourceLabel(tcpIngress *TCPIngress, endpoints []*endpoint.Endpoint) { - for _, ep := range endpoints { - ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("tcpingress/%s/%s", tcpIngress.Namespace, tcpIngress.Name) - } -} - func (sc *kongTCPIngressSource) setDualstackLabel(tcpIngress *TCPIngress, endpoints []*endpoint.Endpoint) { val, ok := tcpIngress.Annotations[ALBDualstackAnnotationKey] if ok && val == ALBDualstackAnnotationValue { @@ -209,22 +202,24 @@ func (sc *kongTCPIngressSource) setDualstackLabel(tcpIngress *TCPIngress, endpoi func (sc *kongTCPIngressSource) endpointsFromTCPIngress(tcpIngress *TCPIngress, targets endpoint.Targets) ([]*endpoint.Endpoint, error) { var endpoints []*endpoint.Endpoint - providerSpecific, setIdentifier := getProviderSpecificAnnotations(tcpIngress.Annotations) - ttl, err := getTTLFromAnnotations(tcpIngress.Annotations) if err != nil { return nil, err } + providerSpecific, setIdentifier := getProviderSpecificAnnotations(tcpIngress.Annotations) + + resource := fmt.Sprintf("tcpingress/%s/%s", tcpIngress.Namespace, tcpIngress.Name) + hostnameList := getHostnamesFromAnnotations(tcpIngress.Annotations) for _, hostname := range hostnameList { - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } if tcpIngress.Spec.Rules != nil { for _, rule := range tcpIngress.Spec.Rules { if rule.Host != "" { - endpoints = append(endpoints, endpointsForHostname(rule.Host, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(rule.Host, targets, ttl, providerSpecific, setIdentifier, resource)...) } } } diff --git a/source/multisource.go b/source/multisource.go index 3844d2ccee..542b7d93d3 100644 --- a/source/multisource.go +++ b/source/multisource.go @@ -39,7 +39,7 @@ func (ms *multiSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, err } if len(ms.defaultTargets) > 0 { for i := range endpoints { - eps := endpointsForHostname(endpoints[i].DNSName, ms.defaultTargets, endpoints[i].RecordTTL, endpoints[i].ProviderSpecific, endpoints[i].SetIdentifier) + eps := endpointsForHostname(endpoints[i].DNSName, ms.defaultTargets, endpoints[i].RecordTTL, endpoints[i].ProviderSpecific, endpoints[i].SetIdentifier, "") for _, ep := range eps { ep.Labels = endpoints[i].Labels } diff --git a/source/openshift_route.go b/source/openshift_route.go index 14e0b632c8..a3cf6d4398 100644 --- a/source/openshift_route.go +++ b/source/openshift_route.go @@ -158,7 +158,6 @@ func (ors *ocpRouteSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, } log.Debugf("Endpoints generated from OpenShift Route: %s/%s: %v", ocpRoute.Namespace, ocpRoute.Name, orEndpoints) - ors.setResourceLabel(ocpRoute, orEndpoints) endpoints = append(endpoints, orEndpoints...) } @@ -188,9 +187,11 @@ func (ors *ocpRouteSource) endpointsFromTemplate(ocpRoute *routev1.Route) ([]*en providerSpecific, setIdentifier := getProviderSpecificAnnotations(ocpRoute.Annotations) + resource := fmt.Sprintf("route/%s/%s", ocpRoute.Namespace, ocpRoute.Name) + var endpoints []*endpoint.Endpoint for _, hostname := range hostnames { - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } return endpoints, nil } @@ -225,12 +226,6 @@ func (ors *ocpRouteSource) filterByAnnotations(ocpRoutes []*routev1.Route) ([]*r return filteredList, nil } -func (ors *ocpRouteSource) setResourceLabel(ocpRoute *routev1.Route, endpoints []*endpoint.Endpoint) { - for _, ep := range endpoints { - ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("route/%s/%s", ocpRoute.Namespace, ocpRoute.Name) - } -} - // endpointsFromOcpRoute extracts the endpoints from a OpenShift Route object func (ors *ocpRouteSource) endpointsFromOcpRoute(ocpRoute *routev1.Route, ignoreHostnameAnnotation bool) []*endpoint.Endpoint { var endpoints []*endpoint.Endpoint @@ -249,15 +244,17 @@ func (ors *ocpRouteSource) endpointsFromOcpRoute(ocpRoute *routev1.Route, ignore providerSpecific, setIdentifier := getProviderSpecificAnnotations(ocpRoute.Annotations) + resource := fmt.Sprintf("route/%s/%s", ocpRoute.Namespace, ocpRoute.Name) + if host != "" { - endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...) } // Skip endpoints if we do not want entries from annotations if !ignoreHostnameAnnotation { hostnameList := getHostnamesFromAnnotations(ocpRoute.Annotations) for _, hostname := range hostnameList { - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } } return endpoints diff --git a/source/skipper_routegroup.go b/source/skipper_routegroup.go index 252f0b8eb9..3d1ec380bc 100644 --- a/source/skipper_routegroup.go +++ b/source/skipper_routegroup.go @@ -279,7 +279,6 @@ func (sc *routeGroupSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint } log.Debugf("Endpoints generated from ingress: %s/%s: %v", rg.Metadata.Namespace, rg.Metadata.Name, eps) - sc.setRouteGroupResourceLabel(rg, eps) sc.setRouteGroupDualstackLabel(rg, eps) endpoints = append(endpoints, eps...) } @@ -312,22 +311,18 @@ func (sc *routeGroupSource) endpointsFromTemplate(rg *routeGroup) ([]*endpoint.E providerSpecific, setIdentifier := getProviderSpecificAnnotations(rg.Metadata.Annotations) + resource := fmt.Sprintf("routegroup/%s/%s", rg.Metadata.Namespace, rg.Metadata.Name) + var endpoints []*endpoint.Endpoint // splits the FQDN template and removes the trailing periods hostnameList := strings.Split(strings.Replace(hostnames, " ", "", -1), ",") for _, hostname := range hostnameList { hostname = strings.TrimSuffix(hostname, ".") - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } return endpoints, nil } -func (sc *routeGroupSource) setRouteGroupResourceLabel(rg *routeGroup, eps []*endpoint.Endpoint) { - for _, ep := range eps { - ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("routegroup/%s/%s", rg.Metadata.Namespace, rg.Metadata.Name) - } -} - func (sc *routeGroupSource) setRouteGroupDualstackLabel(rg *routeGroup, eps []*endpoint.Endpoint) { val, ok := rg.Metadata.Annotations[ALBDualstackAnnotationKey] if ok && val == ALBDualstackAnnotationValue { @@ -360,18 +355,20 @@ func (sc *routeGroupSource) endpointsFromRouteGroup(rg *routeGroup) []*endpoint. providerSpecific, setIdentifier := getProviderSpecificAnnotations(rg.Metadata.Annotations) + resource := fmt.Sprintf("routegroup/%s/%s", rg.Metadata.Namespace, rg.Metadata.Name) + for _, src := range rg.Spec.Hosts { if src == "" { continue } - endpoints = append(endpoints, endpointsForHostname(src, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(src, targets, ttl, providerSpecific, setIdentifier, resource)...) } // Skip endpoints if we do not want entries from annotations if !sc.ignoreHostnameAnnotation { hostnameList := getHostnamesFromAnnotations(rg.Metadata.Annotations) for _, hostname := range hostnameList { - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } } return endpoints diff --git a/source/source.go b/source/source.go index 31e9f8758c..fcc94c02d8 100644 --- a/source/source.go +++ b/source/source.go @@ -252,7 +252,7 @@ func suitableType(target string) string { } // endpointsForHostname returns the endpoint objects for each host-target combination. -func endpointsForHostname(hostname string, targets endpoint.Targets, ttl endpoint.TTL, providerSpecific endpoint.ProviderSpecific, setIdentifier string) []*endpoint.Endpoint { +func endpointsForHostname(hostname string, targets endpoint.Targets, ttl endpoint.TTL, providerSpecific endpoint.ProviderSpecific, setIdentifier string, resource string) []*endpoint.Endpoint { var endpoints []*endpoint.Endpoint var aTargets endpoint.Targets @@ -286,6 +286,9 @@ func endpointsForHostname(hostname string, targets endpoint.Targets, ttl endpoin ProviderSpecific: providerSpecific, SetIdentifier: setIdentifier, } + if resource != "" { + epA.Labels[endpoint.ResourceLabelKey] = resource + } endpoints = append(endpoints, epA) } @@ -299,6 +302,9 @@ func endpointsForHostname(hostname string, targets endpoint.Targets, ttl endpoin ProviderSpecific: providerSpecific, SetIdentifier: setIdentifier, } + if resource != "" { + epAAAA.Labels[endpoint.ResourceLabelKey] = resource + } endpoints = append(endpoints, epAAAA) } @@ -312,6 +318,9 @@ func endpointsForHostname(hostname string, targets endpoint.Targets, ttl endpoin ProviderSpecific: providerSpecific, SetIdentifier: setIdentifier, } + if resource != "" { + epCNAME.Labels[endpoint.ResourceLabelKey] = resource + } endpoints = append(endpoints, epCNAME) } return endpoints diff --git a/source/traefik_proxy.go b/source/traefik_proxy.go index 38bc75b3ee..c43fa40f8f 100644 --- a/source/traefik_proxy.go +++ b/source/traefik_proxy.go @@ -250,7 +250,6 @@ func (ts *traefikSource) ingressRouteEndpoints() ([]*endpoint.Endpoint, error) { } log.Debugf("Endpoints generated from IngressRoute: %s: %v", fullname, ingressEndpoints) - ts.setResourceLabelIngressRoute(ingressRoute, ingressEndpoints) ts.setDualstackLabelIngressRoute(ingressRoute, ingressEndpoints) endpoints = append(endpoints, ingressEndpoints...) } @@ -304,7 +303,6 @@ func (ts *traefikSource) ingressRouteTCPEndpoints() ([]*endpoint.Endpoint, error } log.Debugf("Endpoints generated from IngressRouteTCP: %s: %v", fullname, ingressEndpoints) - ts.setResourceLabelIngressRouteTCP(ingressRouteTCP, ingressEndpoints) ts.setDualstackLabelIngressRouteTCP(ingressRouteTCP, ingressEndpoints) endpoints = append(endpoints, ingressEndpoints...) } @@ -358,7 +356,6 @@ func (ts *traefikSource) ingressRouteUDPEndpoints() ([]*endpoint.Endpoint, error } log.Debugf("Endpoints generated from IngressRouteUDP: %s: %v", fullname, ingressEndpoints) - ts.setResourceLabelIngressRouteUDP(ingressRouteUDP, ingressEndpoints) ts.setDualstackLabelIngressRouteUDP(ingressRouteUDP, ingressEndpoints) endpoints = append(endpoints, ingressEndpoints...) } @@ -412,7 +409,6 @@ func (ts *traefikSource) oldIngressRouteEndpoints() ([]*endpoint.Endpoint, error } log.Debugf("Endpoints generated from IngressRoute: %s: %v", fullname, ingressEndpoints) - ts.setResourceLabelIngressRoute(ingressRoute, ingressEndpoints) ts.setDualstackLabelIngressRoute(ingressRoute, ingressEndpoints) endpoints = append(endpoints, ingressEndpoints...) } @@ -466,7 +462,6 @@ func (ts *traefikSource) oldIngressRouteTCPEndpoints() ([]*endpoint.Endpoint, er } log.Debugf("Endpoints generated from IngressRouteTCP: %s: %v", fullname, ingressEndpoints) - ts.setResourceLabelIngressRouteTCP(ingressRouteTCP, ingressEndpoints) ts.setDualstackLabelIngressRouteTCP(ingressRouteTCP, ingressEndpoints) endpoints = append(endpoints, ingressEndpoints...) } @@ -520,7 +515,6 @@ func (ts *traefikSource) oldIngressRouteUDPEndpoints() ([]*endpoint.Endpoint, er } log.Debugf("Endpoints generated from IngressRouteUDP: %s: %v", fullname, ingressEndpoints) - ts.setResourceLabelIngressRouteUDP(ingressRouteUDP, ingressEndpoints) ts.setDualstackLabelIngressRouteUDP(ingressRouteUDP, ingressEndpoints) endpoints = append(endpoints, ingressEndpoints...) } @@ -621,22 +615,6 @@ func (ts *traefikSource) filterIngressRouteUdpByAnnotations(ingressRoutes []*Ing return filteredList, nil } -func (ts *traefikSource) setResourceLabelIngressRoute(ingressroute *IngressRoute, endpoints []*endpoint.Endpoint) { - for _, ep := range endpoints { - ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("ingressroute/%s/%s", ingressroute.Namespace, ingressroute.Name) - } -} -func (ts *traefikSource) setResourceLabelIngressRouteTCP(ingressroute *IngressRouteTCP, endpoints []*endpoint.Endpoint) { - for _, ep := range endpoints { - ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("ingressroutetcp/%s/%s", ingressroute.Namespace, ingressroute.Name) - } -} -func (ts *traefikSource) setResourceLabelIngressRouteUDP(ingressroute *IngressRouteUDP, endpoints []*endpoint.Endpoint) { - for _, ep := range endpoints { - ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("ingressrouteudp/%s/%s", ingressroute.Namespace, ingressroute.Name) - } -} - func (ts *traefikSource) setDualstackLabelIngressRoute(ingressRoute *IngressRoute, endpoints []*endpoint.Endpoint) { val, ok := ingressRoute.Annotations[ALBDualstackAnnotationKey] if ok && val == ALBDualstackAnnotationValue { @@ -669,16 +647,18 @@ func (ts *traefikSource) setDualstackLabelIngressRouteUDP(ingressRoute *IngressR func (ts *traefikSource) endpointsFromIngressRoute(ingressRoute *IngressRoute, targets endpoint.Targets) ([]*endpoint.Endpoint, error) { var endpoints []*endpoint.Endpoint - providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations) - ttl, err := getTTLFromAnnotations(ingressRoute.Annotations) if err != nil { return nil, err } + providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations) + + resource := fmt.Sprintf("ingressroute/%s/%s", ingressRoute.Namespace, ingressRoute.Name) + hostnameList := getHostnamesFromAnnotations(ingressRoute.Annotations) for _, hostname := range hostnameList { - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } for _, route := range ingressRoute.Spec.Routes { @@ -691,7 +671,7 @@ func (ts *traefikSource) endpointsFromIngressRoute(ingressRoute *IngressRoute, t // Checking for host = * is required, as Host(`*`) can be set if host != "*" && host != "" { - endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...) } } } @@ -704,16 +684,18 @@ func (ts *traefikSource) endpointsFromIngressRoute(ingressRoute *IngressRoute, t func (ts *traefikSource) endpointsFromIngressRouteTCP(ingressRoute *IngressRouteTCP, targets endpoint.Targets) ([]*endpoint.Endpoint, error) { var endpoints []*endpoint.Endpoint - providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations) - ttl, err := getTTLFromAnnotations(ingressRoute.Annotations) if err != nil { return nil, err } + providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations) + + resource := fmt.Sprintf("ingressroutetcp/%s/%s", ingressRoute.Namespace, ingressRoute.Name) + hostnameList := getHostnamesFromAnnotations(ingressRoute.Annotations) for _, hostname := range hostnameList { - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } for _, route := range ingressRoute.Spec.Routes { @@ -727,7 +709,7 @@ func (ts *traefikSource) endpointsFromIngressRouteTCP(ingressRoute *IngressRoute // Checking for host = * is required, as HostSNI(`*`) can be set // in the case of TLS passthrough if host != "*" && host != "" { - endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...) } } } @@ -740,16 +722,18 @@ func (ts *traefikSource) endpointsFromIngressRouteTCP(ingressRoute *IngressRoute func (ts *traefikSource) endpointsFromIngressRouteUDP(ingressRoute *IngressRouteUDP, targets endpoint.Targets) ([]*endpoint.Endpoint, error) { var endpoints []*endpoint.Endpoint - providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations) - ttl, err := getTTLFromAnnotations(ingressRoute.Annotations) if err != nil { return nil, err } + providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations) + + resource := fmt.Sprintf("ingressrouteudp/%s/%s", ingressRoute.Namespace, ingressRoute.Name) + hostnameList := getHostnamesFromAnnotations(ingressRoute.Annotations) for _, hostname := range hostnameList { - endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) + endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...) } return endpoints, nil