Skip to content

chore(code-quality): refactoring and linter fixes #5374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions provider/inmemory/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,28 +312,28 @@ 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 {
return err
}
}
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 {
return err
}
}
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 {
Expand Down
2 changes: 1 addition & 1 deletion registry/dynamodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
10 changes: 4 additions & 6 deletions source/ambassador_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 2 additions & 5 deletions source/contour_httpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
5 changes: 1 addition & 4 deletions source/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
5 changes: 1 addition & 4 deletions source/f5_transportserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
5 changes: 1 addition & 4 deletions source/f5_virtualserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
14 changes: 7 additions & 7 deletions source/gloo_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")...)
}
Expand All @@ -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 {
Expand All @@ -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
}
}
}
Expand All @@ -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) {
Expand Down
12 changes: 4 additions & 8 deletions source/istio_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -313,18 +310,17 @@ 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 {
return nil, err
}
}

providerSpecific, setIdentifier := getProviderSpecificAnnotations(annotations)
providerSpecific, setIdentifier := getProviderSpecificAnnotations(gateway.Annotations)

for _, host := range hostnames {
endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...)
Expand Down
9 changes: 3 additions & 6 deletions source/istio_virtualservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
5 changes: 1 addition & 4 deletions source/kong_tcpingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
7 changes: 2 additions & 5 deletions source/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
9 changes: 3 additions & 6 deletions source/openshift_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
Expand Down
13 changes: 5 additions & 8 deletions source/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
}
}

Expand Down
Loading
Loading