Skip to content
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

Adjust golangci-lint linters #3284

Merged
merged 6 commits into from
Dec 2, 2024
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
43 changes: 35 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,38 @@ linters-settings:
linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
# - canonicalheader # This is a slow linter and we don't use the net/http.Header API
- containedctx
- contextcheck
- copyloopvar
# - cyclop # This is equivalent to gocyclo
- decorder
# - depguard # depguard now denies by default, it should only be enabled if we actually use it
- dogsled
- dupl
- durationcheck
- errcheck
- errchkjson
- errorlint
- errname
- exhaustive
# - exhaustivestruct # Not recommended for general use - meant to be used only for special cases
# - exhaustruct # This is too cumbersome as it requires all string, int, pointer et al fields to be initialized even when the
# type's default suffices, which is most of the time
- fatcontext
# - forbidigo # We don't forbid any statements
# - forcetypeassert # There are many unchecked type assertions that would be the result of a programming error so the
# reasonable recourse would be to panic anyway if checked so this doesn't seem useful
# - funlen # gocyclo is enabled which is generally a better metric than simply LOC.
- gci
- ginkgolinter
- gocheckcompilerdirectives
# - gochecknoglobals # We don't want to forbid global variable constants
# - gochecknoinits # We use init functions for valid reasons
# - gochecksumtype # The usefulness is very narrow
- gocognit
- goconst
- gocritic
Expand All @@ -87,55 +96,73 @@ linters:
- gofumpt
- goheader
- goimports
# - golint # Deprecated since v1.41.0
# - gomnd # It doesn't seem useful in general to enforce constants for all numeric values
# - gomoddirectives # We don't want to forbid the 'replace' directive
# - gomodguard # We don't block any modules
# - goprintffuncname # This doesn't seem useful at all
# - gosmopolitan # This is related to internationalization which is not a concern for us
- gosec
- gosimple
- govet
# - ifshort # This is a style preference and doesn't seem compelling
- grouper
- iface
- importas
- inamedparam
- ineffassign
# - interfacebloat # We track complexity elsewhere
- intrange
# - ireturn # The argument to always "Return Concrete Types" doesn't seem compelling. It is perfectly valid to return
# an interface to avoid exposing the entire underlying struct
# - interfacer # Deprecated since v1.38.0
# an interface to avoid exposing the entire underlying struct
- lll
- loggercheck
- maintidx
- makezero
# - maligned # Deprecated since v1.38.0
- mirror
- misspell
# - mnd # It doesn't seem useful in general to enforce constants for all numeric values
- musttag
- nakedret
# - nestif # This calculates cognitive complexity but we're doing that elsewhere
- nilerr
- nilnil
# - nlreturn # This is reasonable with a block-size of 2 but setting it above isn't honored
# - noctx # We don't send HTTP requests
- nolintlint
- nonamedreturns
# - nosprintfhostport # The use of this is very narrow
# - paralleltest # Not relevant for Ginkgo UTs
- perfsprint
- prealloc
- predeclared
- promlinter
# - protogetter # We don't use protobuf
- reassign
- recvcheck
- revive
# - rowserrcheck # We don't use SQL
# - scopelint # Deprecated since v1.39.0
# - sloglint # We don't use log/slog
# - spancheck # We don't use OpenTelemetry/OpenCensus
# - sqlclosecheck # We don't use SQL
- staticcheck
- stylecheck
- tagalign
# - tagliatelle # Inconsistent with stylecheck and not as good
# - tenv # Not relevant for our Ginkgo UTs
# - testableexamples # We don't need this
# - testifylint # We don't use testify
- testpackage
# - thelper # Not relevant for our Ginkgo UTs
# - tparallel # Not relevant for our Ginkgo UTs
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
# - varnamelen # It doesn't seem necessary to enforce a minimum variable name length
- wastedassign
- whitespace
- wrapcheck
- wsl
# - zerologlint # We use zerolog indirectly so this isn't needed
issues:
exclude-rules:
# Allow dot-imports for Gomega BDD directives per idiomatic Gomega
Expand Down
3 changes: 1 addition & 2 deletions controllers/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package metrics
import (
"context"
"errors"
"fmt"

"github.com/go-logr/logr"
"github.com/submariner-io/submariner-operator/controllers/apply"
Expand Down Expand Up @@ -94,7 +93,7 @@ func newMetricsService(name, namespace, appKey, appName string, port int32) *cor
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Namespace: namespace,
Name: fmt.Sprintf("%s-metrics", name),
Name: name + "-metrics",
},
Spec: corev1.ServiceSpec{
Ports: servicePorts,
Expand Down
3 changes: 1 addition & 2 deletions controllers/submariner/gateway_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package submariner

import (
"context"
"fmt"
"strconv"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -123,7 +122,7 @@ func newGatewayPodTemplate(cr *v1alpha1.Submariner, name string, podSelectorLabe
// We've got a PSK secret, mount it where the gateway expects it
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "psksecret",
MountPath: fmt.Sprintf("/var/run/secrets/submariner.io/%s", cr.Spec.CeIPSecPSKSecret),
MountPath: "/var/run/secrets/submariner.io/" + cr.Spec.CeIPSecPSKSecret,
ReadOnly: true,
})

Expand Down
4 changes: 2 additions & 2 deletions controllers/submariner/loadbalancer_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package submariner

import (
"context"
"fmt"
"strconv"

"github.com/go-logr/logr"
configv1 "github.com/openshift/api/config/v1"
Expand Down Expand Up @@ -61,7 +61,7 @@ func (r *Reconciler) reconcileLoadBalancer(

// For IBM cloud also needs to annotate the allocated health check node port
if platformTypeOCP == string(configv1.IBMCloudPlatformType) {
healthPortStr := fmt.Sprintf("%d", svc.Spec.HealthCheckNodePort)
healthPortStr := strconv.Itoa(int(svc.Spec.HealthCheckNodePort))
svc.ObjectMeta.Annotations = map[string]string{
"service.kubernetes.io/ibm-load-balancer-cloud-provider-vpc-health-check-port": healthPortStr,
}
Expand Down
7 changes: 4 additions & 3 deletions controllers/submariner/metrics_proxy_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package submariner

import (
"context"
"fmt"
"strconv"

"github.com/go-logr/logr"
"github.com/submariner-io/admiral/pkg/names"
Expand Down Expand Up @@ -63,7 +63,8 @@ func newMetricsProxyDaemonSet(cr *v1alpha1.Submariner) *appsv1.DaemonSet {
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
*metricProxyContainer(cr, "gateway-metrics-proxy", fmt.Sprint(gatewayMetricsServicePort), gatewayMetricsServerPort),
*metricProxyContainer(cr, "gateway-metrics-proxy", strconv.Itoa(gatewayMetricsServicePort),
gatewayMetricsServerPort),
},
NodeSelector: map[string]string{"submariner.io/gateway": "true"},
// The MetricsProxy Pod must be able to run on any flagged node, regardless of existing taints
Expand All @@ -75,7 +76,7 @@ func newMetricsProxyDaemonSet(cr *v1alpha1.Submariner) *appsv1.DaemonSet {

if cr.Spec.GlobalCIDR != "" {
daemonSet.Spec.Template.Spec.Containers = append(daemonSet.Spec.Template.Spec.Containers,
*metricProxyContainer(cr, "globalnet-metrics-proxy", fmt.Sprint(globalnetMetricsServicePort), globalnetMetricsServerPort))
*metricProxyContainer(cr, "globalnet-metrics-proxy", strconv.Itoa(globalnetMetricsServicePort), globalnetMetricsServerPort))
}

return daemonSet
Expand Down
Loading
Loading