Skip to content

Commit 7ac688a

Browse files
authored
chore: enable use-any from revive (#667)
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent f948991 commit 7ac688a

21 files changed

+271
-206
lines changed

.golangci.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
issues:
2+
exclude-dirs:
3+
- internal/kubernetes_vendor
24
exclude-files:
35
- "pkg/diff/internal/fieldmanager/borrowed_.*\\.go$"
46
max-issues-per-linter: 0
@@ -7,9 +9,72 @@ linters:
79
enable:
810
- gofumpt
911
- gosimple
12+
- revive
1013
- testifylint
1114
- whitespace
1215
linters-settings:
16+
revive:
17+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
18+
rules:
19+
- name: bool-literal-in-expr
20+
- name: blank-imports
21+
disabled: true
22+
- name: context-as-argument
23+
arguments:
24+
- allowTypesBefore: '*testing.T,testing.TB'
25+
- name: context-keys-type
26+
disabled: true
27+
- name: dot-imports
28+
disabled: true
29+
- name: duplicated-imports
30+
disabled: true
31+
- name: early-return
32+
disabled: true
33+
arguments:
34+
- 'preserveScope'
35+
- name: empty-block
36+
disabled: true
37+
- name: error-naming
38+
disabled: true
39+
- name: error-return
40+
- name: error-strings
41+
disabled: true
42+
- name: errorf
43+
- name: identical-branches
44+
- name: if-return
45+
- name: increment-decrement
46+
disabled: true
47+
- name: indent-error-flow
48+
disabled: true
49+
arguments:
50+
- 'preserveScope'
51+
- name: modifies-parameter
52+
- name: optimize-operands-order
53+
- name: range
54+
- name: receiver-naming
55+
- name: redefines-builtin-id
56+
disabled: true
57+
- name: redundant-import-alias
58+
disabled: true
59+
- name: superfluous-else
60+
arguments:
61+
- 'preserveScope'
62+
- name: time-equal
63+
- name: time-naming
64+
disabled: true
65+
- name: unexported-return
66+
disabled: true
67+
- name: unnecessary-stmt
68+
disabled: true
69+
- name: unreachable-code
70+
- name: unused-parameter
71+
disabled: true
72+
- name: use-any
73+
- name: useless-break
74+
- name: var-declaration
75+
disabled: true
76+
- name: var-naming
77+
disabled: true
1378
testifylint:
1479
enable-all: true
1580
disable:

agent/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func newCmd(log logr.Logger) *cobra.Command {
150150
clusterCache := cache.NewClusterCache(config,
151151
cache.SetNamespaces(namespaces),
152152
cache.SetLogr(log),
153-
cache.SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
153+
cache.SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
154154
// store gc mark of every resource
155155
gcMark := un.GetAnnotations()[annotationGCMark]
156156
info = &resourceInfo{gcMark: un.GetAnnotations()[annotationGCMark]}

pkg/cache/cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type OnEventHandler func(event watch.EventType, un *unstructured.Unstructured)
107107
type OnProcessEventsHandler func(duration time.Duration, processedEventsNumber int)
108108

109109
// OnPopulateResourceInfoHandler returns additional resource metadata that should be stored in cache
110-
type OnPopulateResourceInfoHandler func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool)
110+
type OnPopulateResourceInfoHandler func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool)
111111

112112
// OnResourceUpdatedHandler handlers resource update event
113113
type (
@@ -423,7 +423,7 @@ func (c *clusterCache) newResource(un *unstructured.Unstructured) *Resource {
423423
ownerRefs, isInferredParentOf := c.resolveResourceReferences(un)
424424

425425
cacheManifest := false
426-
var info interface{}
426+
var info any
427427
if c.populateResourceInfoHandler != nil {
428428
info, cacheManifest = c.populateResourceInfoHandler(un, len(ownerRefs) == 0)
429429
}

pkg/cache/cluster_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
"github.com/argoproj/gitops-engine/pkg/utils/kube/kubetest"
3636
)
3737

38-
func mustToUnstructured(obj interface{}) *unstructured.Unstructured {
38+
func mustToUnstructured(obj any) *unstructured.Unstructured {
3939
un, err := kube.ToUnstructured(obj)
4040
if err != nil {
4141
panic(err)
@@ -44,7 +44,7 @@ func mustToUnstructured(obj interface{}) *unstructured.Unstructured {
4444
}
4545

4646
func strToUnstructured(jsonStr string) *unstructured.Unstructured {
47-
obj := make(map[string]interface{})
47+
obj := make(map[string]any)
4848
err := yaml.Unmarshal([]byte(jsonStr), &obj)
4949
if err != nil {
5050
panic(err)
@@ -175,7 +175,7 @@ func Benchmark_sync(t *testing.B) {
175175

176176
c := newCluster(t, resources...)
177177

178-
c.populateResourceInfoHandler = func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
178+
c.populateResourceInfoHandler = func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
179179
time.Sleep(10 * time.Microsecond)
180180
return nil, false
181181
}
@@ -394,7 +394,7 @@ func TestGetChildren(t *testing.T) {
394394

395395
func TestGetManagedLiveObjs(t *testing.T) {
396396
cluster := newCluster(t, testPod1(), testRS(), testDeploy())
397-
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
397+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
398398
return nil, true
399399
}))
400400

@@ -420,7 +420,7 @@ metadata:
420420

421421
func TestGetManagedLiveObjsNamespacedModeClusterLevelResource(t *testing.T) {
422422
cluster := newCluster(t, testPod1(), testRS(), testDeploy())
423-
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
423+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
424424
return nil, true
425425
}))
426426
cluster.namespaces = []string{"default", "production"}
@@ -445,7 +445,7 @@ metadata:
445445

446446
func TestGetManagedLiveObjsNamespacedModeClusterLevelResource_ClusterResourceEnabled(t *testing.T) {
447447
cluster := newCluster(t, testPod1(), testRS(), testDeploy())
448-
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
448+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
449449
return nil, true
450450
}))
451451
cluster.namespaces = []string{"default", "production"}
@@ -486,7 +486,7 @@ metadata:
486486

487487
func TestGetManagedLiveObjsAllNamespaces(t *testing.T) {
488488
cluster := newCluster(t, testPod1(), testRS(), testDeploy())
489-
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
489+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
490490
return nil, true
491491
}))
492492
cluster.namespaces = nil
@@ -514,7 +514,7 @@ metadata:
514514

