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
2 changes: 1 addition & 1 deletion .github/workflows/pr-linter-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jobs:
- name: Linter check
uses: golangci/golangci-lint-action@v6
with:
version: v1.57.2
version: v1.64.5
args: --verbose
70 changes: 51 additions & 19 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ run:
# If false (default) - golangci-lint acquires file lock on start.
allow-parallel-runners: false


# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
Expand All @@ -41,18 +40,25 @@ output:
# print linter name in the end of issue text, default is true
print-linter-name: true

# make issues output unique by line, default is true
uniq-by-line: true


# all available settings of specific linters
linters-settings:

depguard:
rules:
main:
deny:
# specify an error message to output when a denylisted package is used
- pkg: github.com/sirupsen/logrus
desc: "logging is allowed only by logutils.Log"

dogsled:
# checks assignments with too many blank identifiers; default is 2
max-blank-identifiers: 2

dupl:
# tokens count to trigger issue, 150 by default
threshold: 100

errcheck:
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
Expand All @@ -70,25 +76,31 @@ linters-settings:
# path to a file containing a list of functions to exclude from checking
# see https://github.com/kisielk/errcheck#excluding-functions for details
# exclude: /path/to/file.txt

exhaustive:
# indicates that switch statements are to be considered exhaustive if a
# 'default' case is present, even if all enum members aren't listed in the
# switch
default-signifies-exhaustive: false

funlen:
lines: 60
statements: 40

gocognit:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 10

nestif:
# minimal complexity of if statements to report, 5 by default
min-complexity: 4

goconst:
# minimal length of string constant, 3 by default
min-len: 3
# minimal occurrences count to trigger, 3 by default
min-occurrences: 5

gocritic:
# Which checks should be enabled; can't be combined with 'disabled-checks';
# See https://go-critic.github.io/overview#checks-overview
Expand All @@ -113,26 +125,36 @@ linters-settings:
paramsOnly: true
# rangeValCopy:
# sizeThreshold: 32

gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 10

godot:
# check all top-level comments, not only declarations
check-all: false

godox:
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
# might be left in the code accidentally and should be resolved before merging
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
- NOTE
- OPTIMIZE # marks code that should be optimized before merging
- HACK # marks hack-arounds that should be removed before merging

gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true

goimports:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
local-prefixes: github.com/org/project

gosec:
excludes:
- G115

govet:
# report about shadowed variables
# check-shadowing: true
Expand All @@ -153,22 +175,26 @@ linters-settings:
disable:
- shadow
disable-all: false

lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
line-length: 120
# tab width in spaces. Default to 1.
tab-width: 1

misspell:
# Correct spellings using locale preferences for US or UK.
# Default is to use a neutral variety of English.
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
locale: US
ignore-words:
- someword

nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 30

prealloc:
# XXX: we don't recommend using this linter before doing performance profiling.
# For most programs usage of prealloc will be a premature optimization.
Expand All @@ -178,6 +204,7 @@ linters-settings:
simple: true
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: false # Report preallocation suggestions on for loops, false by default

nolintlint:
# Enable to ensure that nolint directives are all used. Default is true.
allow-unused: false
Expand All @@ -187,11 +214,13 @@ linters-settings:
require-explanation: true
# Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
require-specific: true

perfsprint:
strconcat: false
sprintf1: false
errorf: false
int-conversion: true

revive:
rules:
- name: blank-imports
Expand Down Expand Up @@ -238,17 +267,19 @@ linters-settings:
- name: var-declaration
- name: var-naming
disabled: true

rowserrcheck:
packages:
- github.com/jmoiron/sqlx

testifylint:
# TODO: enable them all
disable:
- go-require
- float-compare
- require-error
enable-all: true

testpackage:
# regexp pattern to skip files
skip-regexp: (export|internal)_test\.go
Expand All @@ -258,9 +289,11 @@ linters-settings:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false

whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature

wsl:
# If true append is only allowed to be cuddled if appending value is
# matching variables, fields or types on line above. Default is true.
Expand Down Expand Up @@ -288,11 +321,11 @@ linters:
- asciicheck
- bidichk
- bodyclose
- copyloopvar
- dogsled
- durationcheck
- dupword
- errcheck
- exportloopref
- errchkjson
- goconst
- gofmt
Expand Down Expand Up @@ -325,8 +358,16 @@ linters:
- whitespace
fast: false


