Skip to content

Commit

Permalink
golangci-lint: upgrade to use v1.62.0 & address detected issues (#1044)
Browse files Browse the repository at this point in the history
Signed-off-by: KevFan <[email protected]>
  • Loading branch information
KevFan authored Dec 2, 2024
1 parent 8e8e015 commit f3230d6
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ run-lint: $(GOLANGCI-LINT) ## Run lint tests
$(GOLANGCI-LINT) run

$(GOLANGCI-LINT):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PROJECT_PATH)/bin v1.54.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PROJECT_PATH)/bin v1.62.0

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI-LINT) ## Download golangci-lint locally if necessary.
Expand Down
6 changes: 3 additions & 3 deletions controllers/auth_policy_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (r *AuthPolicyStatusUpdater) Subscription() controller.Subscription {
func (r *AuthPolicyStatusUpdater) UpdateStatus(ctx context.Context, _ []controller.ResourceEvent, topology *machinery.Topology, _ error, state *sync.Map) error {
logger := controller.LoggerFromContext(ctx).WithName("AuthPolicyStatusUpdater")

policies := lo.FilterMap(topology.Policies().Items(), func(item machinery.Policy, index int) (*kuadrantv1.AuthPolicy, bool) {
policies := lo.FilterMap(topology.Policies().Items(), func(item machinery.Policy, _ int) (*kuadrantv1.AuthPolicy, bool) {
p, ok := item.(*kuadrantv1.AuthPolicy)
return p, ok
})
Expand Down Expand Up @@ -222,13 +222,13 @@ func (r *AuthPolicyStatusUpdater) enforcedCondition(policy *kuadrantv1.AuthPolic
case istioGatewayControllerName:
// EnvoyFilter
istioAuthClustersModifiedGateways, _ := state.Load(StateIstioAuthClustersModified)
componentsToSync = append(componentsToSync, gatewayComponentsToSync(g.gateway, kuadrantistio.EnvoyFilterGroupKind, istioAuthClustersModifiedGateways, topology, func(obj machinery.Object) bool {
componentsToSync = append(componentsToSync, gatewayComponentsToSync(g.gateway, kuadrantistio.EnvoyFilterGroupKind, istioAuthClustersModifiedGateways, topology, func(_ machinery.Object) bool {
// return meta.IsStatusConditionTrue(lo.Map(obj.(*controller.RuntimeObject).Object.(*istioclientgonetworkingv1alpha3.EnvoyFilter).Status.Conditions, kuadrantistio.ConditionToProperConditionFunc), "Ready")
return true // Istio won't ever populate the status stanza of EnvoyFilter resources, so we cannot expect to find a given a condition there
})...)
// WasmPlugin
istioExtensionsModifiedGateways, _ := state.Load(StateIstioExtensionsModified)
componentsToSync = append(componentsToSync, gatewayComponentsToSync(g.gateway, kuadrantistio.WasmPluginGroupKind, istioExtensionsModifiedGateways, topology, func(obj machinery.Object) bool {
componentsToSync = append(componentsToSync, gatewayComponentsToSync(g.gateway, kuadrantistio.WasmPluginGroupKind, istioExtensionsModifiedGateways, topology, func(_ machinery.Object) bool {
// return meta.IsStatusConditionTrue(lo.Map(obj.(*controller.RuntimeObject).Object.(*istioclientgoextensionv1alpha1.WasmPlugin).Status.Conditions, kuadrantistio.ConditionToProperConditionFunc), "Ready")
return true // Istio won't ever populate the status stanza of WasmPlugin resources, so we cannot expect to find a given a condition there
})...)
Expand Down
5 changes: 3 additions & 2 deletions controllers/auth_workflow_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"sync"

Expand All @@ -17,7 +18,7 @@ import (

kuadrantv1 "github.com/kuadrant/kuadrant-operator/api/v1"
kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1"
kuadrant "github.com/kuadrant/kuadrant-operator/pkg/kuadrant"
"github.com/kuadrant/kuadrant-operator/pkg/kuadrant"
"github.com/kuadrant/kuadrant-operator/pkg/wasm"
)

Expand Down Expand Up @@ -166,7 +167,7 @@ func authPolicyAcceptedStatus(policy machinery.Policy) (accepted bool, err error
if condition := meta.FindStatusCondition(p.Status.Conditions, string(gatewayapiv1alpha2.PolicyConditionAccepted)); condition != nil {
accepted = condition.Status == metav1.ConditionTrue
if !accepted {
err = fmt.Errorf(condition.Message)
err = errors.New(condition.Message)
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func PolicyAffectedCondition(policyKind string, policies []machinery.Policy) met
Type: PolicyAffectedConditionType(policyKind),
Status: metav1.ConditionTrue,
Reason: string(gatewayapiv1alpha2.PolicyReasonAccepted),
Message: fmt.Sprintf("Object affected by %s %s", policyKind, lo.Map(policies, func(item machinery.Policy, index int) client.ObjectKey {
Message: fmt.Sprintf("Object affected by %s %s", policyKind, lo.Map(policies, func(item machinery.Policy, _ int) client.ObjectKey {
return client.ObjectKey{Name: item.GetName(), Namespace: item.GetNamespace()}
})),
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/dns_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func dnsPolicyAcceptedStatus(policy machinery.Policy) (accepted bool, err error)
if condition := meta.FindStatusCondition(p.Status.Conditions, string(gatewayapiv1alpha2.PolicyConditionAccepted)); condition != nil {
accepted = condition.Status == metav1.ConditionTrue
if !accepted {
err = fmt.Errorf(condition.Message)
err = errors.New(condition.Message)
}
return
}
Expand Down
8 changes: 7 additions & 1 deletion controllers/dnspolicy_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"math"
"slices"
"strings"
"sync"
Expand Down Expand Up @@ -102,7 +103,12 @@ func (r *DNSPolicyStatusUpdater) updateStatus(ctx context.Context, _ []controlle

propagateRecordConditions(policyRecords, newStatus)

newStatus.TotalRecords = int32(len(policyRecords))
if len(policyRecords) > math.MaxInt32 {
pLogger.Error(fmt.Errorf("too many records: %d exceeds int32 limits", len(policyRecords)), "error setting total dns total records")
newStatus.TotalRecords = math.MaxInt32
} else {
newStatus.TotalRecords = int32(len(policyRecords)) // #nosec G115 - false positive - operation is safe now with the check
}
}

equalStatus := equality.Semantic.DeepEqual(newStatus, policy.Status)
Expand Down
4 changes: 2 additions & 2 deletions controllers/effective_tls_policies_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (t *EffectiveTLSPoliciesReconciler) reconcileCertificates(ctx context.Conte
}

func getCertificatesFromTopology(topology *machinery.Topology) []*certmanagerv1.Certificate {
return lo.FilterMap(topology.Objects().Items(), func(item machinery.Object, index int) (*certmanagerv1.Certificate, bool) {
return lo.FilterMap(topology.Objects().Items(), func(item machinery.Object, _ int) (*certmanagerv1.Certificate, bool) {
r, ok := item.(*controller.RuntimeObject)
if !ok {
return nil, false
Expand All @@ -173,7 +173,7 @@ func getCertificatesFromTopology(topology *machinery.Topology) []*certmanagerv1.
}

func getListenersFromTopology(topology *machinery.Topology) []*machinery.Listener {
return lo.FilterMap(topology.Targetables().Items(), func(item machinery.Targetable, index int) (*machinery.Listener, bool) {
return lo.FilterMap(topology.Targetables().Items(), func(item machinery.Targetable, _ int) (*machinery.Listener, bool) {
l, ok := item.(*machinery.Listener)
return l, ok
})
Expand Down
4 changes: 2 additions & 2 deletions controllers/httproute_policy_discoverability_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (r *HTTPRoutePolicyDiscoverabilityReconciler) Subscription() *controller.Su
func (r *HTTPRoutePolicyDiscoverabilityReconciler) reconcile(ctx context.Context, _ []controller.ResourceEvent, topology *machinery.Topology, _ error, s *sync.Map) error {
logger := controller.LoggerFromContext(ctx).WithName("HTTPRoutePolicyDiscoverabilityReconciler").WithName("reconcile")

httpRoutes := lo.FilterMap(topology.Targetables().Items(), func(item machinery.Targetable, index int) (*machinery.HTTPRoute, bool) {
httpRoutes := lo.FilterMap(topology.Targetables().Items(), func(item machinery.Targetable, _ int) (*machinery.HTTPRoute, bool) {
ob, ok := item.(*machinery.HTTPRoute)
return ob, ok
})
Expand All @@ -59,7 +59,7 @@ func (r *HTTPRoutePolicyDiscoverabilityReconciler) reconcile(ctx context.Context

for _, policyKind := range policyKinds {
path := getRoutePath(topology, route)
gateways := lo.FilterMap(path, func(item machinery.Targetable, index int) (*machinery.Gateway, bool) {
gateways := lo.FilterMap(path, func(item machinery.Targetable, _ int) (*machinery.Gateway, bool) {
ob, ok := item.(*machinery.Gateway)
return ob, ok
})
Expand Down
6 changes: 3 additions & 3 deletions controllers/ratelimit_policy_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (r *RateLimitPolicyStatusUpdater) Subscription() controller.Subscription {
func (r *RateLimitPolicyStatusUpdater) UpdateStatus(ctx context.Context, _ []controller.ResourceEvent, topology *machinery.Topology, _ error, state *sync.Map) error {
logger := controller.LoggerFromContext(ctx).WithName("RateLimitPolicyStatusUpdater")

policies := lo.FilterMap(topology.Policies().Items(), func(item machinery.Policy, index int) (*kuadrantv1.RateLimitPolicy, bool) {
policies := lo.FilterMap(topology.Policies().Items(), func(item machinery.Policy, _ int) (*kuadrantv1.RateLimitPolicy, bool) {
p, ok := item.(*kuadrantv1.RateLimitPolicy)
return p, ok
})
Expand Down Expand Up @@ -192,13 +192,13 @@ func (r *RateLimitPolicyStatusUpdater) enforcedCondition(policy *kuadrantv1.Rate
case istioGatewayControllerName:
// EnvoyFilter
istioRateLimitClustersModifiedGateways, _ := state.Load(StateIstioRateLimitClustersModified)
componentsToSync = append(componentsToSync, gatewayComponentsToSync(g.gateway, kuadrantistio.EnvoyFilterGroupKind, istioRateLimitClustersModifiedGateways, topology, func(obj machinery.Object) bool {
componentsToSync = append(componentsToSync, gatewayComponentsToSync(g.gateway, kuadrantistio.EnvoyFilterGroupKind, istioRateLimitClustersModifiedGateways, topology, func(_ machinery.Object) bool {
// return meta.IsStatusConditionTrue(lo.Map(obj.(*controller.RuntimeObject).Object.(*istioclientgonetworkingv1alpha3.EnvoyFilter).Status.Conditions, kuadrantistio.ConditionToProperConditionFunc), "Ready")
return true // Istio won't ever populate the status stanza of EnvoyFilter resources, so we cannot expect to find a given a condition there
})...)
// WasmPlugin
istioExtensionsModifiedGateways, _ := state.Load(StateIstioExtensionsModified)
componentsToSync = append(componentsToSync, gatewayComponentsToSync(g.gateway, kuadrantistio.WasmPluginGroupKind, istioExtensionsModifiedGateways, topology, func(obj machinery.Object) bool {
componentsToSync = append(componentsToSync, gatewayComponentsToSync(g.gateway, kuadrantistio.WasmPluginGroupKind, istioExtensionsModifiedGateways, topology, func(_ machinery.Object) bool {
// return meta.IsStatusConditionTrue(lo.Map(obj.(*controller.RuntimeObject).Object.(*istioclientgoextensionv1alpha1.WasmPlugin).Status.Conditions, kuadrantistio.ConditionToProperConditionFunc), "Ready")
return true // Istio won't ever populate the status stanza of WasmPlugin resources, so we cannot expect to find a given a condition there
})...)
Expand Down
5 changes: 3 additions & 2 deletions controllers/ratelimit_workflow_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"sync"
"unicode"
Expand All @@ -20,7 +21,7 @@ import (

kuadrantv1 "github.com/kuadrant/kuadrant-operator/api/v1"
kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1"
kuadrant "github.com/kuadrant/kuadrant-operator/pkg/kuadrant"
"github.com/kuadrant/kuadrant-operator/pkg/kuadrant"
kuadrantpolicymachinery "github.com/kuadrant/kuadrant-operator/pkg/policymachinery"
"github.com/kuadrant/kuadrant-operator/pkg/wasm"
)
Expand Down Expand Up @@ -234,7 +235,7 @@ func rateLimitPolicyAcceptedStatus(policy machinery.Policy) (accepted bool, err
if condition := meta.FindStatusCondition(p.Status.Conditions, string(gatewayapiv1alpha2.PolicyConditionAccepted)); condition != nil {
accepted = condition.Status == metav1.ConditionTrue
if !accepted {
err = fmt.Errorf(condition.Message)
err = errors.New(condition.Message)
}
return
}
Expand Down
8 changes: 4 additions & 4 deletions controllers/tls_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func LinkListenerToCertificateFunc(objs controller.Store) machinery.LinkFunc {
return nil
}

linkedListeners := lo.Filter(listeners, func(l *machinery.Listener, index int) bool {
linkedListeners := lo.Filter(listeners, func(l *machinery.Listener, _ int) bool {
if l.TLS != nil && l.TLS.CertificateRefs != nil {
for _, certRef := range l.TLS.CertificateRefs {
certRefNS := ""
Expand All @@ -87,7 +87,7 @@ func LinkListenerToCertificateFunc(objs controller.Store) machinery.LinkFunc {
return false
})

return lo.Map(linkedListeners, func(l *machinery.Listener, index int) machinery.Object {
return lo.Map(linkedListeners, func(l *machinery.Listener, _ int) machinery.Object {
return l
})
},
Expand All @@ -106,7 +106,7 @@ func LinkTLSPolicyToIssuerFunc(objs controller.Store) machinery.LinkFunc {

// Policies linked to Issuer
// Issuer must be in the same namespace as the policy
linkedPolicies := lo.FilterMap(tlsPolicies, func(p *kuadrantv1.TLSPolicy, index int) (machinery.Object, bool) {
linkedPolicies := lo.FilterMap(tlsPolicies, func(p *kuadrantv1.TLSPolicy, _ int) (machinery.Object, bool) {
return p, p.Spec.IssuerRef.Name == issuer.GetName() && p.GetNamespace() == issuer.GetNamespace() && p.Spec.IssuerRef.Kind == certmanagerv1.IssuerKind
})

Expand All @@ -126,7 +126,7 @@ func LinkTLSPolicyToClusterIssuerFunc(objs controller.Store) machinery.LinkFunc
clusterIssuer := o.Object.(*certmanagerv1.ClusterIssuer)

// Policies linked to ClusterIssuer
linkedPolicies := lo.FilterMap(tlsPolicies, func(p *kuadrantv1.TLSPolicy, index int) (machinery.Object, bool) {
linkedPolicies := lo.FilterMap(tlsPolicies, func(p *kuadrantv1.TLSPolicy, _ int) (machinery.Object, bool) {
return p, p.Spec.IssuerRef.Name == clusterIssuer.GetName() && p.Spec.IssuerRef.Kind == certmanagerv1.ClusterIssuerKind
})

Expand Down
2 changes: 1 addition & 1 deletion controllers/tlspolicy_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (t *TLSPolicyStatusUpdater) isCertificatesReady(p machinery.Policy, topolog
}

// Get all listeners where the gateway or listener contains this policy
listeners := lo.FilterMap(topology.Targetables().Items(), func(t machinery.Targetable, index int) (*machinery.Listener, bool) {
listeners := lo.FilterMap(topology.Targetables().Items(), func(t machinery.Targetable, _ int) (*machinery.Listener, bool) {
l, ok := t.(*machinery.Listener)
return l, ok && (lo.Contains(l.Policies(), p) || lo.Contains(l.Gateway.Policies(), p))
})
Expand Down

0 comments on commit f3230d6

Please sign in to comment.