diff --git a/provider/aws/aws.go b/provider/aws/aws.go index 89d90a47b5..2ec309256b 100644 --- a/provider/aws/aws.go +++ b/provider/aws/aws.go @@ -254,7 +254,7 @@ func (z zoneTags) filterZonesByTags(p *AWSProvider, zones map[string]*profiledZo // append adds tags to the ZoneTags for a given zoneID. func (z zoneTags) append(id string, tags []route53types.Tag) { zoneId := fmt.Sprintf("/hostedzone/%s", id) - if _, exists := z[zoneId]; !exists { + if _, ok := z[zoneId]; !ok { z[zoneId] = make(map[string]string) } for _, tag := range tags { diff --git a/provider/inmemory/inmemory.go b/provider/inmemory/inmemory.go index 1f636dfdad..a2c054f0d9 100644 --- a/provider/inmemory/inmemory.go +++ b/provider/inmemory/inmemory.go @@ -312,7 +312,7 @@ func (c *inMemoryClient) validateChangeBatch(zone string, changes *plan.Changes) } mesh := sets.New[endpoint.EndpointKey]() for _, newEndpoint := range changes.Create { - if _, exists := curZone[newEndpoint.Key()]; exists { + if _, ok := curZone[newEndpoint.Key()]; ok { return ErrRecordAlreadyExists } if err := c.updateMesh(mesh, newEndpoint); err != nil { @@ -320,7 +320,7 @@ func (c *inMemoryClient) validateChangeBatch(zone string, changes *plan.Changes) } } for _, updateEndpoint := range changes.UpdateNew { - if _, exists := curZone[updateEndpoint.Key()]; !exists { + if _, ok := curZone[updateEndpoint.Key()]; !ok { return ErrRecordNotFound } if err := c.updateMesh(mesh, updateEndpoint); err != nil { @@ -328,12 +328,12 @@ func (c *inMemoryClient) validateChangeBatch(zone string, changes *plan.Changes) } } for _, updateOldEndpoint := range changes.UpdateOld { - if rec, exists := curZone[updateOldEndpoint.Key()]; !exists || rec.Targets[0] != updateOldEndpoint.Targets[0] { + if rec, ok := curZone[updateOldEndpoint.Key()]; !ok || rec.Targets[0] != updateOldEndpoint.Targets[0] { return ErrRecordNotFound } } for _, deleteEndpoint := range changes.Delete { - if rec, exists := curZone[deleteEndpoint.Key()]; !exists || rec.Targets[0] != deleteEndpoint.Targets[0] { + if rec, ok := curZone[deleteEndpoint.Key()]; !ok || rec.Targets[0] != deleteEndpoint.Targets[0] { return ErrRecordNotFound } if err := c.updateMesh(mesh, deleteEndpoint); err != nil { diff --git a/registry/dynamodb_test.go b/registry/dynamodb_test.go index 281e274d9a..e6e71b47d0 100644 --- a/registry/dynamodb_test.go +++ b/registry/dynamodb_test.go @@ -1248,7 +1248,7 @@ func (r *DynamoDBStub) BatchExecuteStatement(context context.Context, input *dyn var key string assert.Nil(r.t, attributevalue.Unmarshal(statement.Parameters[0], &key)) - if code, exists := r.stubConfig.ExpectInsertError[key]; exists { + if code, ok := r.stubConfig.ExpectInsertError[key]; ok { delete(r.stubConfig.ExpectInsertError, key) responses = append(responses, dynamodbtypes.BatchStatementResponse{ Error: &dynamodbtypes.BatchStatementError{ diff --git a/source/ambassador_host.go b/source/ambassador_host.go index 0ddc891180..4dde2eaf85 100644 --- a/source/ambassador_host.go +++ b/source/ambassador_host.go @@ -119,7 +119,7 @@ func (sc *ambassadorHostSource) Endpoints(ctx context.Context) ([]*endpoint.Endp } // Get a list of Ambassador Host resources - ambassadorHosts := []*ambassador.Host{} + var ambassadorHosts []*ambassador.Host for _, hostObj := range hosts { unstructuredHost, ok := hostObj.(*unstructured.Unstructured) if !ok { @@ -185,11 +185,10 @@ func (sc *ambassadorHostSource) Endpoints(ctx context.Context) ([]*endpoint.Endp // endpointsFromHost extracts the endpoints from a Host object func (sc *ambassadorHostSource) endpointsFromHost(host *ambassador.Host, targets endpoint.Targets) ([]*endpoint.Endpoint, error) { var endpoints []*endpoint.Endpoint - annotations := host.Annotations resource := fmt.Sprintf("host/%s/%s", host.Namespace, host.Name) - providerSpecific, setIdentifier := getProviderSpecificAnnotations(annotations) - ttl := getTTLFromAnnotations(annotations, resource) + providerSpecific, setIdentifier := getProviderSpecificAnnotations(host.Annotations) + ttl := getTTLFromAnnotations(host.Annotations, resource) if host.Spec != nil { hostname := host.Spec.Hostname @@ -311,9 +310,8 @@ func (sc *ambassadorHostSource) filterByAnnotations(ambassadorHosts []*ambassado // Return a filtered list of Ambassador Hosts filteredList := []*ambassador.Host{} for _, host := range ambassadorHosts { - annotations := labels.Set(host.Annotations) // include Ambassador Host if its annotations match the annotation filter - if selector.Matches(annotations) { + if selector.Matches(labels.Set(host.Annotations)) { filteredList = append(filteredList, host) } } diff --git a/source/compatibility.go b/source/compatibility.go index d7f4351c8f..afb1de3e47 100644 --- a/source/compatibility.go +++ b/source/compatibility.go @@ -84,8 +84,8 @@ func legacyEndpointsFromMoleculeService(svc *v1.Service) []*endpoint.Endpoint { } // Get the desired hostname of the service from the annotation. - hostnameAnnotation, exists := svc.Annotations[moleculeAnnotationKey] - if !exists { + hostnameAnnotation, ok := svc.Annotations[moleculeAnnotationKey] + if !ok { return nil } diff --git a/source/contour_httpproxy.go b/source/contour_httpproxy.go index 823b91e33c..b8d58e11e5 100644 --- a/source/contour_httpproxy.go +++ b/source/contour_httpproxy.go @@ -224,14 +224,11 @@ func (sc *httpProxySource) filterByAnnotations(httpProxies []*projectcontour.HTT return httpProxies, nil } - filteredList := []*projectcontour.HTTPProxy{} + var filteredList []*projectcontour.HTTPProxy for _, httpProxy := range httpProxies { - // convert the HTTPProxy's annotations to an equivalent label selector - annotations := labels.Set(httpProxy.Annotations) - // include HTTPProxy if its annotations match the selector - if selector.Matches(annotations) { + if selector.Matches(labels.Set(httpProxy.Annotations)) { filteredList = append(filteredList, httpProxy) } } diff --git a/source/crd.go b/source/crd.go index 31a775b063..d62805162f 100644 --- a/source/crd.go +++ b/source/crd.go @@ -287,11 +287,8 @@ func (cs *crdSource) filterByAnnotations(dnsendpoints *endpoint.DNSEndpointList) filteredList := endpoint.DNSEndpointList{} for _, dnsendpoint := range dnsendpoints.Items { - // convert the dnsendpoint' annotations to an equivalent label selector - annotations := labels.Set(dnsendpoint.Annotations) - // include dnsendpoint if its annotations match the selector - if selector.Matches(annotations) { + if selector.Matches(labels.Set(dnsendpoint.Annotations)) { filteredList.Items = append(filteredList.Items, dnsendpoint) } } diff --git a/source/f5_transportserver.go b/source/f5_transportserver.go index d3042a58e9..7a055982eb 100644 --- a/source/f5_transportserver.go +++ b/source/f5_transportserver.go @@ -201,11 +201,8 @@ func (ts *f5TransportServerSource) filterByAnnotations(transportServers []*f5.Tr filteredList := []*f5.TransportServer{} for _, ts := range transportServers { - // convert the TransportServer's annotations to an equivalent label selector - annotations := labels.Set(ts.Annotations) - // include TransportServer if its annotations match the selector - if selector.Matches(annotations) { + if selector.Matches(labels.Set(ts.Annotations)) { filteredList = append(filteredList, ts) } } diff --git a/source/f5_virtualserver.go b/source/f5_virtualserver.go index 85b1538fe0..1e98dc33ad 100644 --- a/source/f5_virtualserver.go +++ b/source/f5_virtualserver.go @@ -208,11 +208,8 @@ func (vs *f5VirtualServerSource) filterByAnnotations(virtualServers []*f5.Virtua filteredList := []*f5.VirtualServer{} for _, vs := range virtualServers { - // convert the VirtualServer's annotations to an equivalent label selector - annotations := labels.Set(vs.Annotations) - // include VirtualServer if its annotations match the selector - if selector.Matches(annotations) { + if selector.Matches(labels.Set(vs.Annotations)) { filteredList = append(filteredList, vs) } } diff --git a/source/gloo_proxy.go b/source/gloo_proxy.go index 74754c19aa..e851b28759 100644 --- a/source/gloo_proxy.go +++ b/source/gloo_proxy.go @@ -161,12 +161,12 @@ func (gs *glooSource) generateEndpointsFromProxy(ctx context.Context, proxy *pro for _, listener := range proxy.Spec.Listeners { for _, virtualHost := range listener.HTTPListener.VirtualHosts { - annotations, err := gs.annotationsFromProxySource(ctx, virtualHost) + ants, err := gs.annotationsFromProxySource(ctx, virtualHost) if err != nil { return nil, err } - ttl := getTTLFromAnnotations(annotations, resource) - providerSpecific, setIdentifier := getProviderSpecificAnnotations(annotations) + ttl := getTTLFromAnnotations(ants, resource) + providerSpecific, setIdentifier := getProviderSpecificAnnotations(ants) for _, domain := range virtualHost.Domains { endpoints = append(endpoints, endpointsForHostname(strings.TrimSuffix(domain, "."), targets, ttl, providerSpecific, setIdentifier, "")...) } @@ -176,7 +176,7 @@ func (gs *glooSource) generateEndpointsFromProxy(ctx context.Context, proxy *pro } func (gs *glooSource) annotationsFromProxySource(ctx context.Context, virtualHost proxyVirtualHost) (map[string]string, error) { - annotations := map[string]string{} + ants := map[string]string{} for _, src := range virtualHost.Metadata.Source { kind := sourceKind(src.Kind) if kind != nil { @@ -185,7 +185,7 @@ func (gs *glooSource) annotationsFromProxySource(ctx context.Context, virtualHos return nil, err } for key, value := range source.GetAnnotations() { - annotations[key] = value + ants[key] = value } } } @@ -197,11 +197,11 @@ func (gs *glooSource) annotationsFromProxySource(ctx context.Context, virtualHos return nil, err } for key, value := range source.GetAnnotations() { - annotations[key] = value + ants[key] = value } } } - return annotations, nil + return ants, nil } func (gs *glooSource) proxyTargets(ctx context.Context, name string, namespace string) (endpoint.Targets, error) { diff --git a/source/istio_gateway.go b/source/istio_gateway.go index d158b30a7f..0ca2a98355 100644 --- a/source/istio_gateway.go +++ b/source/istio_gateway.go @@ -217,11 +217,8 @@ func (sc *gatewaySource) filterByAnnotations(gateways []*networkingv1alpha3.Gate var filteredList []*networkingv1alpha3.Gateway for _, gw := range gateways { - // convert the annotations to an equivalent label selector - annotations := labels.Set(gw.Annotations) - // include if the annotations match the selector - if selector.Matches(annotations) { + if selector.Matches(labels.Set(gw.Annotations)) { filteredList = append(filteredList, gw) } } @@ -313,10 +310,9 @@ func (sc *gatewaySource) endpointsFromGateway(ctx context.Context, hostnames []s resource := fmt.Sprintf("gateway/%s/%s", gateway.Namespace, gateway.Name) - annotations := gateway.Annotations - ttl := getTTLFromAnnotations(annotations, resource) + ttl := getTTLFromAnnotations(gateway.Annotations, resource) - targets := getTargetsFromTargetAnnotation(annotations) + targets := getTargetsFromTargetAnnotation(gateway.Annotations) if len(targets) == 0 { targets, err = sc.targetsFromGateway(ctx, gateway) if err != nil { @@ -324,7 +320,7 @@ func (sc *gatewaySource) endpointsFromGateway(ctx context.Context, hostnames []s } } - providerSpecific, setIdentifier := getProviderSpecificAnnotations(annotations) + providerSpecific, setIdentifier := getProviderSpecificAnnotations(gateway.Annotations) 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 039aa6f3c5..ca6edfbb75 100644 --- a/source/istio_virtualservice.go +++ b/source/istio_virtualservice.go @@ -268,13 +268,10 @@ func (sc *virtualServiceSource) filterByAnnotations(virtualservices []*networkin var filteredList []*networkingv1alpha3.VirtualService - for _, virtualservice := range virtualservices { - // convert the annotations to an equivalent label selector - annotations := labels.Set(virtualservice.Annotations) - + for _, vs := range virtualservices { // include if the annotations match the selector - if selector.Matches(annotations) { - filteredList = append(filteredList, virtualservice) + if selector.Matches(labels.Set(vs.Annotations)) { + filteredList = append(filteredList, vs) } } diff --git a/source/kong_tcpingress.go b/source/kong_tcpingress.go index bca023dbe4..f710a80d86 100644 --- a/source/kong_tcpingress.go +++ b/source/kong_tcpingress.go @@ -179,11 +179,8 @@ func (sc *kongTCPIngressSource) filterByAnnotations(tcpIngresses []*TCPIngress) filteredList := []*TCPIngress{} for _, tcpIngress := range tcpIngresses { - // convert the TCPIngress's annotations to an equivalent label selector - annotations := labels.Set(tcpIngress.Annotations) - // include TCPIngress if its annotations match the selector - if selector.Matches(annotations) { + if selector.Matches(labels.Set(tcpIngress.Annotations)) { filteredList = append(filteredList, tcpIngress) } } diff --git a/source/node.go b/source/node.go index a0e426f17b..d2991d4b43 100644 --- a/source/node.go +++ b/source/node.go @@ -222,14 +222,11 @@ func (ns *nodeSource) filterByAnnotations(nodes []*v1.Node) ([]*v1.Node, error) return nodes, nil } - filteredList := []*v1.Node{} + var filteredList []*v1.Node for _, node := range nodes { - // convert the node's annotations to an equivalent label selector - annotations := labels.Set(node.Annotations) - // include node if its annotations match the selector - if selector.Matches(annotations) { + if selector.Matches(labels.Set(node.Annotations)) { filteredList = append(filteredList, node) } } diff --git a/source/openshift_route.go b/source/openshift_route.go index dd50913f61..b47a14dab5 100644 --- a/source/openshift_route.go +++ b/source/openshift_route.go @@ -24,7 +24,7 @@ import ( "time" routev1 "github.com/openshift/api/route/v1" - versioned "github.com/openshift/client-go/route/clientset/versioned" + "github.com/openshift/client-go/route/clientset/versioned" extInformers "github.com/openshift/client-go/route/informers/externalversions" routeInformer "github.com/openshift/client-go/route/informers/externalversions/route/v1" log "github.com/sirupsen/logrus" @@ -208,14 +208,11 @@ func (ors *ocpRouteSource) filterByAnnotations(ocpRoutes []*routev1.Route) ([]*r return ocpRoutes, nil } - filteredList := []*routev1.Route{} + var filteredList []*routev1.Route for _, ocpRoute := range ocpRoutes { - // convert the Route's annotations to an equivalent label selector - annotations := labels.Set(ocpRoute.Annotations) - // include ocpRoute if its annotations match the selector - if selector.Matches(annotations) { + if selector.Matches(labels.Set(ocpRoute.Annotations)) { filteredList = append(filteredList, ocpRoute) } } diff --git a/source/service.go b/source/service.go index e0f38c69a7..6cbdcf0dbd 100644 --- a/source/service.go +++ b/source/service.go @@ -434,14 +434,11 @@ func (sc *serviceSource) filterByAnnotations(services []*v1.Service) ([]*v1.Serv return services, nil } - filteredList := []*v1.Service{} + var filteredList []*v1.Service for _, service := range services { - // convert the service's annotations to an equivalent label selector - annotations := labels.Set(service.Annotations) - // include service if its annotations match the selector - if selector.Matches(annotations) { + if selector.Matches(labels.Set(service.Annotations)) { filteredList = append(filteredList, service) } } @@ -504,9 +501,9 @@ func (sc *serviceSource) generateEndpoints(svc *v1.Service, hostname string, pro targets = extractServiceExternalName(svc) } - for _, endpoint := range endpoints { - endpoint.ProviderSpecific = providerSpecific - endpoint.SetIdentifier = setIdentifier + for _, en := range endpoints { + en.ProviderSpecific = providerSpecific + en.SetIdentifier = setIdentifier } } diff --git a/source/source.go b/source/source.go index 4f0b69d42c..5e9174320e 100644 --- a/source/source.go +++ b/source/source.go @@ -89,10 +89,10 @@ type Source interface { AddEventHandler(context.Context, func()) } -func getTTLFromAnnotations(annotations map[string]string, resource string) endpoint.TTL { +func getTTLFromAnnotations(ants map[string]string, resource string) endpoint.TTL { ttlNotConfigured := endpoint.TTL(0) - ttlAnnotation, exists := annotations[ttlAnnotationKey] - if !exists { + ttlAnnotation, ok := ants[ttlAnnotationKey] + if !ok { return ttlNotConfigured } ttlValue, err := parseTTL(ttlAnnotation) @@ -171,9 +171,9 @@ func getEndpointsTypeFromAnnotations(annotations map[string]string) string { return annotations[endpointsTypeAnnotationKey] } -func getInternalHostnamesFromAnnotations(annotations map[string]string) []string { - internalHostnameAnnotation, exists := annotations[internalHostnameAnnotationKey] - if !exists { +func getInternalHostnamesFromAnnotations(ants map[string]string) []string { + internalHostnameAnnotation, ok := ants[internalHostnameAnnotationKey] + if !ok { return nil } return splitHostnameAnnotation(internalHostnameAnnotation) @@ -183,40 +183,40 @@ func splitHostnameAnnotation(annotation string) []string { return strings.Split(strings.ReplaceAll(annotation, " ", ""), ",") } -func getAliasFromAnnotations(annotations map[string]string) bool { - aliasAnnotation, exists := annotations[aliasAnnotationKey] +func getAliasFromAnnotations(ants map[string]string) bool { + aliasAnnotation, exists := ants[aliasAnnotationKey] return exists && aliasAnnotation == "true" } -func getProviderSpecificAnnotations(annotations map[string]string) (endpoint.ProviderSpecific, string) { +func getProviderSpecificAnnotations(ants map[string]string) (endpoint.ProviderSpecific, string) { providerSpecificAnnotations := endpoint.ProviderSpecific{} - if v, exists := annotations[CloudflareProxiedKey]; exists { + if v, exists := ants[CloudflareProxiedKey]; exists { providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{ Name: CloudflareProxiedKey, Value: v, }) } - if v, exists := annotations[CloudflareCustomHostnameKey]; exists { + if v, exists := ants[CloudflareCustomHostnameKey]; exists { providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{ Name: CloudflareCustomHostnameKey, Value: v, }) } - if v, exists := annotations[CloudflareRegionKey]; exists { + if v, exists := ants[CloudflareRegionKey]; exists { providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{ Name: CloudflareRegionKey, Value: v, }) } - if getAliasFromAnnotations(annotations) { + if getAliasFromAnnotations(ants) { providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{ Name: "alias", Value: "true", }) } setIdentifier := "" - for k, v := range annotations { + for k, v := range ants { if k == SetIdentifierKey { setIdentifier = v } else if strings.HasPrefix(k, "external-dns.alpha.kubernetes.io/aws-") { @@ -346,8 +346,7 @@ func getLabelSelector(annotationFilter string) (labels.Selector, error) { } func matchLabelSelector(selector labels.Selector, srcAnnotations map[string]string) bool { - annotations := labels.Set(srcAnnotations) - return selector.Matches(annotations) + return selector.Matches(labels.Set(srcAnnotations)) } type eventHandlerFunc func() diff --git a/source/traefik_proxy.go b/source/traefik_proxy.go index 3a07ac91b3..1fd919a45a 100644 --- a/source/traefik_proxy.go +++ b/source/traefik_proxy.go @@ -554,11 +554,8 @@ func (ts *traefikSource) filterIngressRouteByAnnotation(ingressRoutes []*Ingress filteredList := []*IngressRoute{} for _, ingressRoute := range ingressRoutes { - // convert the IngressRoute's annotations to an equivalent label selector - annotations := labels.Set(ingressRoute.Annotations) - // include IngressRoute if its annotations match the selector - if selector.Matches(annotations) { + if selector.Matches(labels.Set(ingressRoute.Annotations)) { filteredList = append(filteredList, ingressRoute) } } @@ -582,14 +579,11 @@ func (ts *traefikSource) filterIngressRouteTcpByAnnotations(ingressRoutes []*Ing return ingressRoutes, nil } - filteredList := []*IngressRouteTCP{} + var filteredList []*IngressRouteTCP for _, ingressRoute := range ingressRoutes { - // convert the IngressRoute's annotations to an equivalent label selector - annotations := labels.Set(ingressRoute.Annotations) - // include IngressRoute if its annotations match the selector - if selector.Matches(annotations) { + if selector.Matches(labels.Set(ingressRoute.Annotations)) { filteredList = append(filteredList, ingressRoute) } } @@ -613,14 +607,11 @@ func (ts *traefikSource) filterIngressRouteUdpByAnnotations(ingressRoutes []*Ing return ingressRoutes, nil } - filteredList := []*IngressRouteUDP{} + var filteredList []*IngressRouteUDP for _, ingressRoute := range ingressRoutes { - // convert the IngressRoute's annotations to an equivalent label selector - annotations := labels.Set(ingressRoute.Annotations) - // include IngressRoute if its annotations match the selector - if selector.Matches(annotations) { + if selector.Matches(labels.Set(ingressRoute.Annotations)) { filteredList = append(filteredList, ingressRoute) } }