Skip to content

Commit 90b69e9

Browse files
authored
chore(deps): bump golangci-lint (#719)
* chore(deps): bump golangci-lint Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * fix lint Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * fix tests Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> --------- Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
1 parent 60c6378 commit 90b69e9

File tree

15 files changed

+167
-164
lines changed

15 files changed

+167
-164
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ jobs:
2020
- run: go mod tidy
2121
- run: make test
2222
- name: Run golangci-lint
23-
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
23+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
2424
with:
25-
version: v1.63.4
25+
version: v2.1.6
2626
args: --verbose
2727
- uses: codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # v5.4.2
2828
with:

.golangci.yaml

Lines changed: 114 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,128 @@
1-
issues:
2-
exclude-dirs:
3-
- internal/kubernetes_vendor
4-
exclude-files:
5-
- "pkg/diff/internal/fieldmanager/borrowed_.*\\.go$"
6-
max-issues-per-linter: 0
7-
max-same-issues: 0
1+
version: "2"
82
linters:
93
enable:
10-
- errcheck
114
- errorlint
125
- gocritic
13-
- gofumpt
14-
- goimports
156
- gomodguard
16-
- gosimple
17-
- govet
187
- importas
19-
- ineffassign
208
- misspell
21-
# Disabled because of https://github.com/argoproj/argo-cd/issues/21705
22-
# - nolintlint
239
- perfsprint
2410
- revive
25-
- staticcheck
2611
- testifylint
2712
- thelper
2813
- unparam
29-
- unused
3014
- usestdlibvars
3115
- whitespace
32-
linters-settings:
33-
gocritic:
34-
disabled-checks:
35-
- appendAssign
36-
- assignOp # Keep it disabled for readability
37-
- exitAfterDefer
38-
- typeSwitchVar
39-
goimports:
40-
local-prefixes: github.com/argoproj/gitops-engine
41-
importas:
42-
alias:
43-
- alias: appsv1
44-
pkg: k8s.io/api/apps/v1
45-
- alias: corev1
46-
pkg: k8s.io/api/core/v1
47-
- alias: apierrors
48-
pkg: k8s.io/apimachinery/pkg/api/errors
49-
- alias: apiextensionsv1
50-
pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
51-
- alias: metav1
52-
pkg: k8s.io/apimachinery/pkg/apis/meta/v1
53-
- alias: testingutils
54-
pkg: github.com/argoproj/gitops-engine/pkg/utils/testing
55-
perfsprint:
56-
# Optimizes even if it requires an int or uint type cast.
57-
int-conversion: true
58-
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
59-
err-error: true
60-
# Optimizes `fmt.Errorf`.
61-
errorf: true
62-
# Optimizes `fmt.Sprintf` with only one argument.
63-
sprintf1: true
64-
# Optimizes into strings concatenation.
65-
strconcat: true
66-
revive:
67-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
68-
rules:
69-
- name: bool-literal-in-expr
70-
- name: blank-imports
71-
disabled: true
72-
- name: context-as-argument
73-
arguments:
74-
- allowTypesBefore: '*testing.T,testing.TB'
75-
- name: context-keys-type
76-
disabled: true
77-
- name: dot-imports
78-
- name: duplicated-imports
79-
- name: early-return
80-
arguments:
81-
- 'preserveScope'
82-
- name: empty-block
83-
disabled: true
84-
- name: error-naming
85-
disabled: true
86-
- name: error-return
87-
- name: error-strings
88-
disabled: true
89-
- name: errorf
90-
- name: identical-branches
91-
- name: if-return
92-
- name: increment-decrement
93-
- name: indent-error-flow
94-
arguments:
95-
- 'preserveScope'
96-
- name: modifies-parameter
97-
- name: optimize-operands-order
98-
- name: range
99-
- name: receiver-naming
100-
- name: redefines-builtin-id
101-
disabled: true
102-
- name: redundant-import-alias
103-
- name: superfluous-else
104-
arguments:
105-
- 'preserveScope'
106-
- name: time-equal
107-
- name: time-naming
108-
disabled: true
109-
- name: unexported-return
110-
disabled: true
111-
- name: unnecessary-stmt
112-
- name: unreachable-code
113-
- name: unused-parameter
114-
- name: use-any
115-
- name: useless-break
116-
- name: var-declaration
117-
- name: var-naming
118-
disabled: true
119-
testifylint:
120-
enable-all: true
121-
disable:
122-
- go-require
123-
run:
124-
timeout: 5m
16+
settings:
17+
gocritic:
18+
disabled-checks:
19+
- appendAssign
20+
- assignOp
21+
- exitAfterDefer
22+
- typeSwitchVar
23+
importas:
24+
alias:
25+
- pkg: k8s.io/api/apps/v1
26+
alias: appsv1
27+
- pkg: k8s.io/api/core/v1
28+
alias: corev1
29+
- pkg: k8s.io/apimachinery/pkg/api/errors
30+
alias: apierrors
31+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
32+
alias: apiextensionsv1
33+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
34+
alias: metav1
35+
- pkg: github.com/argoproj/gitops-engine/pkg/utils/testing
36+
alias: testingutils
37+
perfsprint:
38+
int-conversion: true
39+
err-error: true
40+
errorf: true
41+
sprintf1: true
42+
strconcat: true
43+
revive:
44+
rules:
45+
- name: bool-literal-in-expr
46+
- name: blank-imports
47+
disabled: true
48+
- name: context-as-argument
49+
arguments:
50+
- allowTypesBefore: '*testing.T,testing.TB'
51+
- name: context-keys-type
52+
disabled: true
53+
- name: dot-imports
54+
- name: duplicated-imports
55+
- name: early-return
56+
arguments:
57+
- preserveScope
58+
- name: empty-block
59+
disabled: true
60+
- name: error-naming
61+
disabled: true
62+
- name: error-return
63+
- name: error-strings
64+
disabled: true
65+
- name: errorf
66+
- name: identical-branches
67+
- name: if-return
68+
- name: increment-decrement
69+
- name: indent-error-flow
70+
arguments:
71+
- preserveScope
72+
- name: modifies-parameter
73+
- name: optimize-operands-order
74+
- name: range
75+
- name: receiver-naming
76+
- name: redefines-builtin-id
77+
disabled: true
78+
- name: redundant-import-alias
79+
- name: superfluous-else
80+
arguments:
81+
- preserveScope
82+
- name: time-equal
83+
- name: time-naming
84+
disabled: true
85+
- name: unexported-return
86+
disabled: true
87+
- name: unnecessary-stmt
88+
- name: unreachable-code
89+
- name: unused-parameter
90+
- name: use-any
91+
- name: useless-break
92+
- name: var-declaration
93+
- name: var-naming
94+
disabled: true
95+
testifylint:
96+
enable-all: true
97+
disable:
98+
- go-require
99+
exclusions:
100+
presets:
101+
- comments
102+
- common-false-positives
103+
- legacy
104+
- std-error-handling
105+
paths:
106+
- pkg/diff/internal/fieldmanager/borrowed_.*\.go$
107+
- internal/kubernetes_vendor
108+
- third_party$
109+
- builtin$
110+
- examples$
111+
issues:
112+
max-issues-per-linter: 0
113+
max-same-issues: 0
114+
formatters:
115+
enable:
116+
- gofumpt
117+
- goimports
118+
settings:
119+
goimports:
120+
local-prefixes:
121+
- github.com/argoproj/gitops-engine
122+
exclusions:
123+
paths:
124+
- pkg/diff/internal/fieldmanager/borrowed_.*\.go$
125+
- internal/kubernetes_vendor
126+
- third_party$
127+
- builtin$
128+
- examples$

agent/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type settings struct {
5454

5555
func (s *settings) getGCMark(key kube.ResourceKey) string {
5656
h := sha256.New()
57-
_, _ = h.Write([]byte(fmt.Sprintf("%s/%s", s.repoPath, strings.Join(s.paths, ","))))
57+
_, _ = fmt.Fprintf(h, "%s/%s", s.repoPath, strings.Join(s.paths, ","))
5858
_, _ = h.Write([]byte(strings.Join([]string{key.Group, key.Kind, key.Name}, "/")))
5959
return "sha256." + base64.RawURLEncoding.EncodeToString(h.Sum(nil))
6060
}

pkg/cache/cluster.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ func (c *clusterCache) watchEvents(ctx context.Context, api kube.APIResourceInfo
654654
kube.RetryUntilSucceed(ctx, watchResourcesRetryTimeout, fmt.Sprintf("watch %s on %s", api.GroupKind, c.config.Host), c.log, func() (err error) {
655655
defer func() {
656656
if r := recover(); r != nil {
657-
err = fmt.Errorf("Recovered from panic: %+v\n%s", r, debug.Stack())
657+
err = fmt.Errorf("recovered from panic: %+v\n%s", r, debug.Stack())
658658
}
659659
}()
660660

@@ -699,20 +699,20 @@ func (c *clusterCache) watchEvents(ctx context.Context, api kube.APIResourceInfo
699699

700700
// re-synchronize API state and restart watch periodically
701701
case <-watchResyncTimeoutCh:
702-
return fmt.Errorf("Resyncing %s on %s due to timeout", api.GroupKind, c.config.Host)
702+
return fmt.Errorf("resyncing %s on %s due to timeout", api.GroupKind, c.config.Host)
703703

704704
// re-synchronize API state and restart watch if retry watcher failed to continue watching using provided resource version
705705
case <-w.Done():
706-
return fmt.Errorf("Watch %s on %s has closed", api.GroupKind, c.config.Host)
706+
return fmt.Errorf("watch %s on %s has closed", api.GroupKind, c.config.Host)
707707

708708
case event, ok := <-w.ResultChan():
709709
if !ok {
710-
return fmt.Errorf("Watch %s on %s has closed", api.GroupKind, c.config.Host)
710+
return fmt.Errorf("watch %s on %s has closed", api.GroupKind, c.config.Host)
711711
}
712712

713713
obj, ok := event.Object.(*unstructured.Unstructured)
714714
if !ok {
715-
return fmt.Errorf("Failed to convert to *unstructured.Unstructured: %v", event.Object)
715+
return fmt.Errorf("failed to convert to *unstructured.Unstructured: %v", event.Object)
716716
}
717717

718718
c.recordEvent(event.Type, obj)
@@ -1217,9 +1217,9 @@ func (c *clusterCache) GetManagedLiveObjs(targetObjs []*unstructured.Unstructure
12171217
for _, o := range targetObjs {
12181218
if len(c.namespaces) > 0 {
12191219
if o.GetNamespace() == "" && !c.clusterResources {
1220-
return nil, fmt.Errorf("Cluster level %s %q can not be managed when in namespaced mode", o.GetKind(), o.GetName())
1220+
return nil, fmt.Errorf("cluster level %s %q can not be managed when in namespaced mode", o.GetKind(), o.GetName())
12211221
} else if o.GetNamespace() != "" && !c.managesNamespace(o.GetNamespace()) {
1222-
return nil, fmt.Errorf("Namespace %q for %s %q is not managed", o.GetNamespace(), o.GetKind(), o.GetName())
1222+
return nil, fmt.Errorf("namespace %q for %s %q is not managed", o.GetNamespace(), o.GetKind(), o.GetName())
12231223
}
12241224
}
12251225
}

pkg/cache/cluster_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ metadata:
441441
return len(r.OwnerRefs) == 0
442442
})
443443
assert.Nil(t, managedObjs)
444-
assert.EqualError(t, err, "Cluster level Deployment \"helm-guestbook\" can not be managed when in namespaced mode")
444+
assert.EqualError(t, err, "cluster level Deployment \"helm-guestbook\" can not be managed when in namespaced mode")
445445
}
446446

447447
func TestGetManagedLiveObjsNamespacedModeClusterLevelResource_ClusterResourceEnabled(t *testing.T) {
@@ -482,7 +482,7 @@ metadata:
482482
_, err = cluster.GetManagedLiveObjs([]*unstructured.Unstructured{otherNamespaceRes}, func(r *Resource) bool {
483483
return len(r.OwnerRefs) == 0
484484
})
485-
assert.EqualError(t, err, "Namespace \"some-other-namespace\" for Deployment \"helm-guestbook\" is not managed")
485+
assert.EqualError(t, err, "namespace \"some-other-namespace\" for Deployment \"helm-guestbook\" is not managed")
486486
}
487487

488488
func TestGetManagedLiveObjsAllNamespaces(t *testing.T) {
@@ -564,7 +564,7 @@ metadata:
564564
return len(r.OwnerRefs) == 0
565565
})
566566
assert.Nil(t, managedObjs)
567-
assert.EqualError(t, err, "Namespace \"production\" for Deployment \"helm-guestbook\" is not managed")
567+
assert.EqualError(t, err, "namespace \"production\" for Deployment \"helm-guestbook\" is not managed")
568568
}
569569

570570
func TestGetManagedLiveObjsFailedConversion(t *testing.T) {

pkg/cache/resource.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ func (r *Resource) iterateChildrenV2(graph map[kube.ResourceKey]map[types.UID]*R
118118
for _, c := range children {
119119
childKey := c.ResourceKey()
120120
child := ns[childKey]
121-
if visited[childKey] == 1 {
121+
switch visited[childKey] {
122+
case 1:
122123
// Since we encountered a node that we're currently processing, we know we have a circular dependency.
123124
_ = action(fmt.Errorf("circular dependency detected. %s is child and parent of %s", childKey.String(), key.String()), child, ns)
124-
} else if visited[childKey] == 0 {
125+
case 0:
125126
if action(nil, child, ns) {
126127
child.iterateChildrenV2(graph, ns, visited, action)
127128
}

pkg/diff/diff_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func TestDiffArrayModification(t *testing.T) {
275275
func TestThreeWayDiff(t *testing.T) {
276276
// 1. get config and live to be the same. Both have a foo annotation.
277277
configDep := newDeployment()
278-
configDep.ObjectMeta.Namespace = ""
278+
configDep.Namespace = ""
279279
configDep.Annotations = map[string]string{
280280
"foo": "bar",
281281
}
@@ -540,7 +540,7 @@ func TestRemoveNamespaceAnnotation(t *testing.T) {
540540
"namespace": "default",
541541
},
542542
}})
543-
assert.Equal(t, "", obj.GetNamespace())
543+
assert.Empty(t, obj.GetNamespace())
544544

545545
obj = removeNamespaceAnnotation(&unstructured.Unstructured{Object: map[string]any{
546546
"metadata": map[string]any{
@@ -549,7 +549,7 @@ func TestRemoveNamespaceAnnotation(t *testing.T) {
549549
"annotations": make(map[string]any),
550550
},
551551
}})
552-
assert.Equal(t, "", obj.GetNamespace())
552+
assert.Empty(t, obj.GetNamespace())
553553
assert.Nil(t, obj.GetAnnotations())
554554

555555
obj = removeNamespaceAnnotation(&unstructured.Unstructured{Object: map[string]any{
@@ -559,7 +559,7 @@ func TestRemoveNamespaceAnnotation(t *testing.T) {
559559
"annotations": "wrong value",
560560
},
561561
}})
562-
assert.Equal(t, "", obj.GetNamespace())
562+
assert.Empty(t, obj.GetNamespace())
563563
val, _, _ := unstructured.NestedString(obj.Object, "metadata", "annotations")
564564
assert.Equal(t, "wrong value", val)
565565
}

pkg/health/health_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,5 @@ func TestGetArgoWorkflowHealth(t *testing.T) {
170170
health, err = getArgoWorkflowHealth(&sampleWorkflow)
171171
require.NoError(t, err)
172172
assert.Equal(t, HealthStatusProgressing, health.Status)
173-
assert.Equal(t, "", health.Message)
173+
assert.Empty(t, health.Message)
174174
}

0 commit comments

Comments
 (0)