515515
func TestGetManagedLiveObjsValidNamespace(t *testing.T) {
516516
cluster := newCluster(t, testPod1(), testRS(), testDeploy())
517-
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
517+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
518518
return nil, true
519519
}))
520520
cluster.namespaces = []string{"default", "production"}
@@ -542,7 +542,7 @@ metadata:
542542

543543
func TestGetManagedLiveObjsInvalidNamespace(t *testing.T) {
544544
cluster := newCluster(t, testPod1(), testRS(), testDeploy())
545-
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
545+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
546546
return nil, true
547547
}))
548548
cluster.namespaces = []string{"default", "develop"}
@@ -602,7 +602,7 @@ func TestGetManagedLiveObjsFailedConversion(t *testing.T) {
602602
Meta: metav1.APIResource{Namespaced: true},
603603
},
604604
})
605-
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
605+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
606606
return nil, true
607607
}))
608608
cluster.namespaces = []string{"default"}
@@ -953,14 +953,14 @@ func testCRD() *apiextensions.CustomResourceDefinition {
953953
}
954954

955955
func testCronTab() *unstructured.Unstructured {
956-
return &unstructured.Unstructured{Object: map[string]interface{}{
956+
return &unstructured.Unstructured{Object: map[string]any{
957957
"apiVersion": "stable.example.com/v1",
958958
"kind": "CronTab",
959-
"metadata": map[string]interface{}{
959+
"metadata": map[string]any{
960960
"name": "test-crontab",
961961
"namespace": "default",
962962
},
963-
"spec": map[string]interface{}{
963+
"spec": map[string]any{
964964
"cronSpec": "* * * * */5",
965965
"image": "my-awesome-cron-image",
966966
},
@@ -1258,7 +1258,7 @@ func Test_watchEvents_Deadlock(t *testing.T) {
12581258
// Resync watches often to use the semaphore and trigger the rate limiting behavior
12591259
SetResyncTimeout(500 * time.Millisecond),
12601260
// Use new resource handler to run code in the list callbacks
1261-
SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
1261+
SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
12621262
if un.GroupVersionKind().GroupKind() == res1.GroupVersionKind().GroupKind() ||
12631263
un.GroupVersionKind().GroupKind() == res2.GroupVersionKind().GroupKind() {
12641264
// Create a bottleneck for resources holding the semaphore

pkg/cache/predicates_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func ExampleNewClusterCache_inspectNamespaceResources() {
9898
// cache default namespace only
9999
SetNamespaces([]string{"default", "kube-system"}),
100100
// configure custom logic to cache resources manifest and additional metadata
101-
SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
101+
SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
102102
// if resource belongs to 'extensions' group then mark if with 'deprecated' label
103103
if un.GroupVersionKind().Group == "extensions" {
104104
info = []string{"deprecated"}

pkg/cache/references_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ func Test_isStatefulSetChild(t *testing.T) {
6868
{
6969
name: "Mismatch PVC for sw-broker",
7070
args: args{un: &unstructured.Unstructured{
71-
Object: map[string]interface{}{
71+
Object: map[string]any{
7272
"apiVersion": "apps/v1",
7373
"kind": "StatefulSet",
74-
"metadata": map[string]interface{}{
74+
"metadata": map[string]any{
7575
"name": "sw-broker",
7676
},
77-
"spec": map[string]interface{}{
78-
"volumeClaimTemplates": []interface{}{
79-
map[string]interface{}{
80-
"metadata": map[string]interface{}{
77+
"spec": map[string]any{
78+
"volumeClaimTemplates": []any{
79+
map[string]any{
80+
"metadata": map[string]any{
8181
"name": "volume-2",
8282
},
8383
},

pkg/cache/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Resource struct {
2323
// Optional creation timestamp of the resource
2424
CreationTimestamp *metav1.Time
2525
// Optional additional information about the resource
26-
Info interface{}
26+
Info any
2727
// Optional whole resource manifest
2828
Resource *unstructured.Unstructured
2929

0 commit comments

Comments
 (0)