Refactor setting the "resource" label into endpointsForHostname

This commit is contained in:
John Gardiner Myers 2023-07-03 19:24:05 -07:00
parent 79196a16a1
commit 39955e556e
13 changed files with 79 additions and 115 deletions

View File

@ -176,7 +176,7 @@ func (sc *ambassadorHostSource) endpointsFromHost(ctx context.Context, host *amb
if host.Spec != nil { if host.Spec != nil {
hostname := host.Spec.Hostname hostname := host.Spec.Hostname
if hostname != "" { if hostname != "" {
endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, "")...)
} }
} }

View File

@ -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) log.Debugf("Endpoints generated from HTTPProxy: %s/%s: %v", hp.Namespace, hp.Name, hpEndpoints)
sc.setResourceLabel(hp, hpEndpoints)
endpoints = append(endpoints, hpEndpoints...) endpoints = append(endpoints, hpEndpoints...)
} }
@ -206,9 +205,11 @@ func (sc *httpProxySource) endpointsFromTemplate(httpProxy *projectcontour.HTTPP
providerSpecific, setIdentifier := getProviderSpecificAnnotations(httpProxy.Annotations) providerSpecific, setIdentifier := getProviderSpecificAnnotations(httpProxy.Annotations)
resource := fmt.Sprintf("HTTPProxy/%s/%s", httpProxy.Namespace, httpProxy.Name)
var endpoints []*endpoint.Endpoint var endpoints []*endpoint.Endpoint
for _, hostname := range hostnames { 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 return endpoints, nil
} }
@ -244,12 +245,6 @@ func (sc *httpProxySource) filterByAnnotations(httpProxies []*projectcontour.HTT
return filteredList, nil 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 // endpointsFromHTTPProxyConfig extracts the endpoints from a Contour HTTPProxy object
func (sc *httpProxySource) endpointsFromHTTPProxy(httpProxy *projectcontour.HTTPProxy) ([]*endpoint.Endpoint, error) { func (sc *httpProxySource) endpointsFromHTTPProxy(httpProxy *projectcontour.HTTPProxy) ([]*endpoint.Endpoint, error) {
if httpProxy.Status.CurrentStatus != "valid" { if httpProxy.Status.CurrentStatus != "valid" {
@ -257,8 +252,6 @@ func (sc *httpProxySource) endpointsFromHTTPProxy(httpProxy *projectcontour.HTTP
return nil, nil return nil, nil
} }
var endpoints []*endpoint.Endpoint
ttl, err := getTTLFromAnnotations(httpProxy.Annotations) ttl, err := getTTLFromAnnotations(httpProxy.Annotations)
if err != nil { if err != nil {
log.Warn(err) log.Warn(err)
@ -279,9 +272,13 @@ func (sc *httpProxySource) endpointsFromHTTPProxy(httpProxy *projectcontour.HTTP
providerSpecific, setIdentifier := getProviderSpecificAnnotations(httpProxy.Annotations) 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 virtualHost := httpProxy.Spec.VirtualHost; virtualHost != nil {
if fqdn := virtualHost.Fqdn; fqdn != "" { 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 { if !sc.ignoreHostnameAnnotation {
hostnameList := getHostnamesFromAnnotations(httpProxy.Annotations) hostnameList := getHostnamesFromAnnotations(httpProxy.Annotations)
for _, hostname := range hostnameList { for _, hostname := range hostnameList {
endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...)
} }
} }

View File

@ -228,18 +228,14 @@ func (src *gatewayRouteSource) Endpoints(ctx context.Context) ([]*endpoint.Endpo
} }
// Create endpoints from hostnames and targets. // 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) providerSpecific, setIdentifier := getProviderSpecificAnnotations(annots)
ttl, err := getTTLFromAnnotations(annots) ttl, err := getTTLFromAnnotations(annots)
if err != nil { if err != nil {
log.Warn(err) log.Warn(err)
} }
for host, targets := range hostTargets { for host, targets := range hostTargets {
eps := endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier) endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...)
for _, ep := range eps {
ep.Labels[endpoint.ResourceLabelKey] = resourceKey
}
endpoints = append(endpoints, eps...)
} }
log.Debugf("Endpoints generated from %s %s/%s: %v", src.rtKind, meta.Namespace, meta.Name, endpoints) log.Debugf("Endpoints generated from %s %s/%s: %v", src.rtKind, meta.Namespace, meta.Name, endpoints)
} }

View File

@ -159,7 +159,7 @@ func (gs *glooSource) generateEndpointsFromProxy(ctx context.Context, proxy *pro
} }
providerSpecific, setIdentifier := getProviderSpecificAnnotations(annotations) providerSpecific, setIdentifier := getProviderSpecificAnnotations(annotations)
for _, domain := range virtualHost.Domains { 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, "")...)
} }
} }
} }

