diff --git a/source/ambassador_host.go b/source/ambassador_host.go index 32fc6effbe..d06e79ed7a 100644 --- a/source/ambassador_host.go +++ b/source/ambassador_host.go @@ -173,10 +173,7 @@ func (sc *ambassadorHostSource) endpointsFromHost(ctx context.Context, host *amb resource := fmt.Sprintf("host/%s/%s", host.Namespace, host.Name) annotations := host.Annotations - ttl, err := getTTLFromAnnotations(annotations) - if err != nil { - return nil, err - } + ttl := getTTLFromAnnotations(annotations, resource) if host.Spec != nil { hostname := host.Spec.Hostname diff --git a/source/contour_httpproxy.go b/source/contour_httpproxy.go index be6c7440a7..818646e420 100644 --- a/source/contour_httpproxy.go +++ b/source/contour_httpproxy.go @@ -186,10 +186,9 @@ func (sc *httpProxySource) endpointsFromTemplate(httpProxy *projectcontour.HTTPP return nil, err } - ttl, err := getTTLFromAnnotations(httpProxy.Annotations) - if err != nil { - log.Warn(err) - } + resource := fmt.Sprintf("HTTPProxy/%s/%s", httpProxy.Namespace, httpProxy.Name) + + ttl := getTTLFromAnnotations(httpProxy.Annotations, resource) targets := getTargetsFromTargetAnnotation(httpProxy.Annotations) if len(targets) == 0 { @@ -205,8 +204,6 @@ 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, resource)...) @@ -252,10 +249,9 @@ func (sc *httpProxySource) endpointsFromHTTPProxy(httpProxy *projectcontour.HTTP return nil, nil } - ttl, err := getTTLFromAnnotations(httpProxy.Annotations) - if err != nil { - log.Warn(err) - } + resource := fmt.Sprintf("HTTPProxy/%s/%s", httpProxy.Namespace, httpProxy.Name) + + ttl := getTTLFromAnnotations(httpProxy.Annotations, resource) targets := getTargetsFromTargetAnnotation(httpProxy.Annotations) @@ -272,8 +268,6 @@ 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 { diff --git a/source/f5_virtualserver.go b/source/f5_virtualserver.go index ed3ef853a0..8e7b251a00 100644 --- a/source/f5_virtualserver.go +++ b/source/f5_virtualserver.go @@ -147,10 +147,9 @@ func (vs *f5VirtualServerSource) endpointsFromVirtualServers(virtualServers []*f var endpoints []*endpoint.Endpoint for _, virtualServer := range virtualServers { - ttl, err := getTTLFromAnnotations(virtualServer.Annotations) - if err != nil { - return nil, err - } + resource := fmt.Sprintf("f5-virtualserver/%s/%s", virtualServer.Namespace, virtualServer.Name) + + ttl := getTTLFromAnnotations(virtualServer.Annotations, resource) targets := getTargetsFromTargetAnnotation(virtualServer.Annotations) if len(targets) == 0 && virtualServer.Spec.VirtualServerAddress != "" { @@ -160,7 +159,6 @@ func (vs *f5VirtualServerSource) endpointsFromVirtualServers(virtualServers []*f targets = append(targets, virtualServer.Status.VSAddress) } - resource := fmt.Sprintf("f5-virtualserver/%s/%s", virtualServer.Namespace, virtualServer.Name) endpoints = append(endpoints, endpointsForHostname(virtualServer.Spec.Host, targets, ttl, nil, "", resource)...) } diff --git a/source/gateway.go b/source/gateway.go index e725b9eceb..78e8ac5685 100644 --- a/source/gateway.go +++ b/source/gateway.go @@ -230,10 +230,7 @@ func (src *gatewayRouteSource) Endpoints(ctx context.Context) ([]*endpoint.Endpo // Create endpoints from hostnames and targets. 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) - } + ttl := getTTLFromAnnotations(annots, resource) for host, targets := range hostTargets { endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...) } diff --git a/source/gloo_proxy.go b/source/gloo_proxy.go index 19bbf62cff..74754c19aa 100644 --- a/source/gloo_proxy.go +++ b/source/gloo_proxy.go @@ -19,6 +19,7 @@ package source import ( "context" "encoding/json" + "fmt" "strings" log "github.com/sirupsen/logrus" @@ -155,16 +156,16 @@ func (gs *glooSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, erro func (gs *glooSource) generateEndpointsFromProxy(ctx context.Context, proxy *proxy, targets endpoint.Targets) ([]*endpoint.Endpoint, error) { endpoints := []*endpoint.Endpoint{} + + resource := fmt.Sprintf("proxy/%s/%s", proxy.Metadata.Namespace, proxy.Metadata.Name) + for _, listener := range proxy.Spec.Listeners { for _, virtualHost := range listener.HTTPListener.VirtualHosts { annotations, err := gs.annotationsFromProxySource(ctx, virtualHost) if err != nil { return nil, err } - ttl, err := getTTLFromAnnotations(annotations) - if err != nil { - return nil, err - } + ttl := getTTLFromAnnotations(annotations, resource) providerSpecific, setIdentifier := getProviderSpecificAnnotations(annotations) for _, domain := range virtualHost.Domains { endpoints = append(endpoints, endpointsForHostname(strings.TrimSuffix(domain, "."), targets, ttl, providerSpecific, setIdentifier, "")...) diff --git a/source/ingress.go b/source/ingress.go index 89450a5723..14676e8cef 100644 --- a/source/ingress.go +++ b/source/ingress.go @@ -188,10 +188,9 @@ func (sc *ingressSource) endpointsFromTemplate(ing *networkv1.Ingress) ([]*endpo return nil, err } - ttl, err := getTTLFromAnnotations(ing.Annotations) - if err != nil { - log.Warn(err) - } + resource := fmt.Sprintf("ingress/%s/%s", ing.Namespace, ing.Name) + + ttl := getTTLFromAnnotations(ing.Annotations, resource) targets := getTargetsFromTargetAnnotation(ing.Annotations) if len(targets) == 0 { @@ -200,8 +199,6 @@ 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, resource)...) @@ -289,10 +286,9 @@ func (sc *ingressSource) setDualstackLabel(ingress *networkv1.Ingress, endpoints // endpointsFromIngress extracts the endpoints from ingress object func endpointsFromIngress(ing *networkv1.Ingress, ignoreHostnameAnnotation bool, ignoreIngressTLSSpec bool, ignoreIngressRulesSpec bool) []*endpoint.Endpoint { - ttl, err := getTTLFromAnnotations(ing.Annotations) - if err != nil { - log.Warn(err) - } + resource := fmt.Sprintf("ingress/%s/%s", ing.Namespace, ing.Name) + + ttl := getTTLFromAnnotations(ing.Annotations, resource) targets := getTargetsFromTargetAnnotation(ing.Annotations) @@ -302,8 +298,6 @@ 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 diff --git a/source/istio_gateway.go b/source/istio_gateway.go index 4b006a6ab9..1c780c31c9 100644 --- a/source/istio_gateway.go +++ b/source/istio_gateway.go @@ -304,15 +304,14 @@ func (sc *gatewaySource) targetsFromGateway(ctx context.Context, gateway *networ // endpointsFromGatewayConfig extracts the endpoints from an Istio Gateway Config object func (sc *gatewaySource) endpointsFromGateway(ctx context.Context, hostnames []string, gateway *networkingv1alpha3.Gateway) ([]*endpoint.Endpoint, error) { var endpoints []*endpoint.Endpoint + var err error + + resource := fmt.Sprintf("gateway/%s/%s", gateway.Namespace, gateway.Name) annotations := gateway.Annotations - ttl, err := getTTLFromAnnotations(annotations) - if err != nil { - log.Warn(err) - } + ttl := getTTLFromAnnotations(annotations, resource) targets := getTargetsFromTargetAnnotation(annotations) - if len(targets) == 0 { targets, err = sc.targetsFromGateway(ctx, gateway) if err != nil { @@ -322,8 +321,6 @@ 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, resource)...) } diff --git a/source/istio_virtualservice.go b/source/istio_virtualservice.go index b6c3e212b7..1eed91d1a8 100644 --- a/source/istio_virtualservice.go +++ b/source/istio_virtualservice.go @@ -222,14 +222,11 @@ func (sc *virtualServiceSource) endpointsFromTemplate(ctx context.Context, virtu return nil, err } - ttl, err := getTTLFromAnnotations(virtualService.Annotations) - if err != nil { - log.Warn(err) - } + resource := fmt.Sprintf("virtualservice/%s/%s", virtualService.Namespace, virtualService.Name) - providerSpecific, setIdentifier := getProviderSpecificAnnotations(virtualService.Annotations) + ttl := getTTLFromAnnotations(virtualService.Annotations, resource) - resource := fmt.Sprintf("virtualservice/%s/%s", virtualService.Namespace, virtualService.Name) + providerSpecific, setIdentifier := getProviderSpecificAnnotations(virtualService.Annotations) var endpoints []*endpoint.Endpoint for _, hostname := range hostnames { @@ -312,18 +309,16 @@ func (sc *virtualServiceSource) targetsFromVirtualService(ctx context.Context, v // endpointsFromVirtualService extracts the endpoints from an Istio VirtualService Config object func (sc *virtualServiceSource) endpointsFromVirtualService(ctx context.Context, virtualservice *networkingv1alpha3.VirtualService) ([]*endpoint.Endpoint, error) { var endpoints []*endpoint.Endpoint + var err error - ttl, err := getTTLFromAnnotations(virtualservice.Annotations) - if err != nil { - log.Warn(err) - } + resource := fmt.Sprintf("virtualservice/%s/%s", virtualservice.Namespace, virtualservice.Name) + + ttl := getTTLFromAnnotations(virtualservice.Annotations, resource) targetsFromAnnotation := getTargetsFromTargetAnnotation(virtualservice.Annotations) 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 diff --git a/source/kong_tcpingress.go b/source/kong_tcpingress.go index f1a264760c..fbd8dba93e 100644 --- a/source/kong_tcpingress.go +++ b/source/kong_tcpingress.go @@ -204,14 +204,11 @@ func (sc *kongTCPIngressSource) setDualstackLabel(tcpIngress *TCPIngress, endpoi func (sc *kongTCPIngressSource) endpointsFromTCPIngress(tcpIngress *TCPIngress, targets endpoint.Targets) ([]*endpoint.Endpoint, error) { var endpoints []*endpoint.Endpoint - ttl, err := getTTLFromAnnotations(tcpIngress.Annotations) - if err != nil { - return nil, err - } + resource := fmt.Sprintf("tcpingress/%s/%s", tcpIngress.Namespace, tcpIngress.Name) - providerSpecific, setIdentifier := getProviderSpecificAnnotations(tcpIngress.Annotations) + ttl := getTTLFromAnnotations(tcpIngress.Annotations, resource) - resource := fmt.Sprintf("tcpingress/%s/%s", tcpIngress.Namespace, tcpIngress.Name) + providerSpecific, setIdentifier := getProviderSpecificAnnotations(tcpIngress.Annotations) hostnameList := getHostnamesFromAnnotations(tcpIngress.Annotations) for _, hostname := range hostnameList { diff --git a/source/node.go b/source/node.go index 1fcfce6c00..81e40755dc 100644 --- a/source/node.go +++ b/source/node.go @@ -104,10 +104,7 @@ func (ns *nodeSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, erro log.Debugf("creating endpoint for node %s", node.Name) - ttl, err := getTTLFromAnnotations(node.Annotations) - if err != nil { - log.Warn(err) - } + ttl := getTTLFromAnnotations(node.Annotations, fmt.Sprintf("node/%s", node.Name)) // create new endpoint with the information we already have ep := &endpoint.Endpoint{ diff --git a/source/openshift_route.go b/source/openshift_route.go index a3cf6d4398..dd50913f61 100644 --- a/source/openshift_route.go +++ b/source/openshift_route.go @@ -174,10 +174,9 @@ func (ors *ocpRouteSource) endpointsFromTemplate(ocpRoute *routev1.Route) ([]*en return nil, err } - ttl, err := getTTLFromAnnotations(ocpRoute.Annotations) - if err != nil { - log.Warn(err) - } + resource := fmt.Sprintf("route/%s/%s", ocpRoute.Namespace, ocpRoute.Name) + + ttl := getTTLFromAnnotations(ocpRoute.Annotations, resource) targets := getTargetsFromTargetAnnotation(ocpRoute.Annotations) if len(targets) == 0 { @@ -187,8 +186,6 @@ 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, resource)...) @@ -230,10 +227,9 @@ func (ors *ocpRouteSource) filterByAnnotations(ocpRoutes []*routev1.Route) ([]*r func (ors *ocpRouteSource) endpointsFromOcpRoute(ocpRoute *routev1.Route, ignoreHostnameAnnotation bool) []*endpoint.Endpoint { var endpoints []*endpoint.Endpoint - ttl, err := getTTLFromAnnotations(ocpRoute.Annotations) - if err != nil { - log.Warn(err) - } + resource := fmt.Sprintf("route/%s/%s", ocpRoute.Namespace, ocpRoute.Name) + + ttl := getTTLFromAnnotations(ocpRoute.Annotations, resource) targets := getTargetsFromTargetAnnotation(ocpRoute.Annotations) targetsFromRoute, host := ors.getTargetsFromRouteStatus(ocpRoute.Status) @@ -244,8 +240,6 @@ 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, resource)...) } diff --git a/source/service.go b/source/service.go index fd091d0f44..db7247902a 100644 --- a/source/service.go +++ b/source/service.go @@ -460,10 +460,7 @@ func (sc *serviceSource) setResourceLabel(service *v1.Service, endpoints []*endp func (sc *serviceSource) generateEndpoints(svc *v1.Service, hostname string, providerSpecific endpoint.ProviderSpecific, setIdentifier string, useClusterIP bool) []*endpoint.Endpoint { hostname = strings.TrimSuffix(hostname, ".") - ttl, err := getTTLFromAnnotations(svc.Annotations) - if err != nil { - log.Warn(err) - } + ttl := getTTLFromAnnotations(svc.Annotations, fmt.Sprintf("service/%s/%s", svc.Namespace, svc.Name)) epA := &endpoint.Endpoint{ RecordTTL: ttl, @@ -510,6 +507,7 @@ func (sc *serviceSource) generateEndpoints(svc *v1.Service, hostname string, pro } case v1.ServiceTypeNodePort: // add the nodeTargets and extract an SRV endpoint + var err error targets, err = sc.extractNodePortTargets(svc) if err != nil { log.Errorf("Unable to extract targets from service %s/%s error: %v", svc.Namespace, svc.Name, err) diff --git a/source/skipper_routegroup.go b/source/skipper_routegroup.go index 3d1ec380bc..2c3475ac4e 100644 --- a/source/skipper_routegroup.go +++ b/source/skipper_routegroup.go @@ -300,8 +300,10 @@ func (sc *routeGroupSource) endpointsFromTemplate(rg *routeGroup) ([]*endpoint.E hostnames := buf.String() + resource := fmt.Sprintf("routegroup/%s/%s", rg.Metadata.Namespace, rg.Metadata.Name) + // error handled in endpointsFromRouteGroup(), otherwise duplicate log - ttl, _ := getTTLFromAnnotations(rg.Metadata.Annotations) + ttl := getTTLFromAnnotations(rg.Metadata.Annotations, resource) targets := getTargetsFromTargetAnnotation(rg.Metadata.Annotations) @@ -311,8 +313,6 @@ 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), ",") @@ -336,10 +336,10 @@ func (sc *routeGroupSource) setRouteGroupDualstackLabel(rg *routeGroup, eps []*e // annotation logic ported from source/ingress.go without Spec.TLS part, because it'S not supported in RouteGroup func (sc *routeGroupSource) endpointsFromRouteGroup(rg *routeGroup) []*endpoint.Endpoint { endpoints := []*endpoint.Endpoint{} - ttl, err := getTTLFromAnnotations(rg.Metadata.Annotations) - if err != nil { - log.Warnf("Failed to get TTL from annotation: %v", err) - } + + resource := fmt.Sprintf("routegroup/%s/%s", rg.Metadata.Namespace, rg.Metadata.Name) + + ttl := getTTLFromAnnotations(rg.Metadata.Annotations, resource) targets := getTargetsFromTargetAnnotation(rg.Metadata.Annotations) if len(targets) == 0 { @@ -355,8 +355,6 @@ 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 diff --git a/source/source.go b/source/source.go index fcc94c02d8..6af02ec319 100644 --- a/source/source.go +++ b/source/source.go @@ -29,6 +29,7 @@ import ( "time" "unicode" + log "github.com/sirupsen/logrus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -86,20 +87,22 @@ type Source interface { AddEventHandler(context.Context, func()) } -func getTTLFromAnnotations(annotations map[string]string) (endpoint.TTL, error) { +func getTTLFromAnnotations(annotations map[string]string, resource string) endpoint.TTL { ttlNotConfigured := endpoint.TTL(0) ttlAnnotation, exists := annotations[ttlAnnotationKey] if !exists { - return ttlNotConfigured, nil + return ttlNotConfigured } ttlValue, err := parseTTL(ttlAnnotation) if err != nil { - return ttlNotConfigured, fmt.Errorf("\"%v\" is not a valid TTL value", ttlAnnotation) + log.Warnf("%s: \"%v\" is not a valid TTL value: %v", resource, ttlAnnotation, err) + return ttlNotConfigured } if ttlValue < ttlMinimum || ttlValue > ttlMaximum { - return ttlNotConfigured, fmt.Errorf("TTL value must be between [%d, %d]", ttlMinimum, ttlMaximum) + log.Warnf("TTL value %q must be between [%d, %d]", ttlValue, ttlMinimum, ttlMaximum) + return ttlNotConfigured } - return endpoint.TTL(ttlValue), nil + return endpoint.TTL(ttlValue) } // parseTTL parses TTL from string, returning duration in seconds. @@ -109,9 +112,13 @@ func getTTLFromAnnotations(annotations map[string]string) (endpoint.TTL, error) // Note: for durations like "1.5s" the fraction is omitted (resulting in 1 second // for the example). func parseTTL(s string) (ttlSeconds int64, err error) { - ttlDuration, err := time.ParseDuration(s) - if err != nil { - return strconv.ParseInt(s, 10, 64) + ttlDuration, errDuration := time.ParseDuration(s) + if errDuration != nil { + ttlInt, err := strconv.ParseInt(s, 10, 64) + if err != nil { + return 0, errDuration + } + return ttlInt, nil } return int64(ttlDuration.Seconds()), nil diff --git a/source/source_test.go b/source/source_test.go index d6befe804e..417a3c14e5 100644 --- a/source/source_test.go +++ b/source/source_test.go @@ -30,61 +30,51 @@ func TestGetTTLFromAnnotations(t *testing.T) { title string annotations map[string]string expectedTTL endpoint.TTL - expectedErr error }{ { title: "TTL annotation not present", annotations: map[string]string{"foo": "bar"}, expectedTTL: endpoint.TTL(0), - expectedErr: nil, }, { title: "TTL annotation value is not a number", annotations: map[string]string{ttlAnnotationKey: "foo"}, expectedTTL: endpoint.TTL(0), - expectedErr: fmt.Errorf("\"foo\" is not a valid TTL value"), }, { title: "TTL annotation value is empty", annotations: map[string]string{ttlAnnotationKey: ""}, expectedTTL: endpoint.TTL(0), - expectedErr: fmt.Errorf("\"\" is not a valid TTL value"), }, { title: "TTL annotation value is negative number", annotations: map[string]string{ttlAnnotationKey: "-1"}, expectedTTL: endpoint.TTL(0), - expectedErr: fmt.Errorf("TTL value must be between [%d, %d]", ttlMinimum, ttlMaximum), }, { title: "TTL annotation value is too high", annotations: map[string]string{ttlAnnotationKey: fmt.Sprintf("%d", 1<<32)}, expectedTTL: endpoint.TTL(0), - expectedErr: fmt.Errorf("TTL value must be between [%d, %d]", ttlMinimum, ttlMaximum), }, { title: "TTL annotation value is set correctly using integer", annotations: map[string]string{ttlAnnotationKey: "60"}, expectedTTL: endpoint.TTL(60), - expectedErr: nil, }, { title: "TTL annotation value is set correctly using duration (whole)", annotations: map[string]string{ttlAnnotationKey: "10m"}, expectedTTL: endpoint.TTL(600), - expectedErr: nil, }, { title: "TTL annotation value is set correctly using duration (fractional)", annotations: map[string]string{ttlAnnotationKey: "20.5s"}, expectedTTL: endpoint.TTL(20), - expectedErr: nil, }, } { t.Run(tc.title, func(t *testing.T) { - ttl, err := getTTLFromAnnotations(tc.annotations) + ttl := getTTLFromAnnotations(tc.annotations, "resource/test") assert.Equal(t, tc.expectedTTL, ttl) - assert.Equal(t, tc.expectedErr, err) }) } } diff --git a/source/traefik_proxy.go b/source/traefik_proxy.go index c43fa40f8f..2050cb7ceb 100644 --- a/source/traefik_proxy.go +++ b/source/traefik_proxy.go @@ -647,14 +647,11 @@ func (ts *traefikSource) setDualstackLabelIngressRouteUDP(ingressRoute *IngressR func (ts *traefikSource) endpointsFromIngressRoute(ingressRoute *IngressRoute, targets endpoint.Targets) ([]*endpoint.Endpoint, error) { var endpoints []*endpoint.Endpoint - ttl, err := getTTLFromAnnotations(ingressRoute.Annotations) - if err != nil { - return nil, err - } + resource := fmt.Sprintf("ingressroute/%s/%s", ingressRoute.Namespace, ingressRoute.Name) - providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations) + ttl := getTTLFromAnnotations(ingressRoute.Annotations, resource) - resource := fmt.Sprintf("ingressroute/%s/%s", ingressRoute.Namespace, ingressRoute.Name) + providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations) hostnameList := getHostnamesFromAnnotations(ingressRoute.Annotations) for _, hostname := range hostnameList { @@ -684,14 +681,11 @@ func (ts *traefikSource) endpointsFromIngressRoute(ingressRoute *IngressRoute, t func (ts *traefikSource) endpointsFromIngressRouteTCP(ingressRoute *IngressRouteTCP, targets endpoint.Targets) ([]*endpoint.Endpoint, error) { var endpoints []*endpoint.Endpoint - ttl, err := getTTLFromAnnotations(ingressRoute.Annotations) - if err != nil { - return nil, err - } + resource := fmt.Sprintf("ingressroutetcp/%s/%s", ingressRoute.Namespace, ingressRoute.Name) - providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations) + ttl := getTTLFromAnnotations(ingressRoute.Annotations, resource) - resource := fmt.Sprintf("ingressroutetcp/%s/%s", ingressRoute.Namespace, ingressRoute.Name) + providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations) hostnameList := getHostnamesFromAnnotations(ingressRoute.Annotations) for _, hostname := range hostnameList { @@ -722,14 +716,11 @@ func (ts *traefikSource) endpointsFromIngressRouteTCP(ingressRoute *IngressRoute func (ts *traefikSource) endpointsFromIngressRouteUDP(ingressRoute *IngressRouteUDP, targets endpoint.Targets) ([]*endpoint.Endpoint, error) { var endpoints []*endpoint.Endpoint - ttl, err := getTTLFromAnnotations(ingressRoute.Annotations) - if err != nil { - return nil, err - } + resource := fmt.Sprintf("ingressrouteudp/%s/%s", ingressRoute.Namespace, ingressRoute.Name) - providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations) + ttl := getTTLFromAnnotations(ingressRoute.Annotations, resource) - resource := fmt.Sprintf("ingressrouteudp/%s/%s", ingressRoute.Namespace, ingressRoute.Name) + providerSpecific, setIdentifier := getProviderSpecificAnnotations(ingressRoute.Annotations) hostnameList := getHostnamesFromAnnotations(ingressRoute.Annotations) for _, hostname := range hostnameList {