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
192 changes: 179 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,202 @@
run:
timeout: 5m
issues-exit-code: 1

output:
formats:
- format: colored-line-number

linters-settings:
cyclop:
max-complexity: 15

depguard:
rules:
main:
files:
- "$all"
- "!$test"
deny:
- pkg: "reflect"
desc: "Reflection is never clear."
- pkg: "gob"
desc: "Please convert types manually"

dupl:
threshold: 100

errcheck:
check-type-assertions: true
check-blank: true
exclude-functions:
- fmt:.*
- io/ioutil:^Read.*

gci:
sections:
- standard
- default
- blank
- dot
- prefix(github.com/linode/linode-cloud-controller-manager)

goconst:
min-len: 3
min-occurrences: 5

gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style

settings:
captLocal:
paramsOnly: true
rangeValCopy:
sizeThreshold: 32

gofmt:
simplify: true

goimports:
local-prefixes: github.com/linode/linode-cloud-controller-manager

govet:
enable:
- shadow

gosec:
confidence: "medium"
excludes:
- G115

nolintlint:
require-explanation: true
require-specific: true

prealloc:
simple: true
range-loops: true
for-loops: true

varnamelen:
min-name-length: 2

linters:
disable-all: true
#disable-all: true
disable:
- errcheck
- errchkjson
- errorlint
- govet
- testifylint
enable:
# these are enabled by default
- errcheck
#- errcheck
- gosimple
- govet
#- govet
- ineffassign
- staticcheck
- typecheck
- unused
# cherry picked from https://golangci-lint.run/usage/linters/
# - ginkgolinter # to be enabled once #158 is merged
- ginkgolinter
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- copyloopvar
#- cyclop
- decorder
#- depguard
- dogsled
- dupl
- dupword
- durationcheck
#- errchkjson
- errname
#- errorlint
- exhaustive
#- forbidigo
#- forcetypeassert
#- gci
- gocheckcompilerdirectives
- gofmt
- goimports
#- gocognit
#- goconst
#- gocritic
- gofumpt
- goprintffuncname
#- gosec
- importas
- loggercheck
- maintidx
- makezero
- misspell
#- mnd
- musttag
#- nestif
- nilerr
- prealloc
- nilnil
- noctx
- nolintlint
- nosprintfhostport
#- paralleltest
#- prealloc
- predeclared
- reassign
- tenv
#- tenv
#- thelper
- unconvert
- wastedassign
- unparam
- gofumpt
- nosprintfhostport
- musttag
- exhaustive
- nilnil
- usestdlibvars
#- varnamelen
- wastedassign
- whitespace

presets:
- bugs
- unused
fast: false

issues:
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test(ing)?\.go
linters:
- gocyclo
- maintidx
- errcheck
- dupl
- gosec
- copyloopvar
- unparam
- varnamelen

# Ease some gocritic warnings on test files.
- path: _test\.go
text: "(unnamedResult|exitAfterDefer)"
linters:
- gocritic

- text: "G101:"
linters:
- gosec
- gas

- text: "G104:"
linters:
- gosec
- gas

exclude-use-default: false
new: false
max-issues-per-linter: 0
max-same-issues: 0
exclude-files:
- "zz_generated\\..+\\.go$"
3 changes: 2 additions & 1 deletion cloud/linode/cilium_loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
ciliumclient "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2alpha1"
slimv1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/apis/meta/v1"
"github.com/google/uuid"
"github.com/linode/linode-cloud-controller-manager/cloud/annotations"
"github.com/linode/linodego"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -23,6 +22,8 @@ import (
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"

"github.com/linode/linode-cloud-controller-manager/cloud/annotations"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion cloud/linode/cilium_loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
k8sClient "github.com/cilium/cilium/pkg/k8s/client"
fakev2alpha1 "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2alpha1/fake"
"github.com/golang/mock/gomock"
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks"
"github.com/linode/linodego"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

"github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cloud/linode/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"os"
"time"

_ "github.com/hexdigest/gowrap"
"github.com/linode/linodego"
"k8s.io/klog/v2"

_ "github.com/hexdigest/gowrap"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cloud/linode/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
func newLinodeClientWithPrometheus(apiToken string, timeout time.Duration) (client.Client, error) {
linodeClient, err := client.New(apiToken, timeout)
if err != nil {
return nil, fmt.Errorf("client was not created succesfully: %w", err)
return nil, fmt.Errorf("client was not created successfully: %w", err)

Check warning on line 80 in cloud/linode/cloud.go

View check run for this annotation

Codecov / codecov/patch

cloud/linode/cloud.go#L80

Added line #L80 was not covered by tests
}

if Options.LinodeGoDebug {
Expand Down
5 changes: 3 additions & 2 deletions cloud/linode/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks"
"github.com/stretchr/testify/assert"
cloudprovider "k8s.io/cloud-provider"

"github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks"
)

func TestNewCloudRouteControllerDisabled(t *testing.T) {
Expand Down Expand Up @@ -75,7 +76,7 @@ func TestNewCloud(t *testing.T) {
}()
_, err := newCloud()
assert.NoError(t, err, "expected no error if deprecated flag vpcname is set")
assert.Equal(t, Options.VPCNames, "tt", "expected vpcnames to be set to vpcname")
assert.Equal(t, "tt", Options.VPCNames, "expected vpcnames to be set to vpcname")
})

t.Run("should fail if incorrect loadbalancertype is set", func(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions cloud/linode/fake_linode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (f *fakeAPI) setupRoutes() {
f.mux.HandleFunc("GET /v4/nodebalancers/{nodeBalancerId}", func(w http.ResponseWriter, r *http.Request) {
nb, found := f.nb[r.PathValue("nodeBalancerId")]
if !found {
w.WriteHeader(404)
w.WriteHeader(http.StatusNotFound)
resp := linodego.APIError{
Errors: []linodego.APIErrorReason{
{Reason: "Not Found"},
Expand Down Expand Up @@ -284,7 +284,7 @@ func (f *fakeAPI) setupRoutes() {

firewallDevices, found := f.fwd[fwdId]
if !found {
w.WriteHeader(404)
w.WriteHeader(http.StatusNotFound)
resp := linodego.APIError{
Errors: []linodego.APIErrorReason{
{Reason: "Not Found"},
Expand Down Expand Up @@ -728,7 +728,7 @@ func (f *fakeAPI) setupRoutes() {
return
}

w.WriteHeader(404)
w.WriteHeader(http.StatusNotFound)
resp := linodego.APIError{
Errors: []linodego.APIErrorReason{
{Reason: "Not Found"},
Expand Down Expand Up @@ -767,7 +767,7 @@ func (f *fakeAPI) setupRoutes() {
return
}

w.WriteHeader(404)
w.WriteHeader(http.StatusNotFound)
resp := linodego.APIError{
Errors: []linodego.APIErrorReason{
{Reason: "Not Found"},
Expand Down
Loading
Loading