View File

@ -175,7 +175,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) log.Debugf("Endpoints generated from ingress: %s/%s: %v", ing.Namespace, ing.Name, ingEndpoints)
sc.setResourceLabel(ing, ingEndpoints)
sc.setDualstackLabel(ing, ingEndpoints) sc.setDualstackLabel(ing, ingEndpoints)
endpoints = append(endpoints, ingEndpoints...) endpoints = append(endpoints, ingEndpoints...)
} }
@ -205,9 +204,11 @@ func (sc *ingressSource) endpointsFromTemplate(ing *networkv1.Ingress) ([]*endpo
providerSpecific, setIdentifier := getProviderSpecificAnnotations(ing.Annotations) providerSpecific, setIdentifier := getProviderSpecificAnnotations(ing.Annotations)
resource := fmt.Sprintf("ingress/%s/%s", ing.Namespace, ing.Name)
var endpoints []*endpoint.Endpoint var endpoints []*endpoint.Endpoint
for _, hostname := range hostnames { 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 return endpoints, nil
} }
@ -280,12 +281,6 @@ func (sc *ingressSource) filterByIngressClass(ingresses []*networkv1.Ingress) ([
return filteredList, nil 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) { func (sc *ingressSource) setDualstackLabel(ingress *networkv1.Ingress, endpoints []*endpoint.Endpoint) {
val, ok := ingress.Annotations[ALBDualstackAnnotationKey] val, ok := ingress.Annotations[ALBDualstackAnnotationKey]
if ok && val == ALBDualstackAnnotationValue { if ok && val == ALBDualstackAnnotationValue {
@ -311,6 +306,8 @@ func endpointsFromIngress(ing *networkv1.Ingress, ignoreHostnameAnnotation bool,
providerSpecific, setIdentifier := getProviderSpecificAnnotations(ing.Annotations) providerSpecific, setIdentifier := getProviderSpecificAnnotations(ing.Annotations)
resource := fmt.Sprintf("ingress/%s/%s", ing.Namespace, ing.Name)
// Gather endpoints defined on hosts sections of the ingress // Gather endpoints defined on hosts sections of the ingress
var definedHostsEndpoints []*endpoint.Endpoint var definedHostsEndpoints []*endpoint.Endpoint
// Skip endpoints if we do not want entries from Rules section // Skip endpoints if we do not want entries from Rules section
@ -319,7 +316,7 @@ func endpointsFromIngress(ing *networkv1.Ingress, ignoreHostnameAnnotation bool,
if rule.Host == "" { if rule.Host == "" {
continue continue
} }
definedHostsEndpoints = append(definedHostsEndpoints, endpointsForHostname(rule.Host, targets, ttl, providerSpecific, setIdentifier)...) definedHostsEndpoints = append(definedHostsEndpoints, endpointsForHostname(rule.Host, targets, ttl, providerSpecific, setIdentifier, resource)...)
} }
} }
@ -330,7 +327,7 @@ func endpointsFromIngress(ing *networkv1.Ingress, ignoreHostnameAnnotation bool,
if host == "" { if host == "" {
continue continue
} }
definedHostsEndpoints = append(definedHostsEndpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier)...) definedHostsEndpoints = append(definedHostsEndpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...)
} }
} }
} }
@ -339,7 +336,7 @@ func endpointsFromIngress(ing *networkv1.Ingress, ignoreHostnameAnnotation bool,
var annotationEndpoints []*endpoint.Endpoint var annotationEndpoints []*endpoint.Endpoint
if !ignoreHostnameAnnotation { if !ignoreHostnameAnnotation {
for _, hostname := range getHostnamesFromAnnotations(ing.Annotations) { 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)...)
} }
} }

