Skip to content
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
167 changes: 106 additions & 61 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,135 @@
# GolangCI-Lint settings

version: "2"
# Disable all linters and enable the required ones
linters:
disable-all: true
default: none

# Supported linters: https://golangci-lint.run/usage/linters/
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- copyloopvar
- decorder
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exptostd
- fatcontext
- forbidigo
- forcetypeassert
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoinits
- gochecksumtype
- gocognit
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- goprintffuncname
- gosec
- govet
- grouper
- iface
- importas
- ineffassign
- interfacebloat
- lll
- loggercheck
- makezero
- mirror
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnesserr
- noctx
- nolintlint
- nosprintfhostport
- prealloc
- stylecheck
- predeclared
- reassign
- rowserrcheck
- sqlclosecheck
- staticcheck
- testableexamples
- tparallel
- unconvert
- unparam
- paralleltest
- forbidigo
fast: false
- unused
- usestdlibvars
- usetesting
- wastedassign
- zerologlint

# Specific linter settings
settings:
gocognit:
# Minimal code complexity to report
min-complexity: 16
gocyclo:
# Minimal code complexity to report
min-complexity: 16
misspell:
# Correct spellings using locale preferences for US
locale: US
staticcheck:
# Default list with custom silencing of:

checks: [
"all",
# Disable the checks that staticcheck disables by default
"-ST1000",
"-ST1003",
"-ST1016",
"-ST1020",
"-ST1021",
"-ST1022",
"-QF1008", # Omit embedded fields from selector expression.
]
exclusions:
rules:
# Exclude gochecknoinits and gosec from running on tests files
- path: _test\.go
linters:
- dupl
- gochecknoinits
- gosec
- errcheck
- gocognit
- musttag
- noctx
- usestdlibvars
- exhaustruct
- copyloopvar
- goconst
- path: test/*
linters:
- gochecknoinits
- gosec
- gocognit
# Exclude lll issues for long lines with go:generate
- linters:
- lll
source: "^//go:generate "
paths:
- .go/pkg/mod
- vendor-fork
- internal/logreporter/api/loki

# Run options
run:
# 10 minute timeout for analysis
timeout: 10m
# Specific linter settings
linters-settings:
gocyclo:
# Minimal code complexity to report
min-complexity: 16
govet:
disable-all: true
enable:
# Report shadowed variables
- shadow

misspell:
# Correct spellings using locale preferences for US
locale: US
goimports:
# Put imports beginning with prefix after 3rd-party packages
local-prefixes: gitswarm.f5net.com/indigo,gitlab.com/f5
exhaustruct:
# List of regular expressions to match struct packages and names.
# If this list is empty, all structs are tested.
# Default: []
include:
- "gitlab.com/f5/nginx/nginxazurelb/azure-resource-provider/pkg/token.TokenID"
- "gitlab.com/f5/nginx/nginxazurelb/azure-resource-provider/internal/dpo/agent/certificates.CertGetRequest"

issues:
exclude-dirs:
- .go/pkg/mod
# Exclude configuration
exclude-rules:
# Exclude gochecknoinits and gosec from running on tests files
- path: _test\.go
linters:
- gochecknoinits
- gosec
- path: test/*
linters:
- gochecknoinits
- gosec
# Exclude lll issues for long lines with go:generate
- linters:
- lll
source: "^//go:generate "
# Exclude false positive paralleltest error : Range statement for test case does not use range value in test Run
- linters:
- paralleltest
text: "does not use range value in test Run"

# Disable maximum issues count per one linter
max-issues-per-linter: 0

Expand Down
3 changes: 2 additions & 1 deletion cmd/nginx-loadbalancer-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main

import (
"context"
"errors"
"fmt"
"log/slog"
"os"
Expand Down Expand Up @@ -119,7 +120,7 @@ func initializeLogger(logLevel string) {
func buildKubernetesClient() (*kubernetes.Clientset, error) {
slog.Debug("Watcher::buildKubernetesClient")
k8sConfig, err := rest.InClusterConfig()
if err == rest.ErrNotInCluster {
if errors.Is(err, rest.ErrNotInCluster) {
return nil, fmt.Errorf(`not running in a Cluster: %w`, err)
} else if err != nil {
return nil, fmt.Errorf(`error occurred getting the Cluster config: %w`, err)
Expand Down
1 change: 1 addition & 0 deletions internal/application/application_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
)

func buildTerrorizingBorderClient(clientType string) (Interface, error) {
//nolint:dupword // dupword doesn't understand jokes
nginxClient := mocks.NewErroringMockClient(errors.New(`something went horribly horribly wrong`))
bc, err := NewBorderClient(clientType, nginxClient)

Expand Down
4 changes: 0 additions & 4 deletions internal/application/nginx_http_border_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
* Copyright 2023 F5 Inc. All rights reserved.
* Use of this source code is governed by the Apache License that can be found in the LICENSE file.
*/

