Skip to content

Commit ccee583

Browse files
authored
chore: enable unused-parameter and var-declaration from revive (#668)
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent edb9faa commit ccee583

File tree

16 files changed

+54
-56
lines changed

16 files changed

+54
-56
lines changed

.golangci.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,9 @@ linters-settings:
9898
disabled: true
9999
- name: unreachable-code
100100
- name: unused-parameter
101-
disabled: true
102101
- name: use-any
103102
- name: useless-break
104103
- name: var-declaration
105-
disabled: true
106104
- name: var-naming
107105
disabled: true
108106
testifylint:

agent/main.go

Lines changed: 2 additions & 2 deletions
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 any, cacheManifest bool) {
153+
cache.SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, _ bool) (info any, cacheManifest bool) {
154154
// store gc mark of every resource
155155
gcMark := un.GetAnnotations()[annotationGCMark]
156156
info = &resourceInfo{gcMark: un.GetAnnotations()[annotationGCMark]}
@@ -175,7 +175,7 @@ func newCmd(log logr.Logger) *cobra.Command {
175175
resync <- true
176176
}
177177
}()
178-
http.HandleFunc("/api/v1/sync", func(writer http.ResponseWriter, request *http.Request) {
178+
http.HandleFunc("/api/v1/sync", func(_ http.ResponseWriter, _ *http.Request) {
179179
log.Info("Synchronization triggered by API call")
180180
resync <- true
181181
})

pkg/cache/cluster.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,12 @@ type clusterCacheSync struct {
264264
}
265265

266266
// ListRetryFuncNever never retries on errors
267-
func ListRetryFuncNever(err error) bool {
267+
func ListRetryFuncNever(_ error) bool {
268268
return false
269269
}
270270

271271
// ListRetryFuncAlways always retries on errors
272-
func ListRetryFuncAlways(err error) bool {
272+
func ListRetryFuncAlways(_ error) bool {
273273
return true
274274
}
275275

@@ -589,7 +589,7 @@ func (c *clusterCache) listResources(ctx context.Context, resClient dynamic.Reso
589589
}
590590
defer c.listSemaphore.Release(1)
591591

592-
var retryCount int64 = 0
592+
var retryCount int64
593593
resourceVersion := ""
594594
listPager := pager.New(func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
595595
var res *unstructured.UnstructuredList

pkg/cache/cluster_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func newCluster(t testing.TB, objs ...runtime.Object) *clusterCache {
8484
return cache
8585
}
8686

87-
func newClusterWithOptions(t testing.TB, opts []UpdateSettingsFunc, objs ...runtime.Object) *clusterCache {
87+
func newClusterWithOptions(_ testing.TB, opts []UpdateSettingsFunc, objs ...runtime.Object) *clusterCache {
8888
client := fake.NewSimpleDynamicClient(scheme.Scheme, objs...)
8989
reactor := client.ReactionChain[0]
9090
client.PrependReactor("list", "*", func(action testcore.Action) (handled bool, ret runtime.Object, err error) {
@@ -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 any, cacheManifest bool) {
178+
c.populateResourceInfoHandler = func(_ *unstructured.Unstructured, _ 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 any, cacheManifest bool) {
397+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(_ *unstructured.Unstructured, _ 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 any, cacheManifest bool) {
423+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(_ *unstructured.Unstructured, _ 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 any, cacheManifest bool) {
448+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(_ *unstructured.Unstructured, _ 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 any, cacheManifest bool) {
489+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(_ *unstructured.Unstructured, _ 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 any, cacheManifest bool) {
517+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(_ *unstructured.Unstructured, _ 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 any, cacheManifest bool) {
545+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(_ *unstructured.Unstructured, _ 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 any, cacheManifest bool) {
605+
cluster.Invalidate(SetPopulateResourceInfoHandler(func(_ *unstructured.Unstructured, _ bool) (info any, cacheManifest bool) {
606606
return nil, true
607607
}))
608608
cluster.namespaces = []string{"default"}
@@ -634,7 +634,7 @@ metadata:
634634
return testCronTab(), nil
635635
})
636636

637-
managedObjs, err := cluster.GetManagedLiveObjs([]*unstructured.Unstructured{targetDeploy}, func(r *Resource) bool {
637+
managedObjs, err := cluster.GetManagedLiveObjs([]*unstructured.Unstructured{targetDeploy}, func(_ *Resource) bool {
638638
return true
639639
})
640640
assert.NoError(t, err)
@@ -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 any, cacheManifest bool) {
1261+
SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, _ 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
@@ -1370,7 +1370,7 @@ func BenchmarkIterateHierarchyV2(b *testing.B) {
13701370
for n := 0; n < b.N; n++ {
13711371
cluster.IterateHierarchyV2([]kube.ResourceKey{
13721372
{Namespace: "default", Name: "test-1", Kind: "Pod"},
1373-
}, func(child *Resource, _ map[kube.ResourceKey]*Resource) bool {
1373+
}, func(_ *Resource, _ map[kube.ResourceKey]*Resource) bool {
13741374
return true
13751375
})
13761376
}

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 any, cacheManifest bool) {
101+
SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, _ 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/diff/diff.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type DiffResultList struct {
5757

5858
type noopNormalizer struct{}
5959

60-
func (n *noopNormalizer) Normalize(un *unstructured.Unstructured) error {
60+
func (n *noopNormalizer) Normalize(_ *unstructured.Unstructured) error {
6161
return nil
6262
}
6363

@@ -201,7 +201,7 @@ func serverSideDiff(config, live *unstructured.Unstructured, opts ...Option) (*D
201201
// managedFields. All fields under this condition will be reverted with their state
202202
// from live. If the given predictedLive does not have the managedFields, an error
203203
// will be returned.
204-
func removeWebhookMutation(predictedLive, live *unstructured.Unstructured, gvkParser *managedfields.GvkParser, manager string) (*unstructured.Unstructured, error) {
204+
func removeWebhookMutation(predictedLive, live *unstructured.Unstructured, gvkParser *managedfields.GvkParser, _ string) (*unstructured.Unstructured, error) {
205205
plManagedFields := predictedLive.GetManagedFields()
206206
if len(plManagedFields) == 0 {
207207
return nil, fmt.Errorf("predictedLive for resource %s/%s must have the managedFields", predictedLive.GetKind(), predictedLive.GetName())

pkg/diff/diff_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ func TestServerSideDiff(t *testing.T) {
895895
dryRunner := mocks.NewServerSideDryRunner(t)
896896

897897
dryRunner.On("Run", mock.Anything, mock.AnythingOfType("*unstructured.Unstructured"), manager).
898-
Return(func(ctx context.Context, obj *unstructured.Unstructured, manager string) (string, error) {
898+
Return(func(_ context.Context, _ *unstructured.Unstructured, _ string) (string, error) {
899899
return predictedLive, nil
900900
})
901901
opts := []Option{

pkg/engine/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (e *gitOpsEngine) Sync(ctx context.Context,
9292

9393
resUpdated := make(chan bool)
9494
resIgnore := make(chan struct{})
95-
unsubscribe := e.cache.OnResourceUpdated(func(newRes *cache.Resource, oldRes *cache.Resource, namespaceResources map[kube.ResourceKey]*cache.Resource) {
95+
unsubscribe := e.cache.OnResourceUpdated(func(newRes *cache.Resource, oldRes *cache.Resource, _ map[kube.ResourceKey]*cache.Resource) {
9696
var key kube.ResourceKey
9797
if newRes != nil {
9898
key = newRes.ResourceKey()

pkg/sync/reconcile_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
type unknownResourceInfoProvider struct{}
1515

16-
func (e *unknownResourceInfoProvider) IsNamespaced(gk schema.GroupKind) (bool, error) {
16+
func (e *unknownResourceInfoProvider) IsNamespaced(_ schema.GroupKind) (bool, error) {
1717
return false, errors.New("unknown")
1818
}
1919

pkg/sync/sync_context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ func (sc *syncContext) GetState() (common.OperationPhase, string, []common.Resou
598598
}
599599

600600
func (sc *syncContext) setOperationFailed(syncFailTasks, syncFailedTasks syncTasks, message string) {
601-
errorMessageFactory := func(tasks []*syncTask, message string) string {
601+
errorMessageFactory := func(_ []*syncTask, message string) string {
602602
messages := syncFailedTasks.Map(func(task *syncTask) string {
603603
return task.message
604604
})
@@ -933,7 +933,7 @@ func (sc *syncContext) setOperationPhase(phase common.OperationPhase, message st
933933

934934
// ensureCRDReady waits until specified CRD is ready (established condition is true).
935935
func (sc *syncContext) ensureCRDReady(name string) error {
936-
return wait.PollUntilContextTimeout(context.Background(), time.Duration(100)*time.Millisecond, crdReadinessTimeout, true, func(ctx context.Context) (bool, error) {
936+
return wait.PollUntilContextTimeout(context.Background(), time.Duration(100)*time.Millisecond, crdReadinessTimeout, true, func(_ context.Context) (bool, error) {
937937
crd, err := sc.extensionsclientset.ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), name, metav1.GetOptions{})
938938
if err != nil {
939939
return false, err

0 commit comments

Comments
 (0)