View File

@ -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) log.Debugf("Endpoints generated from gateway: %s/%s: %v", gateway.Namespace, gateway.Name, gwEndpoints)
sc.setResourceLabel(gateway, gwEndpoints)
endpoints = append(endpoints, gwEndpoints...) endpoints = append(endpoints, gwEndpoints...)
} }
@ -230,12 +229,6 @@ func (sc *gatewaySource) filterByAnnotations(gateways []*networkingv1alpha3.Gate
return filteredList, nil 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) { func parseIngress(ingress string) (namespace, name string, err error) {
parts := strings.Split(ingress, "/") parts := strings.Split(ingress, "/")
if len(parts) == 2 { if len(parts) == 2 {
@ -329,8 +322,10 @@ func (sc *gatewaySource) endpointsFromGateway(ctx context.Context, hostnames []s
providerSpecific, setIdentifier := getProviderSpecificAnnotations(annotations) providerSpecific, setIdentifier := getProviderSpecificAnnotations(annotations)
resource := fmt.Sprintf("gateway/%s/%s", gateway.Namespace, gateway.Name)
for _, host := range hostnames { 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 return endpoints, nil

View File

@ -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) log.Debugf("Endpoints generated from VirtualService: %s/%s: %v", virtualService.Namespace, virtualService.Name, gwEndpoints)
sc.setResourceLabel(virtualService, gwEndpoints)
endpoints = append(endpoints, gwEndpoints...) endpoints = append(endpoints, gwEndpoints...)
} }
@ -230,13 +229,15 @@ func (sc *virtualServiceSource) endpointsFromTemplate(ctx context.Context, virtu
providerSpecific, setIdentifier := getProviderSpecificAnnotations(virtualService.Annotations) providerSpecific, setIdentifier := getProviderSpecificAnnotations(virtualService.Annotations)
resource := fmt.Sprintf("virtualservice/%s/%s", virtualService.Namespace, virtualService.Name)
var endpoints []*endpoint.Endpoint var endpoints []*endpoint.Endpoint
for _, hostname := range hostnames { for _, hostname := range hostnames {
targets, err := sc.targetsFromVirtualService(ctx, virtualService, hostname) targets, err := sc.targetsFromVirtualService(ctx, virtualService, hostname)
if err != nil { if err != nil {
return endpoints, err 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 return endpoints, nil
} }
@ -272,12 +273,6 @@ func (sc *virtualServiceSource) filterByAnnotations(virtualservices []*networkin
return filteredList, nil 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 // append a target to the list of targets unless it's already in the list
func appendUnique(targets []string, target string) []string { func appendUnique(targets []string, target string) []string {
for _, element := range targets { for _, element := range targets {
@ -327,6 +322,8 @@ func (sc *virtualServiceSource) endpointsFromVirtualService(ctx context.Context,
providerSpecific, setIdentifier := getProviderSpecificAnnotations(virtualservice.Annotations) providerSpecific, setIdentifier := getProviderSpecificAnnotations(virtualservice.Annotations)
resource := fmt.Sprintf("virtualservice/%s/%s", virtualservice.Namespace, virtualservice.Name)
for _, host := range virtualservice.Spec.Hosts { for _, host := range virtualservice.Spec.Hosts {
if host == "" || host == "*" { if host == "" || host == "*" {
continue 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 // Skip endpoints if we do not want entries from annotations
@ -362,7 +359,7 @@ func (sc *virtualServiceSource) endpointsFromVirtualService(ctx context.Context,
return endpoints, err return endpoints, err
} }
} }
endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier)...) endpoints = append(endpoints, endpointsForHostname(hostname, targets, ttl, providerSpecific, setIdentifier, resource)...)
} }
} }

View File

@ -146,7 +146,6 @@ func (sc *kongTCPIngressSource) Endpoints(ctx context.Context) ([]*endpoint.Endp
} }
log.Debugf("Endpoints generated from TCPIngress: %s: %v", fullname, ingressEndpoints) log.Debugf("Endpoints generated from TCPIngress: %s: %v", fullname, ingressEndpoints)
sc.setResourceLabel(tcpIngress, ingressEndpoints)
sc.setDualstackLabel(tcpIngress, ingressEndpoints) sc.setDualstackLabel(tcpIngress, ingressEndpoints)
endpoints = append(endpoints, ingressEndpoints...) endpoints = append(endpoints, ingressEndpoints...)
} }
@ -189,12 +188,6 @@ func (sc *kongTCPIngressSource) filterByAnnotations(tcpIngresses []*TCPIngress)
return filteredList, nil 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) { func (sc *kongTCPIngressSource) setDualstackLabel(tcpIngress *TCPIngress, endpoints []*endpoint.Endpoint) {
val, ok := tcpIngress.Annotations[ALBDualstackAnnotationKey] val, ok := tcpIngress.Annotations[ALBDualstackAnnotationKey]
if ok && val == ALBDualstackAnnotationValue { 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) { func (sc *kongTCPIngressSource) endpointsFromTCPIngress(tcpIngress *TCPIngress, targets endpoint.Targets) ([]*endpoint.Endpoint, error) {
var endpoints []*endpoint.Endpoint var endpoints []*endpoint.Endpoint
providerSpecific, setIdentifier := getProviderSpecificAnnotations(tcpIngress.Annotations)
ttl, err := getTTLFromAnnotations(tcpIngress.Annotations) ttl, err := getTTLFromAnnotations(tcpIngress.Annotations)
if err != nil { if err != nil {
return nil, err return nil, err
} }
providerSpecific, setIdentifier := getProviderSpecificAnnotations(tcpIngress.Annotations)
resource := fmt.Sprintf("tcpingress/%s/%s", tcpIngress.Namespace, tcpIngress.Name)
hostnameList := getHostnamesFromAnnotations(tcpIngress.Annotations) hostnameList := getHostnamesFromAnnotations(tcpIngress.Annotations)
for _, hostname := range hostnameList { 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 { if tcpIngress.Spec.Rules != nil {
for _, rule := range tcpIngress.Spec.Rules { for _, rule := range tcpIngress.Spec.Rules {
if rule.Host != "" { if rule.Host != "" {
endpoints = append(endpoints, endpointsForHostname(rule.Host, targets, ttl, providerSpecific, setIdentifier)...) endpoints = append(endpoints, endpointsForHostname(rule.Host, targets, ttl, providerSpecific, setIdentifier, resource)...)
} }
} }
} }

View File

@ -39,7 +39,7 @@ func (ms *multiSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, err
} }
if len(ms.defaultTargets) > 0 { if len(ms.defaultTargets) > 0 {
for i := range endpoints { 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 { for _, ep := range eps {
ep.Labels = endpoints[i].Labels ep.Labels = endpoints[i].Labels
} }

View File

@ -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) log.Debugf("Endpoints generated from OpenShift Route: %s/%s: %v", ocpRoute.Namespace, ocpRoute.Name, orEndpoints)
ors.setResourceLabel(ocpRoute, orEndpoints)
endpoints = append(endpoints, orEndpoints...) endpoints = append(endpoints, orEndpoints...)
} }
@ -188,9 +187,11 @@ func (ors *ocpRouteSource) endpointsFromTemplate(ocpRoute *routev1.Route) ([]*en
providerSpecific, setIdentifier := getProviderSpecificAnnotations(ocpRoute.Annotations) providerSpecific, setIdentifier := getProviderSpecificAnnotations(ocpRoute.Annotations)
resource := fmt.Sprintf("route/%s/%s", ocpRoute.Namespace, ocpRoute.Name)
var endpoints []*endpoint.Endpoint var endpoints []*endpoint.Endpoint
for _, hostname := range hostnames { 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 return endpoints, nil
} }
@ -225,12 +226,6 @@ func (ors *ocpRouteSource) filterByAnnotations(ocpRoutes []*routev1.Route) ([]*r
return filteredList, nil 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 // endpointsFromOcpRoute extracts the endpoints from a OpenShift Route object
func (ors *ocpRouteSource) endpointsFromOcpRoute(ocpRoute *routev1.Route, ignoreHostnameAnnotation bool) []*endpoint.Endpoint { func (ors *ocpRouteSource) endpointsFromOcpRoute(ocpRoute *routev1.Route, ignoreHostnameAnnotation bool) []*endpoint.Endpoint {
var endpoints []*endpoint.Endpoint var endpoints []*endpoint.Endpoint
@ -249,15 +244,17 @@ func (ors *ocpRouteSource) endpointsFromOcpRoute(ocpRoute *routev1.Route, ignore
providerSpecific, setIdentifier := getProviderSpecificAnnotations(ocpRoute.Annotations) providerSpecific, setIdentifier := getProviderSpecificAnnotations(ocpRoute.Annotations)
resource := fmt.Sprintf("route/%s/%s", ocpRoute.Namespace, ocpRoute.Name)
if host != "" { 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 // Skip endpoints if we do not want entries from annotations
if !ignoreHostnameAnnotation { if !ignoreHostnameAnnotation {
hostnameList := getHostnamesFromAnnotations(ocpRoute.Annotations) hostnameList := getHostnamesFromAnnotations(ocpRoute.Annotations)
for _, hostname := range hostnameList { 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 return endpoints

View File

@ -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) log.Debugf("Endpoints generated from ingress: %s/%s: %v", rg.Metadata.Namespace, rg.Metadata.Name, eps)
sc.setRouteGroupResourceLabel(rg, eps)
sc.setRouteGroupDualstackLabel(rg, eps) sc.setRouteGroupDualstackLabel(rg, eps)
endpoints = append(endpoints, eps...) endpoints = append(endpoints, eps...)
} }
@ -312,22 +311,18 @@ func (sc *routeGroupSource) endpointsFromTemplate(rg *routeGroup) ([]*endpoint.E
providerSpecific, setIdentifier := getProviderSpecificAnnotations(rg.Metadata.Annotations) providerSpecific, setIdentifier := getProviderSpecificAnnotations(rg.Metadata.Annotations)
resource := fmt.Sprintf("routegroup/%s/%s", rg.Metadata.Namespace, rg.Metadata.Name)
var endpoints []*endpoint.Endpoint var endpoints []*endpoint.Endpoint
// splits the FQDN template and removes the trailing periods // splits the FQDN template and removes the trailing periods
hostnameList := strings.Split(strings.Replace(hostnames, " ", "", -1), ",") hostnameList := strings.Split(strings.Replace(hostnames, " ", "", -1), ",")
for _, hostname := range hostnameList { for _, hostname := range hostnameList {
hostname = strings.TrimSuffix(hostname, ".") 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 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) { func (sc *routeGroupSource) setRouteGroupDualstackLabel(rg *routeGroup, eps []*endpoint.Endpoint) {
val, ok := rg.Metadata.Annotations[ALBDualstackAnnotationKey] val, ok := rg.Metadata.Annotations[ALBDualstackAnnotationKey]
if ok && val == ALBDualstackAnnotationValue { if ok && val == ALBDualstackAnnotationValue {
@ -360,18 +355,20 @@ func (sc *routeGroupSource) endpointsFromRouteGroup(rg *routeGroup) []*endpoint.
providerSpecific, setIdentifier := getProviderSpecificAnnotations(rg.Metadata.Annotations) providerSpecific, setIdentifier := getProviderSpecificAnnotations(rg.Metadata.Annotations)
resource := fmt.Sprintf("routegroup/%s/%s", rg.Metadata.Namespace, rg.Metadata.Name)
for _, src := range rg.Spec.Hosts { for _, src := range rg.Spec.Hosts {
if src == "" { if src == "" {
continue 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 // Skip endpoints if we do not want entries from annotations
if !sc.ignoreHostnameAnnotation { if !sc.ignoreHostnameAnnotation {
hostnameList := getHostnamesFromAnnotations(rg.Metadata.Annotations) hostnameList := getHostnamesFromAnnotations(rg.Metadata.Annotations)
for _, hostname := range hostnameList { 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 return endpoints

View File

@ -252,7 +252,7 @@ func suitableType(target string) string {
} }
// endpointsForHostname returns the endpoint objects for each host-target combination. // 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 endpoints []*endpoint.Endpoint
var aTargets endpoint.Targets var aTargets endpoint.Targets
@ -286,6 +286,9 @@ func endpointsForHostname(hostname string, targets endpoint.Targets, ttl endpoin
ProviderSpecific: providerSpecific, ProviderSpecific: providerSpecific,
SetIdentifier: setIdentifier, SetIdentifier: setIdentifier,
} }
if resource != "" {
epA.Labels[endpoint.ResourceLabelKey] = resource
}
endpoints = append(endpoints, epA) endpoints = append(endpoints, epA)
} }
@ -299,6 +302,9 @@ func endpointsForHostname(hostname string, targets endpoint.Targets, ttl endpoin
ProviderSpecific: providerSpecific, ProviderSpecific: providerSpecific,
SetIdentifier: setIdentifier, SetIdentifier: setIdentifier,
} }
if resource != "" {
epAAAA.Labels[endpoint.ResourceLabelKey] = resource
}
endpoints = append(endpoints, epAAAA) endpoints = append(endpoints, epAAAA)
} }
@ -312,6 +318,9 @@ func endpointsForHostname(hostname string, targets endpoint.Targets, ttl endpoin
ProviderSpecific: providerSpecific, ProviderSpecific: providerSpecific,
SetIdentifier: setIdentifier, SetIdentifier: setIdentifier,
} }
if resource != "" {
epCNAME.Labels[endpoint.ResourceLabelKey] = resource
}
endpoints = append(endpoints, epCNAME) endpoints = append(endpoints, epCNAME)
} }
return endpoints return endpoints

View File

@ -250,7 +250,6 @@ func (ts *traefikSource) ingressRouteEndpoints() ([]*endpoint.Endpoint, error) {
} }
log.Debugf("Endpoints generated from IngressRoute: %s: %v", fullname, ingressEndpoints) log.Debugf("Endpoints generated from IngressRoute: %s: %v", fullname, ingressEndpoints)
ts.setResourceLabelIngressRoute(ingressRoute, ingressEndpoints)
ts.setDualstackLabelIngressRoute(ingressRoute, ingressEndpoints) ts.setDualstackLabelIngressRoute(ingressRoute, ingressEndpoints)
endpoints = append(endpoints, 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) log.Debugf("Endpoints generated from IngressRouteTCP: %s: %v", fullname, ingressEndpoints)
ts.setResourceLabelIngressRouteTCP(ingressRouteTCP, ingressEndpoints)
ts.setDualstackLabelIngressRouteTCP(ingressRouteTCP, ingressEndpoints) ts.setDualstackLabelIngressRouteTCP(ingressRouteTCP, ingressEndpoints)
endpoints = append(endpoints, 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) log.Debugf("Endpoints generated from IngressRouteUDP: %s: %v", fullname, ingressEndpoints)
ts.setResourceLabelIngressRouteUDP(ingressRouteUDP, ingressEndpoints)
ts.setDualstackLabelIngressRouteUDP(ingressRouteUDP, ingressEndpoints) ts.setDualstackLabelIngressRouteUDP(ingressRouteUDP, ingressEndpoints)
endpoints = append(endpoints, 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) log.Debugf("Endpoints generated from IngressRoute: %s: %v", fullname, ingressEndpoints)
ts.setResourceLabelIngressRoute(ingressRoute, ingressEndpoints)
ts.setDualstackLabelIngressRoute(ingressRoute, ingressEndpoints) ts.setDualstackLabelIngressRoute(ingressRoute, ingressEndpoints)
endpoints = append(endpoints, 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) log.Debugf("Endpoints generated from IngressRouteTCP: %s: %v", fullname, ingressEndpoints)
ts.setResourceLabelIngressRouteTCP(ingressRouteTCP, ingressEndpoints)
ts.setDualstackLabelIngressRouteTCP(ingressRouteTCP, ingressEndpoints) ts.setDualstackLabelIngressRouteTCP(ingressRouteTCP, ingressEndpoints)
endpoints = append(endpoints, 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) log.Debugf("Endpoints generated from IngressRouteUDP: %s: %v", fullname, ingressEndpoints)
ts.setResourceLabelIngressRouteUDP(ingressRouteUDP, ingressEndpoints)
ts.setDualstackLabelIngressRouteUDP(ingressRouteUDP, ingressEndpoints) ts.setDualstackLabelIngressRouteUDP(ingressRouteUDP, ingressEndpoints)
endpoints = append(endpoints, ingressEndpoints...) endpoints = append(endpoints, ingressEndpoints...)
} }
@ -621,22 +615,6 @@ func (ts *traefikSource) filterIngressRouteUdpByAnnotations(ingressRoutes []*Ing
return filteredList, nil 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) { func (ts *traefikSource) setDualstackLabelIngressRoute(ingressRoute *IngressRoute, endpoints []*endpoint.Endpoint) {
val, ok := ingressRoute.Annotations[ALBDualstackAnnotationKey] val, ok := ingressRoute.Annotations[ALBDualstackAnnotationKey]
if ok && val == ALBDualstackAnnotationValue { 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) { func (ts *traefikSource) endpointsFromIngressRoute(ingressRoute *IngressRoute, targets endpoint.Targets) ([]*endpoint.Endpoint, error) {
var endpoints []*endpoint.Endpoint var endpoints []*endpoint.Endpoint
providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations)
ttl, err := getTTLFromAnnotations(ingressRoute.Annotations) ttl, err := getTTLFromAnnotations(ingressRoute.Annotations)
if err != nil { if err != nil {
return nil, err return nil, err
} }
providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations)
resource := fmt.Sprintf("ingressroute/%s/%s", ingressRoute.Namespace, ingressRoute.Name)
hostnameList := getHostnamesFromAnnotations(ingressRoute.Annotations) hostnameList := getHostnamesFromAnnotations(ingressRoute.Annotations)
for _, hostname := range hostnameList { 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 { 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 // Checking for host = * is required, as Host(`*`) can be set
if host != "*" && host != "" { 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) { func (ts *traefikSource) endpointsFromIngressRouteTCP(ingressRoute *IngressRouteTCP, targets endpoint.Targets) ([]*endpoint.Endpoint, error) {
var endpoints []*endpoint.Endpoint var endpoints []*endpoint.Endpoint
providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations)
ttl, err := getTTLFromAnnotations(ingressRoute.Annotations) ttl, err := getTTLFromAnnotations(ingressRoute.Annotations)
if err != nil { if err != nil {
return nil, err return nil, err
} }
providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations)
resource := fmt.Sprintf("ingressroutetcp/%s/%s", ingressRoute.Namespace, ingressRoute.Name)
hostnameList := getHostnamesFromAnnotations(ingressRoute.Annotations) hostnameList := getHostnamesFromAnnotations(ingressRoute.Annotations)
for _, hostname := range hostnameList { 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 { 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 // Checking for host = * is required, as HostSNI(`*`) can be set
// in the case of TLS passthrough // in the case of TLS passthrough
if host != "*" && host != "" { 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) { func (ts *traefikSource) endpointsFromIngressRouteUDP(ingressRoute *IngressRouteUDP, targets endpoint.Targets) ([]*endpoint.Endpoint, error) {
var endpoints []*endpoint.Endpoint var endpoints []*endpoint.Endpoint
providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations)
ttl, err := getTTLFromAnnotations(ingressRoute.Annotations) ttl, err := getTTLFromAnnotations(ingressRoute.Annotations)
if err != nil { if err != nil {
return nil, err return nil, err
} }
providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations)
resource := fmt.Sprintf("ingressrouteudp/%s/%s", ingressRoute.Namespace, ingressRoute.Name)
hostnameList := getHostnamesFromAnnotations(ingressRoute.Annotations) hostnameList := getHostnamesFromAnnotations(ingressRoute.Annotations)
for _, hostname := range hostnameList { 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 return endpoints, nil