// dupl complains about duplicates with nginx_stream_border_client_test.go
//
//nolint:dupl
package application

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/application/nginx_stream_border_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* Copyright 2023 F5 Inc. All rights reserved.
* Use of this source code is governed by the Apache License that can be found in the LICENSE file.
*/
// dupl complains about duplicates with nginx_http_border_client_test.go
//nolint:dupl
package application

import (
Expand Down
1 change: 1 addition & 0 deletions internal/communication/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func NewHeaders(apiKey string) []string {

// NewTransport is a factory method to create a new basic Http Transport.
func NewTransport(skipVerify bool) *netHttp.Transport {
//nolint:forcetypeassert
transport := netHttp.DefaultTransport.(*netHttp.Transport).Clone()
transport.TLSClientConfig.InsecureSkipVerify = skipVerify

Expand Down
1 change: 0 additions & 1 deletion internal/communication/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func TestNewHTTPClient(t *testing.T) {
}
}

//nolint:goconst
func TestNewHeaders(t *testing.T) {
t.Parallel()
headers := NewHeaders("fakeKey")
Expand Down
4 changes: 4 additions & 0 deletions internal/observation/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func (w *Watcher) buildEndpointSlicesEventHandlerForDelete() func(interface{}) {
func (w *Watcher) buildServiceEventHandlerForAdd() func(interface{}) {
slog.Info("Watcher::buildServiceEventHandlerForAdd")
return func(obj interface{}) {
//nolint:forcetypeassert
service := obj.(*v1.Service)
if !w.isDesiredService(service) {
return
Expand All @@ -228,6 +229,7 @@ func (w *Watcher) buildServiceEventHandlerForAdd() func(interface{}) {
func (w *Watcher) buildServiceEventHandlerForDelete() func(interface{}) {
slog.Info("Watcher::buildServiceEventHandlerForDelete")
return func(obj interface{}) {
//nolint:forcetypeassert
service := obj.(*v1.Service)
if !w.isDesiredService(service) {
return
Expand All @@ -245,7 +247,9 @@ func (w *Watcher) buildServiceEventHandlerForDelete() func(interface{}) {
func (w *Watcher) buildServiceEventHandlerForUpdate() func(interface{}, interface{}) {
slog.Info("Watcher::buildServiceEventHandlerForUpdate")
return func(previous, updated interface{}) {
//nolint:forcetypeassert
previousService := previous.(*v1.Service)
//nolint:forcetypeassert
service := updated.(*v1.Service)

if w.isDesiredService(previousService) && !w.isDesiredService(service) {
Expand Down
2 changes: 1 addition & 1 deletion internal/probation/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (hs *HealthServer) Start() {
mux.HandleFunc("/readyz", hs.HandleReady)
mux.HandleFunc("/startupz", hs.HandleStartup)

listener, err := net.Listen("tcp", address)
listener, err := net.Listen("tcp", address) //nolint:noctx
if err != nil {
slog.Error("failed to listen", "error", err)
return
Expand Down
6 changes: 4 additions & 2 deletions internal/synchronization/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ func (s *Synchronizer) buildBorderClient(event *core.ServerUpdateEvent) (applica
var err error
httpClient, err := communication.NewHTTPClient(s.settings.APIKey, s.settings.SkipVerifyTLS)
if err != nil {
return nil, fmt.Errorf(`error creating HTTP client: %v`, err)
return nil, fmt.Errorf(`error creating HTTP client: %w`, err)
}

ngxClient, err := nginxClient.NewNginxClient(event.NginxHost, nginxClient.WithHTTPClient(httpClient))
if err != nil {
return nil, fmt.Errorf(`error creating Nginx Plus client: %v`, err)
return nil, fmt.Errorf(`error creating Nginx Plus client: %w`, err)
}

return application.NewBorderClient(event.ClientType, ngxClient)
Expand All @@ -164,6 +164,8 @@ func (s *Synchronizer) fanOutEventToHosts(event core.ServerUpdateEvents) core.Se
// handleServiceEvent gets the latest state for the service from the shared
// informer cache, translates the service event into server update events and
// dispatches these events to the proper handler function.
//
//nolint:gocognit
func (s *Synchronizer) handleServiceEvent(ctx context.Context, key ServiceKey) (err error) {
logger := slog.With("service", key)
logger.Debug(`Synchronizer::handleServiceEvent`)
Expand Down
1 change: 1 addition & 0 deletions internal/translation/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (t *Translator) buildLoadBalancerEvents(event *core.Event) (events core.Ser
return events, nil
}

//nolint:gocognit
func (t *Translator) buildClusterIPEvents(event *core.Event) (events core.ServerUpdateEvents, err error) {
namespace := event.Service.GetObjectMeta().GetNamespace()
serviceName := event.Service.Name
Expand Down
Loading