Skip to content

Commit

Permalink
fixup! fix: Clean up golangci-lint config
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Oliveira <msouzaol@redhat.com>
  • Loading branch information
mateusoliveira43 committed Mar 28, 2024
1 parent 95d16a0 commit e86f210
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-linter-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
version: v1.57.1
21 changes: 12 additions & 9 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Documentation reference https://github.com/golangci/golangci-lint/blob/v1.57.1/.golangci.reference.yml
run:
timeout: 20m
skip-dirs:
- third_party/*
skip-dirs-use-default: false
modules-download-mode: readonly
allow-parallel-runners: false

output:
format: colored-line-number
formats:
- format: colored-line-number
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
Expand All @@ -18,8 +16,9 @@ linters-settings:
dogsled:
max-blank-identifiers: 2
errcheck:
check-type-assertions: true
check-blank: true
# TODO: enable them all
check-type-assertions: false
check-blank: false
goconst:
min-len: 3
min-occurrences: 5
Expand All @@ -45,8 +44,7 @@ linters-settings:
# TODO: enable them all
# enable-all-rules: true
rules:
- name: unexported-return
disabled: true # TODO should be false?
- name: duplicated-imports
testifylint:
# TODO: enable them all
disable:
Expand All @@ -61,11 +59,13 @@ linters-settings:
- suite-dont-use-pkg
- suite-extra-assert-call
- suite-thelper
- nil-compare
enable:
- empty
- len
unparam:
check-exported: true
# TODO: enable
check-exported: false
whitespace:
multi-if: false
multi-func: false
Expand Down Expand Up @@ -155,6 +155,9 @@ issues:
- unconvert
- unparam
- unused
exclude-dirs:
- third_party/*
exclude-dirs-use-default: false
max-issues-per-linter: 0
max-same-issues: 0

Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,13 @@ endif

lint:
ifneq ($(SKIP_TESTS), 1)
@$(MAKE) shell CMD="-c 'hack/lint-verify.sh'"
@$(MAKE) shell CMD="-c 'hack/lint.sh'"
endif

lint-fix:
ifneq ($(SKIP_TESTS), 1)
@$(MAKE) shell CMD="-c 'hack/lint-verify.sh'"
@$(MAKE) shell CMD="-c 'hack/lint.sh --fix'"
endif

Expand Down
1 change: 1 addition & 0 deletions changelogs/unreleased/7194-mateusoliveira43
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean up golangci-lint config
20 changes: 20 additions & 0 deletions hack/lint-verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
#
# Copyright 2020 the Velero contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

CMD="golangci-lint config verify"
echo "Running $CMD"

exec $CMD
7 changes: 3 additions & 4 deletions pkg/backup/backup_pv_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
corev1api "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -123,21 +122,21 @@ func TestBackupPVAction(t *testing.T) {

// non-empty spec.volumeName when status.phase is 'Pending'
// should result in no error and no additional items
pvc.Object["status"].(map[string]interface{})["phase"] = corev1api.ClaimPending
pvc.Object["status"].(map[string]interface{})["phase"] = corev1.ClaimPending
_, additional, err = a.Execute(pvc, backup)
require.NoError(t, err)
require.Empty(t, additional)

// non-empty spec.volumeName when status.phase is 'Lost'
// should result in no error and no additional items
pvc.Object["status"].(map[string]interface{})["phase"] = corev1api.ClaimLost
pvc.Object["status"].(map[string]interface{})["phase"] = corev1.ClaimLost
_, additional, err = a.Execute(pvc, backup)
require.NoError(t, err)
require.Empty(t, additional)

// non-empty spec.volumeName when status.phase is 'Bound'
// should result in no error and one additional item for the PV
pvc.Object["status"].(map[string]interface{})["phase"] = corev1api.ClaimBound
pvc.Object["status"].(map[string]interface{})["phase"] = corev1.ClaimBound
_, additional, err = a.Execute(pvc, backup)
require.NoError(t, err)
require.Len(t, additional, 1)
Expand Down
20 changes: 9 additions & 11 deletions pkg/cmd/cli/backup/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ import (
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
controllerclient "sigs.k8s.io/controller-runtime/pkg/client"
kbclient "sigs.k8s.io/controller-runtime/pkg/client"

velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/builder"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
cmdtest "github.com/vmware-tanzu/velero/pkg/cmd/test"
"github.com/vmware-tanzu/velero/pkg/test"
velerotest "github.com/vmware-tanzu/velero/pkg/test"
)

func TestCreateOptions_BuildBackup(t *testing.T) {
Expand Down Expand Up @@ -88,7 +86,7 @@ func TestCreateOptions_BuildBackupFromSchedule(t *testing.T) {
scheme := runtime.NewScheme()
err := velerov1api.AddToScheme(scheme)
require.NoError(t, err)
o.client = velerotest.NewFakeControllerRuntimeClient(t).(controllerclient.WithWatch)
o.client = test.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)

t.Run("inexistent schedule", func(t *testing.T) {
_, err := o.BuildBackup(cmdtest.VeleroNameSpace)
Expand Down Expand Up @@ -214,7 +212,7 @@ func TestCreateCommand(t *testing.T) {
flags.Parse([]string{"--parallel-files-upload", fmt.Sprintf("%d", parallelFilesUpload)})
//flags.Parse([]string{"--wait"})

client := velerotest.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)
client := test.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)

f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderWatchClient").Return(client, nil)
Expand Down Expand Up @@ -273,7 +271,7 @@ func TestCreateCommand(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
cmd := NewCreateCommand(f, "")
kbclient := velerotest.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)
kbclient := test.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)

f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderWatchClient").Return(kbclient, nil)
Expand All @@ -300,14 +298,14 @@ func TestCreateCommand(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
cmd := NewCreateCommand(f, "")
kbclient := velerotest.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)
kubeclient := test.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)

vsl := builder.ForVolumeSnapshotLocation(cmdtest.VeleroNameSpace, vslName).Result()

kbclient.Create(cmd.Context(), vsl, &controllerclient.CreateOptions{})
kubeclient.Create(cmd.Context(), vsl, &kbclient.CreateOptions{})

f.On("Namespace").Return(cmdtest.VeleroNameSpace)
f.On("KubebuilderWatchClient").Return(kbclient, nil)
f.On("KubebuilderWatchClient").Return(kubeclient, nil)

flags := new(flag.FlagSet)
o := NewCreateOptions()
Expand Down Expand Up @@ -338,13 +336,13 @@ func TestCreateCommand(t *testing.T) {
fromSchedule := "schedule-name-1"
flags.Parse([]string{"--from-schedule", fromSchedule})

kbclient := velerotest.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)
kubeclient := test.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)

schedule := builder.ForSchedule(cmdtest.VeleroNameSpace, fromSchedule).Result()
kbclient.Create(context.Background(), schedule, &controllerclient.CreateOptions{})
kubeclient.Create(context.Background(), schedule, &kbclient.CreateOptions{})

f.On("Namespace").Return(cmdtest.VeleroNameSpace)
f.On("KubebuilderWatchClient").Return(kbclient, nil)
f.On("KubebuilderWatchClient").Return(kubeclient, nil)

e := o.Complete(args, f)
assert.NoError(t, e)
Expand Down
16 changes: 8 additions & 8 deletions pkg/cmd/cli/restore/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/spf13/pflag"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
kubeclient "sigs.k8s.io/controller-runtime/pkg/client"
kbclient "sigs.k8s.io/controller-runtime/pkg/client"

velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/builder"
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestCreateCommand(t *testing.T) {
flags.Parse([]string{"--item-operation-timeout", itemOperationTimeout})
flags.Parse([]string{"--write-sparse-files", writeSparseFiles})
flags.Parse([]string{"--parallel-files-download", "2"})
client := velerotest.NewFakeControllerRuntimeClient(t).(kubeclient.WithWatch)
client := velerotest.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)

f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderWatchClient").Return(client, nil)
Expand Down Expand Up @@ -157,14 +157,14 @@ func TestCreateCommand(t *testing.T) {
fromSchedule := "schedule-name-1"
flags.Parse([]string{"--from-schedule", fromSchedule})

kbclient := velerotest.NewFakeControllerRuntimeClient(t).(kubeclient.WithWatch)
kubeclient := velerotest.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)
schedule := builder.ForSchedule(cmdtest.VeleroNameSpace, fromSchedule).Result()
require.NoError(t, kbclient.Create(context.Background(), schedule, &kubeclient.CreateOptions{}))
require.NoError(t, kubeclient.Create(context.Background(), schedule, &kbclient.CreateOptions{}))
backup := builder.ForBackup(cmdtest.VeleroNameSpace, "test-backup").FromSchedule(schedule).Phase(velerov1api.BackupPhaseCompleted).Result()
require.NoError(t, kbclient.Create(context.Background(), backup, &kubeclient.CreateOptions{}))
require.NoError(t, kubeclient.Create(context.Background(), backup, &kbclient.CreateOptions{}))

f.On("Namespace").Return(cmdtest.VeleroNameSpace)
f.On("KubebuilderWatchClient").Return(kbclient, nil)
f.On("KubebuilderWatchClient").Return(kubeclient, nil)

require.NoError(t, o.Complete(args, f))
require.NoError(t, o.Validate(c, []string{}, f))
Expand All @@ -183,10 +183,10 @@ func TestCreateCommand(t *testing.T) {
flags.Parse([]string{"--wait", "true"})
flags.Parse([]string{"--from-backup", nonExistedBackupName})

kbclient := velerotest.NewFakeControllerRuntimeClient(t).(kubeclient.WithWatch)
kubeclient := velerotest.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)

f.On("Namespace").Return(cmdtest.VeleroNameSpace)
f.On("KubebuilderWatchClient").Return(kbclient, nil)
f.On("KubebuilderWatchClient").Return(kubeclient, nil)

require.NoError(t, o.Complete(nil, f))
err := o.Validate(c, []string{}, f)
Expand Down
2 changes: 1 addition & 1 deletion pkg/repository/maintenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestDeleteOldMaintenanceJobs(t *testing.T) {
assert.NoError(t, err)

// We expect the number of jobs to be equal to 'keep'
assert.Equal(t, keep, len(jobList.Items))
assert.Len(t, jobList.Items, keep)

// We expect that the oldest jobs were deleted
// Job3 should not be present in the remaining list
Expand Down
3 changes: 1 addition & 2 deletions test/perf/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/vmware-tanzu/velero/test/perf/metrics"
. "github.com/vmware-tanzu/velero/test/util/k8s"
"github.com/vmware-tanzu/velero/test/util/report"
"github.com/vmware-tanzu/velero/test/util/velero"
. "github.com/vmware-tanzu/velero/test/util/velero"
)

Expand Down Expand Up @@ -274,7 +273,7 @@ func (t *TestCase) MonitorMetircs(ctx context.Context, collectors *metrics.Metri
}
collectors.RegisterOneTimeMetric(timeMetrics)

veleroPodList, err := velero.ListVeleroPods(ctx, VeleroCfg.VeleroNamespace)
veleroPodList, err := ListVeleroPods(ctx, VeleroCfg.VeleroNamespace)
if err != nil {
fmt.Printf("couldn't monitor velero pod metrics for failed to get velero pod with err %v\n", err)
} else {
Expand Down
3 changes: 1 addition & 2 deletions test/util/k8s/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
waitutil "k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes"
)

Expand Down Expand Up @@ -83,7 +82,7 @@ func WaitForConfigmapDelete(c clientset.Interface, ns, name string) error {
return err
}

return waitutil.PollImmediateInfinite(5*time.Second,
return wait.PollImmediateInfinite(5*time.Second,
func() (bool, error) {
if _, err := c.CoreV1().ConfigMaps(ns).Get(context.TODO(), ns, metav1.GetOptions{}); err != nil {
if apierrors.IsNotFound(err) {
Expand Down
15 changes: 7 additions & 8 deletions test/util/k8s/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/vmware-tanzu/velero/pkg/util/boolptr"
Expand Down Expand Up @@ -70,9 +69,9 @@ func CreatePod(client TestClient, ns, name, sc, pvcName string, volumeNameList [
Annotations: ann,
},
Spec: corev1.PodSpec{
SecurityContext: &v1.PodSecurityContext{
SecurityContext: &corev1.PodSecurityContext{
FSGroup: func(i int64) *int64 { return &i }(65534),
FSGroupChangePolicy: func(policy v1.PodFSGroupChangePolicy) *v1.PodFSGroupChangePolicy { return &policy }(v1.FSGroupChangeAlways),
FSGroupChangePolicy: func(policy corev1.PodFSGroupChangePolicy) *corev1.PodFSGroupChangePolicy { return &policy }(corev1.FSGroupChangeAlways),
},
Containers: []corev1.Container{
{
Expand All @@ -81,16 +80,16 @@ func CreatePod(client TestClient, ns, name, sc, pvcName string, volumeNameList [
Command: []string{"sleep", "3600"},
VolumeMounts: vmList,
// Make pod obeys the restricted pod security standards.
SecurityContext: &v1.SecurityContext{
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: boolptr.False(),
Capabilities: &v1.Capabilities{
Drop: []v1.Capability{"ALL"},
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
RunAsNonRoot: boolptr.True(),
RunAsUser: func(i int64) *int64 { return &i }(65534),
RunAsGroup: func(i int64) *int64 { return &i }(65534),
SeccompProfile: &v1.SeccompProfile{
Type: v1.SeccompProfileTypeRuntimeDefault,
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
},
},
Expand Down
3 changes: 1 addition & 2 deletions test/util/k8s/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
waitutil "k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes"
)

Expand All @@ -45,7 +44,7 @@ func WaitForSecretDelete(c clientset.Interface, ns, name string) error {
if err := c.CoreV1().Secrets(ns).Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to delete secret in namespace %q", ns))
}
return waitutil.PollImmediateInfinite(5*time.Second,
return wait.PollImmediateInfinite(5*time.Second,
func() (bool, error) {
if _, err := c.CoreV1().Secrets(ns).Get(context.TODO(), ns, metav1.GetOptions{}); err != nil {
if apierrors.IsNotFound(err) {
Expand Down

0 comments on commit e86f210

Please sign in to comment.