issues:
# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
exclude-dirs:
- pkg/plugin/generated/*

exclude-rules:
- linters:
- staticcheck
Expand Down Expand Up @@ -370,17 +411,8 @@ issues:
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

# Show only new issues created after git revision `REV`
# new-from-rev: origin/main

# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
exclude-dirs:
- pkg/plugin/generated/*
# make issues output unique by line, default is true
uniq-by-line: true

severity:
# Default value is empty string.
Expand Down
2 changes: 1 addition & 1 deletion hack/build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ RUN ARCH=$(go env GOARCH) && \
chmod +x /usr/bin/goreleaser

# get golangci-lint
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.57.2
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.64.5

# install kubectl
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/$(go env GOARCH)/kubectl
Expand Down
2 changes: 1 addition & 1 deletion internal/resourcepolicies/resource_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (p *Policies) BuildPolicy(resPolicies *ResourcePolicies) error {
volP.conditions = append(volP.conditions, &nfsCondition{nfs: con.NFS})
volP.conditions = append(volP.conditions, &csiCondition{csi: con.CSI})
volP.conditions = append(volP.conditions, &volumeTypeCondition{volumeTypes: con.VolumeTypes})
if con.PVCLabels != nil && len(con.PVCLabels) > 0 {
if len(con.PVCLabels) > 0 {
volP.conditions = append(volP.conditions, &pvcLabelsCondition{labels: con.PVCLabels})
}
p.volumePolicies = append(p.volumePolicies, volP)
Expand Down
2 changes: 0 additions & 2 deletions internal/resourcepolicies/volume_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func TestParseCapacity(t *testing.T) {
}

for _, test := range tests {
test := test // capture range variable
t.Run(test.input, func(t *testing.T) {
actual, actualErr := parseCapacity(test.input)
if test.expected != emptyCapacity {
Expand Down Expand Up @@ -181,7 +180,6 @@ func TestCapacityIsInRange(t *testing.T) {
}

for _, test := range tests {
test := test // capture range variable
t.Run(fmt.Sprintf("%v with %v", test.capacity, test.quantity), func(t *testing.T) {
t.Parallel()

Expand Down
3 changes: 1 addition & 2 deletions internal/storage/storagelocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import (
"context"
"fmt"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -98,7 +97,7 @@
locations := new(velerov1api.BackupStorageLocationList)
defaultLocations := new(velerov1api.BackupStorageLocationList)
if err := kbClient.List(context.Background(), locations, &client.ListOptions{Namespace: namespace}); err != nil {
return defaultLocations, errors.Wrapf(err, fmt.Sprintf("failed to list backup storage locations in namespace %s", namespace))
return defaultLocations, errors.Wrapf(err, "failed to list backup storage locations in namespace %s", namespace)

Check warning on line 100 in internal/storage/storagelocation.go

View check run for this annotation

Codecov / codecov/patch

internal/storage/storagelocation.go#L100

Added line #L100 was not covered by tests
}

for _, location := range locations.Items {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/util/downloadrequest/downloadrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
if err != nil {
if urlErr, ok := err.(*url.Error); ok {
if _, ok := urlErr.Err.(x509.UnknownAuthorityError); ok {
return fmt.Errorf(err.Error() + "\n\nThe --insecure-skip-tls-verify flag can also be used to accept any TLS certificate for the download, but it is susceptible to man-in-the-middle attacks.")
return fmt.Errorf("%s\n\nThe --insecure-skip-tls-verify flag can also be used to accept any TLS certificate for the download, but it is susceptible to man-in-the-middle attacks", err.Error())

Check warning on line 155 in pkg/cmd/util/downloadrequest/downloadrequest.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/util/downloadrequest/downloadrequest.go#L155

Added line #L155 was not covered by tests
}
}
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/backup_deletion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ func (r *backupDeletionReconciler) deleteMovedSnapshots(ctx context.Context, bac
directSnapshots := map[string][]repotypes.SnapshotIdentifier{}
for i := range list.Items {
cm := list.Items[i]
if cm.Data == nil || len(cm.Data) == 0 {
if len(cm.Data) == 0 {
errs = append(errs, errors.New("no snapshot info in config"))
continue
}
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/backup_sync_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,6 @@ var _ = Describe("Backup Sync Reconciler", func() {
},
}
for _, test := range testCases {
test := test
It(test.name, func() {
logger := velerotest.NewLogger()
b := backupSyncReconciler{
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/data_download_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,12 @@ func TestDataDownloadReconcile(t *testing.T) {
}
if test.dd.Namespace == velerov1api.DefaultNamespace {
if controllerutil.ContainsFinalizer(test.dd, DataUploadDownloadFinalizer) {
assert.True(t, true, apierrors.IsNotFound(err))
assert.True(t, true, apierrors.IsNotFound(err)) //nolint:testifylint //FIXME
} else {
require.NoError(t, err)
}
} else {
assert.True(t, true, apierrors.IsNotFound(err))
assert.True(t, true, apierrors.IsNotFound(err)) //nolint:testifylint //FIXME
}

if !test.needCreateFSBR {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/restore_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ func (r *restoreReconciler) validateAndComplete(restore *api.Restore) (backupInf
}
resourceModifiers, err = resourcemodifiers.GetResourceModifiersFromConfig(ResourceModifierConfigMap)
if err != nil {
restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, errors.Wrapf(err, fmt.Sprintf("Error in parsing resource modifiers provided in configmap %s/%s", restore.Namespace, restore.Spec.ResourceModifier.Name)).Error())
restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, errors.Wrapf(err, "Error in parsing resource modifiers provided in configmap %s/%s", restore.Namespace, restore.Spec.ResourceModifier.Name).Error())
return backupInfo{}, nil
} else if err = resourceModifiers.Validate(); err != nil {
restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, errors.Wrapf(err, fmt.Sprintf("Validation error in resource modifiers provided in configmap %s/%s", restore.Namespace, restore.Spec.ResourceModifier.Name)).Error())
restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, errors.Wrapf(err, "Validation error in resource modifiers provided in configmap %s/%s", restore.Namespace, restore.Spec.ResourceModifier.Name).Error())
return backupInfo{}, nil
}
r.logger.Infof("Retrieved Resource modifiers provided in configmap %s/%s", restore.Namespace, restore.Spec.ResourceModifier.Name)
Expand Down
4 changes: 2 additions & 2 deletions pkg/restore/actions/csi/volumesnapshot_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ func TestResetVolumeSnapshotSpecForRestore(t *testing.T) {
resetVolumeSnapshotSpecForRestore(&tc.vs, &tc.vscName)

assert.Equalf(t, tc.vs.Name, before.Name, "unexpected change to Object.Name, Want: %s; Got %s", before.Name, tc.vs.Name)
assert.Equal(t, tc.vs.Namespace, before.Namespace, "unexpected change to Object.Namespace, Want: %s; Got %s", tc.name, before.Namespace, tc.vs.Namespace)
assert.Equalf(t, tc.vs.Namespace, before.Namespace, "unexpected change to Object.Namespace, Want: %s; Got %s", before.Namespace, tc.vs.Namespace)
assert.NotNil(t, tc.vs.Spec.Source)
assert.Nil(t, tc.vs.Spec.Source.PersistentVolumeClaimName)
assert.NotNil(t, tc.vs.Spec.Source.VolumeSnapshotContentName)
assert.Equal(t, *tc.vs.Spec.Source.VolumeSnapshotContentName, tc.vscName)
assert.Equal(t, *tc.vs.Spec.VolumeSnapshotClassName, *before.Spec.VolumeSnapshotClassName, "unexpected value for Spec.VolumeSnapshotClassName, Want: %s, Got: %s",
assert.Equalf(t, *tc.vs.Spec.VolumeSnapshotClassName, *before.Spec.VolumeSnapshotClassName, "unexpected value for Spec.VolumeSnapshotClassName, Want: %s, Got: %s",
*tc.vs.Spec.VolumeSnapshotClassName, *before.Spec.VolumeSnapshotClassName)
assert.Nil(t, tc.vs.Status)
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/test/fake_discovery_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (di *FakeServerResourcesInterface) ServerPreferredResources() ([]*metav1.AP
if di.ReturnError != nil {
return di.ResourceList, di.ReturnError
}
if di.FailedGroups == nil || len(di.FailedGroups) == 0 {
if len(di.FailedGroups) == 0 {
return di.ResourceList, nil
}
return di.ResourceList, &discovery.ErrGroupDiscoveryFailed{Groups: di.FailedGroups}
Expand All @@ -168,7 +168,7 @@ func (di *FakeServerResourcesInterface) ServerGroupsAndResources() ([]*metav1.AP
if di.ReturnError != nil {
return di.APIGroup, di.ResourceList, di.ReturnError
}
if di.FailedGroups == nil || len(di.FailedGroups) == 0 {
if len(di.FailedGroups) == 0 {
return di.APIGroup, di.ResourceList, nil
}
return di.APIGroup, di.ResourceList, &discovery.ErrGroupDiscoveryFailed{Groups: di.FailedGroups}
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/kube/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

// Client knows how to perform CRUD operations on Kubernetes objects.
// go:generate mockery --name=Client
//
//go:generate mockery --name=Client
type Client interface {
client.Reader
client.Writer
Expand Down
Loading
Loading