Skip to content

Commit

Permalink
chore: enable use-any from revive (#667)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 authored Feb 6, 2025
1 parent f948991 commit 7ac688a
Show file tree
Hide file tree
Showing 21 changed files with 271 additions and 206 deletions.
65 changes: 65 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
issues:
exclude-dirs:
- internal/kubernetes_vendor
exclude-files:
- "pkg/diff/internal/fieldmanager/borrowed_.*\\.go$"
max-issues-per-linter: 0
Expand All @@ -7,9 +9,72 @@ linters:
enable:
- gofumpt
- gosimple
- revive
- testifylint
- whitespace
linters-settings:
revive:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
rules:
- name: bool-literal-in-expr
- name: blank-imports
disabled: true
- name: context-as-argument
arguments:
- allowTypesBefore: '*testing.T,testing.TB'
- name: context-keys-type
disabled: true
- name: dot-imports
disabled: true
- name: duplicated-imports
disabled: true
- name: early-return
disabled: true
arguments:
- 'preserveScope'
- name: empty-block
disabled: true
- name: error-naming
disabled: true
- name: error-return
- name: error-strings
disabled: true
- name: errorf
- name: identical-branches
- name: if-return
- name: increment-decrement
disabled: true
- name: indent-error-flow
disabled: true
arguments:
- 'preserveScope'
- name: modifies-parameter
- name: optimize-operands-order
- name: range
- name: receiver-naming
- name: redefines-builtin-id
disabled: true
- name: redundant-import-alias
disabled: true
- name: superfluous-else
arguments:
- 'preserveScope'
- name: time-equal
- name: time-naming
disabled: true
- name: unexported-return
disabled: true
- name: unnecessary-stmt
disabled: true
- name: unreachable-code
- name: unused-parameter
disabled: true
- name: use-any
- name: useless-break
- name: var-declaration
disabled: true
- name: var-naming
disabled: true
testifylint:
enable-all: true
disable:
Expand Down
2 changes: 1 addition & 1 deletion agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func newCmd(log logr.Logger) *cobra.Command {
clusterCache := cache.NewClusterCache(config,
cache.SetNamespaces(namespaces),
cache.SetLogr(log),
cache.SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
cache.SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
// store gc mark of every resource
gcMark := un.GetAnnotations()[annotationGCMark]
info = &resourceInfo{gcMark: un.GetAnnotations()[annotationGCMark]}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type OnEventHandler func(event watch.EventType, un *unstructured.Unstructured)
type OnProcessEventsHandler func(duration time.Duration, processedEventsNumber int)

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

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

cacheManifest := false
var info interface{}
var info any
if c.populateResourceInfoHandler != nil {
info, cacheManifest = c.populateResourceInfoHandler(un, len(ownerRefs) == 0)
}
Expand Down
28 changes: 14 additions & 14 deletions pkg/cache/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"github.com/argoproj/gitops-engine/pkg/utils/kube/kubetest"
)

func mustToUnstructured(obj interface{}) *unstructured.Unstructured {
func mustToUnstructured(obj any) *unstructured.Unstructured {
un, err := kube.ToUnstructured(obj)
if err != nil {
panic(err)
Expand All @@ -44,7 +44,7 @@ func mustToUnstructured(obj interface{}) *unstructured.Unstructured {
}

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

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

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

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

Expand All @@ -420,7 +420,7 @@ metadata:

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

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

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

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

func TestGetManagedLiveObjsInvalidNamespace(t *testing.T) {
cluster := newCluster(t, testPod1(), testRS(), testDeploy())
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
return nil, true
}))
cluster.namespaces = []string{"default", "develop"}
Expand Down Expand Up @@ -602,7 +602,7 @@ func TestGetManagedLiveObjsFailedConversion(t *testing.T) {
Meta: metav1.APIResource{Namespaced: true},
},
})
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
cluster.Invalidate(SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
return nil, true
}))
cluster.namespaces = []string{"default"}
Expand Down Expand Up @@ -953,14 +953,14 @@ func testCRD() *apiextensions.CustomResourceDefinition {
}

func testCronTab() *unstructured.Unstructured {
return &unstructured.Unstructured{Object: map[string]interface{}{
return &unstructured.Unstructured{Object: map[string]any{
"apiVersion": "stable.example.com/v1",
"kind": "CronTab",
"metadata": map[string]interface{}{
"metadata": map[string]any{
"name": "test-crontab",
"namespace": "default",
},
"spec": map[string]interface{}{
"spec": map[string]any{
"cronSpec": "* * * * */5",
"image": "my-awesome-cron-image",
},
Expand Down Expand Up @@ -1258,7 +1258,7 @@ func Test_watchEvents_Deadlock(t *testing.T) {
// Resync watches often to use the semaphore and trigger the rate limiting behavior
SetResyncTimeout(500 * time.Millisecond),
// Use new resource handler to run code in the list callbacks
SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
if un.GroupVersionKind().GroupKind() == res1.GroupVersionKind().GroupKind() ||
un.GroupVersionKind().GroupKind() == res2.GroupVersionKind().GroupKind() {
// Create a bottleneck for resources holding the semaphore
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/predicates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func ExampleNewClusterCache_inspectNamespaceResources() {
// cache default namespace only
SetNamespaces([]string{"default", "kube-system"}),
// configure custom logic to cache resources manifest and additional metadata
SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info any, cacheManifest bool) {
// if resource belongs to 'extensions' group then mark if with 'deprecated' label
if un.GroupVersionKind().Group == "extensions" {
info = []string{"deprecated"}
Expand Down
12 changes: 6 additions & 6 deletions pkg/cache/references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ func Test_isStatefulSetChild(t *testing.T) {
{
name: "Mismatch PVC for sw-broker",
args: args{un: &unstructured.Unstructured{
Object: map[string]interface{}{
Object: map[string]any{
"apiVersion": "apps/v1",
"kind": "StatefulSet",
"metadata": map[string]interface{}{
"metadata": map[string]any{
"name": "sw-broker",
},
"spec": map[string]interface{}{
"volumeClaimTemplates": []interface{}{
map[string]interface{}{
"metadata": map[string]interface{}{
"spec": map[string]any{
"volumeClaimTemplates": []any{
map[string]any{
"metadata": map[string]any{
"name": "volume-2",
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Resource struct {
// Optional creation timestamp of the resource
CreationTimestamp *metav1.Time
// Optional additional information about the resource
Info interface{}
Info any
// Optional whole resource manifest
Resource *unstructured.Unstructured

Expand Down
Loading

0 comments on commit 7ac688a

Please sign in to comment.