Skip to content

Commit ff6c49e

Browse files
committed
Upgrade golangci-lint and fix warnings
1 parent c94ec71 commit ff6c49e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+124
-124
lines changed

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
run:
5-
deadline: 30m
5+
timeout: 30m
66

77
linters:
88
# please, do not use `enable-all`: it's deprecated and will be removed soon.

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ all: generate license fix vet fmt test lint tidy
1616
go install github.com/google/[email protected]
1717

1818
"$(MYGOBIN)/golangci-lint":
19-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3
19+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2
2020

2121
"$(MYGOBIN)/deepcopy-gen":
2222
go install k8s.io/code-generator/cmd/[email protected]

pkg/apply/applier.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,13 @@ func (a *Applier) Run(ctx context.Context, invInfo inventory.Info, objects objec
213213
}
214214
// Create a new TaskStatusRunner to execute the taskQueue.
215215
klog.V(4).Infoln("applier building TaskStatusRunner...")
216-
allIds := object.UnstructuredSetToObjMetadataSet(append(applyObjs, pruneObjs...))
216+
allIDs := object.UnstructuredSetToObjMetadataSet(append(applyObjs, pruneObjs...))
217217
statusWatcher := a.statusWatcher
218218
// Disable watcher for dry runs
219219
if opts.DryRunStrategy.ClientOrServerDryRun() {
220220
statusWatcher = watcher.BlindStatusWatcher{}
221221
}
222-
runner := taskrunner.NewTaskStatusRunner(allIds, statusWatcher)
222+
runner := taskrunner.NewTaskStatusRunner(allIDs, statusWatcher)
223223
klog.V(4).Infoln("applier running TaskStatusRunner...")
224224
err = runner.Run(ctx, taskContext, taskQueue.ToChannel(), taskrunner.Options{
225225
EmitStatusEvents: options.EmitStatusEvents,

pkg/apply/destroyer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ func (d *Destroyer) Run(ctx context.Context, invInfo inventory.Info, options Des
176176
}
177177
// Create a new TaskStatusRunner to execute the taskQueue.
178178
klog.V(4).Infoln("destroyer building TaskStatusRunner...")
179-
deleteIds := object.UnstructuredSetToObjMetadataSet(deleteObjs)
179+
deleteIDs := object.UnstructuredSetToObjMetadataSet(deleteObjs)
180180
statusWatcher := d.statusWatcher
181181
// Disable watcher for dry runs
182182
if opts.DryRunStrategy.ClientOrServerDryRun() {
183183
statusWatcher = watcher.BlindStatusWatcher{}
184184
}
185-
runner := taskrunner.NewTaskStatusRunner(deleteIds, statusWatcher)
185+
runner := taskrunner.NewTaskStatusRunner(deleteIDs, statusWatcher)
186186
klog.V(4).Infoln("destroyer running TaskStatusRunner...")
187187
err = runner.Run(ctx, taskContext, taskQueue.ToChannel(), taskrunner.Options{
188188
EmitStatusEvents: options.EmitStatusEvents,

pkg/apply/prune/prune_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,9 @@ func TestPrune(t *testing.T) {
574574
for _, obj := range tc.clusterObjs {
575575
clusterObjs = append(clusterObjs, obj)
576576
}
577-
pruneIds := object.UnstructuredSetToObjMetadataSet(tc.pruneObjs)
577+
pruneIDs := object.UnstructuredSetToObjMetadataSet(tc.pruneObjs)
578578
po := Pruner{
579-
InvClient: inventory.NewFakeClient(pruneIds),
579+
InvClient: inventory.NewFakeClient(pruneIDs),
580580
Client: fake.NewSimpleDynamicClient(scheme.Scheme, clusterObjs...),
581581
Mapper: testrestmapper.TestOnlyStaticRESTMapper(scheme.Scheme,
582582
scheme.Scheme.PrioritizedVersionsAllGroups()...),
@@ -620,21 +620,21 @@ func TestPrune(t *testing.T) {
620620
for _, id := range tc.expectedFailed {
621621
assert.Truef(t, im.IsFailedDelete(id), "Prune() should mark object as failed: %s", id)
622622
}
623-
for _, id := range pruneIds.Diff(tc.expectedFailed) {
623+
for _, id := range pruneIDs.Diff(tc.expectedFailed) {
624624
assert.Falsef(t, im.IsFailedDelete(id), "Prune() should NOT mark object as failed: %s", id)
625625
}
626626
// validate record of skipped prunes
627627
for _, id := range tc.expectedSkipped {
628628
assert.Truef(t, im.IsSkippedDelete(id), "Prune() should mark object as skipped: %s", id)
629629
}
630-
for _, id := range pruneIds.Diff(tc.expectedSkipped) {
630+
for _, id := range pruneIDs.Diff(tc.expectedSkipped) {
631631
assert.Falsef(t, im.IsSkippedDelete(id), "Prune() should NOT mark object as skipped: %s", id)
632632
}
633633
// validate record of abandoned objects
634634
for _, id := range tc.expectedAbandoned {
635635
assert.Truef(t, taskContext.IsAbandonedObject(id), "Prune() should mark object as abandoned: %s", id)
636636
}
637-
for _, id := range pruneIds.Diff(tc.expectedAbandoned) {
637+
for _, id := range pruneIDs.Diff(tc.expectedAbandoned) {
638638
assert.Falsef(t, taskContext.IsAbandonedObject(id), "Prune() should NOT mark object as abandoned: %s", id)
639639
}
640640
})
@@ -761,9 +761,9 @@ func TestPruneWithErrors(t *testing.T) {
761761
}
762762
for name, tc := range tests {
763763
t.Run(name, func(t *testing.T) {
764-
pruneIds := object.UnstructuredSetToObjMetadataSet(tc.pruneObjs)
764+
pruneIDs := object.UnstructuredSetToObjMetadataSet(tc.pruneObjs)
765765
po := Pruner{
766-
InvClient: inventory.NewFakeClient(pruneIds),
766+
InvClient: inventory.NewFakeClient(pruneIDs),
767767
// Set up the fake dynamic client to recognize all objects, and the RESTMapper.
768768
Client: &fakeDynamicClient{
769769
resourceInterface: &failureNamespaceClient{},
@@ -867,10 +867,10 @@ func TestGetPruneObjs(t *testing.T) {
867867
if len(tc.expectedObjs) != len(actualObjs) {
868868
t.Fatalf("expected %d prune objs, got %d", len(tc.expectedObjs), len(actualObjs))
869869
}
870-
actualIds := object.UnstructuredSetToObjMetadataSet(actualObjs)
871-
expectedIds := object.UnstructuredSetToObjMetadataSet(tc.expectedObjs)
872-
if !object.ObjMetadataSetEquals(expectedIds, actualIds) {
873-
t.Errorf("expected prune objects (%v), got (%v)", expectedIds, actualIds)
870+
actualIDs := object.UnstructuredSetToObjMetadataSet(actualObjs)
871+
expectedIDs := object.UnstructuredSetToObjMetadataSet(tc.expectedObjs)
872+
if !object.ObjMetadataSetEquals(expectedIDs, actualIDs) {
873+
t.Errorf("expected prune objects (%v), got (%v)", expectedIDs, actualIDs)
874874
}
875875
})
876876
}

pkg/apply/solver/solver.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ func (t *TaskQueueBuilder) Build(taskContext *taskrunner.TaskContext, o Options)
182182
t.newApplyTask(applySet, t.ApplyFilters, t.ApplyMutators, o))
183183
// dry-run skips wait tasks
184184
if !o.DryRunStrategy.ClientOrServerDryRun() {
185-
applyIds := object.UnstructuredSetToObjMetadataSet(applySet)
185+
applyIDs := object.UnstructuredSetToObjMetadataSet(applySet)
186186
tasks = append(tasks,
187-
t.newWaitTask(applyIds, taskrunner.AllCurrent, o.ReconcileTimeout))
187+
t.newWaitTask(applyIDs, taskrunner.AllCurrent, o.ReconcileTimeout))
188188
}
189189
}
190190
}
@@ -206,14 +206,14 @@ func (t *TaskQueueBuilder) Build(taskContext *taskrunner.TaskContext, o Options)
206206
t.newPruneTask(pruneSet, t.PruneFilters, o))
207207
// dry-run skips wait tasks
208208
if !o.DryRunStrategy.ClientOrServerDryRun() {
209-
pruneIds := object.UnstructuredSetToObjMetadataSet(pruneSet)
209+
pruneIDs := object.UnstructuredSetToObjMetadataSet(pruneSet)
210210
tasks = append(tasks,
211-
t.newWaitTask(pruneIds, taskrunner.AllNotFound, o.PruneTimeout))
211+
t.newWaitTask(pruneIDs, taskrunner.AllNotFound, o.PruneTimeout))
212212
}
213213
}
214214
}
215215

216-
prevInvIds, _ := t.InvClient.GetClusterObjs(t.invInfo)
216+
prevInvIDs, _ := t.InvClient.GetClusterObjs(t.invInfo)
217217
klog.V(2).Infoln("adding delete/update inventory task")
218218
var taskName string
219219
if o.Destroy {
@@ -225,7 +225,7 @@ func (t *TaskQueueBuilder) Build(taskContext *taskrunner.TaskContext, o Options)
225225
TaskName: taskName,
226226
InvClient: t.InvClient,
227227
InvInfo: t.invInfo,
228-
PrevInventory: prevInvIds,
228+
PrevInventory: prevInvIDs,
229229
DryRun: o.DryRunStrategy,
230230
Destroy: o.Destroy,
231231
})
@@ -257,13 +257,13 @@ func (t *TaskQueueBuilder) newApplyTask(applyObjs object.UnstructuredSet,
257257

258258
// AppendWaitTask appends a task to wait on the passed objects to the task queue.
259259
// Returns a pointer to the Builder to chain function calls.
260-
func (t *TaskQueueBuilder) newWaitTask(waitIds object.ObjMetadataSet, condition taskrunner.Condition,
260+
func (t *TaskQueueBuilder) newWaitTask(waitIDs object.ObjMetadataSet, condition taskrunner.Condition,
261261
waitTimeout time.Duration) taskrunner.Task {
262-
waitIds = t.Collector.FilterInvalidIds(waitIds)
262+
waitIDs = t.Collector.FilterInvalidIds(waitIDs)
263263
klog.V(2).Infoln("adding wait task")
264264
task := taskrunner.NewWaitTask(
265265
fmt.Sprintf("wait-%d", t.waitCounter),
266-
waitIds,
266+
waitIDs,
267267
condition,
268268
waitTimeout,
269269
t.Mapper,

pkg/apply/solver/solver_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,8 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
808808
}
809809
}
810810

811-
applyIds := object.UnstructuredSetToObjMetadataSet(tc.applyObjs)
812-
fakeInvClient := inventory.NewFakeClient(applyIds)
811+
applyIDs := object.UnstructuredSetToObjMetadataSet(tc.applyObjs)
812+
fakeInvClient := inventory.NewFakeClient(applyIDs)
813813
vCollector := &validation.Collector{}
814814
tqb := TaskQueueBuilder{
815815
Pruner: pruner,
@@ -1484,8 +1484,8 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
14841484
}
14851485
}
14861486

1487-
pruneIds := object.UnstructuredSetToObjMetadataSet(tc.pruneObjs)
1488-
fakeInvClient := inventory.NewFakeClient(pruneIds)
1487+
pruneIDs := object.UnstructuredSetToObjMetadataSet(tc.pruneObjs)
1488+
fakeInvClient := inventory.NewFakeClient(pruneIDs)
14891489
vCollector := &validation.Collector{}
14901490
tqb := TaskQueueBuilder{
14911491
Pruner: pruner,

pkg/apply/task/apply_task_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -492,22 +492,22 @@ func TestApplyTaskWithError(t *testing.T) {
492492
assert.Equal(t, tc.expectedEvents[i].ApplyEvent.Error.Error(), e.ApplyEvent.Error.Error())
493493
}
494494

495-
applyIds := object.UnstructuredSetToObjMetadataSet(tc.objs)
495+
applyIDs := object.UnstructuredSetToObjMetadataSet(tc.objs)
496496

497497
im := taskContext.InventoryManager()
498498

499499
// validate record of failed prunes
500500
for _, id := range tc.expectedFailed {
501501
assert.Truef(t, im.IsFailedApply(id), "ApplyTask should mark object as failed: %s", id)
502502
}
503-
for _, id := range applyIds.Diff(tc.expectedFailed) {
503+
for _, id := range applyIDs.Diff(tc.expectedFailed) {
504504
assert.Falsef(t, im.IsFailedApply(id), "ApplyTask should NOT mark object as failed: %s", id)
505505
}
506506
// validate record of skipped prunes
507507
for _, id := range tc.expectedSkipped {
508508
assert.Truef(t, im.IsSkippedApply(id), "ApplyTask should mark object as skipped: %s", id)
509509
}
510-
for _, id := range applyIds.Diff(tc.expectedSkipped) {
510+
for _, id := range applyIDs.Diff(tc.expectedSkipped) {
511511
assert.Falsef(t, im.IsSkippedApply(id), "ApplyTask should NOT mark object as skipped: %s", id)
512512
}
513513
})

pkg/apply/task/inv_add_task_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ func TestInvAddTask(t *testing.T) {
158158
if taskName != task.Name() {
159159
t.Errorf("expected task name (%s), got (%s)", taskName, task.Name())
160160
}
161-
applyIds := object.UnstructuredSetToObjMetadataSet(tc.applyObjs)
162-
if !task.Identifiers().Equal(applyIds) {
163-
t.Errorf("expected task ids (%s), got (%s)", applyIds, task.Identifiers())
161+
applyIDs := object.UnstructuredSetToObjMetadataSet(tc.applyObjs)
162+
if !task.Identifiers().Equal(applyIDs) {
163+
t.Errorf("expected task ids (%s), got (%s)", applyIDs, task.Identifiers())
164164
}
165165
task.Start(context)
166166
result := <-context.TaskChannel()

pkg/apply/taskrunner/task.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type WaitTask struct {
5656
// TaskName allows providing a name for the task.
5757
TaskName string
5858
// Ids is the full list of resources that we are waiting for.
59-
Ids object.ObjMetadataSet
59+
Ids object.ObjMetadataSet //nolint:revive
6060
// Condition defines the status we want all resources to reach
6161
Condition Condition
6262
// Timeout defines how long we are willing to wait for the condition

pkg/inventory/inventory-client.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ func NewClient(factory cmdutil.Factory,
9696
// objects if an inventory object does not exist. Returns an error if one
9797
// occurred.
9898
func (cic *ClusterClient) Merge(localInv Info, objs object.ObjMetadataSet, dryRun common.DryRunStrategy) (object.ObjMetadataSet, error) {
99-
pruneIds := object.ObjMetadataSet{}
99+
pruneIDs := object.ObjMetadataSet{}
100100
invObj := cic.invToUnstructuredFunc(localInv)
101101
clusterInv, err := cic.getClusterInventoryInfo(localInv)
102102
if err != nil {
103-
return pruneIds, err
103+
return pruneIDs, err
104104
}
105105

106106
// Inventory does not exist on the cluster.
@@ -128,34 +128,34 @@ func (cic *ClusterClient) Merge(localInv Info, objs object.ObjMetadataSet, dryRu
128128
// Update existing cluster inventory with merged union of objects
129129
clusterObjs, err := cic.GetClusterObjs(localInv)
130130
if err != nil {
131-
return pruneIds, err
131+
return pruneIDs, err
132132
}
133-
pruneIds = clusterObjs.Diff(objs)
133+
pruneIDs = clusterObjs.Diff(objs)
134134
unionObjs := clusterObjs.Union(objs)
135135
var status []actuation.ObjectStatus
136136
if cic.statusPolicy == StatusPolicyAll {
137-
status = getObjStatus(pruneIds, unionObjs)
137+
status = getObjStatus(pruneIDs, unionObjs)
138138
}
139-
klog.V(4).Infof("num objects to prune: %d", len(pruneIds))
139+
klog.V(4).Infof("num objects to prune: %d", len(pruneIDs))
140140
klog.V(4).Infof("num merged objects to store in inventory: %d", len(unionObjs))
141141
wrappedInv := cic.InventoryFactoryFunc(clusterInv)
142142
if err = wrappedInv.Store(unionObjs, status); err != nil {
143-
return pruneIds, err
143+
return pruneIDs, err
144144
}
145145

146146
// Update not required when all objects in inventory are the same and
147147
// status does not need to be updated. If status is stored, always update the
148148
// inventory to store the latest status.
149149
if objs.Equal(clusterObjs) && cic.statusPolicy == StatusPolicyNone {
150-
return pruneIds, nil
150+
return pruneIDs, nil
151151
}
152152

153153
if dryRun.ClientOrServerDryRun() {
154154
klog.V(4).Infof("dry-run create inventory object: not created")
155-
return pruneIds, nil
155+
return pruneIDs, nil
156156
}
157157
err = wrappedInv.Apply(cic.dc, cic.mapper, cic.statusPolicy)
158-
return pruneIds, err
158+
return pruneIDs, err
159159
}
160160

161161
// Replace stores the passed objects in the cluster inventory object, or
@@ -451,9 +451,9 @@ func (cic *ClusterClient) getMapping(obj *unstructured.Unstructured) (*meta.REST
451451

452452
// getObjStatus returns the list of object status
453453
// at the beginning of an apply process.
454-
func getObjStatus(pruneIds, unionIds []object.ObjMetadata) []actuation.ObjectStatus {
454+
func getObjStatus(pruneIDs, unionIDs []object.ObjMetadata) []actuation.ObjectStatus {
455455
status := []actuation.ObjectStatus{}
456-
for _, obj := range unionIds {
456+
for _, obj := range unionIDs {
457457
status = append(status,
458458
actuation.ObjectStatus{
459459
ObjectReference: ObjectReferenceFromObjMetadata(obj),
@@ -462,7 +462,7 @@ func getObjStatus(pruneIds, unionIds []object.ObjMetadata) []actuation.ObjectSta
462462
Reconcile: actuation.ReconcilePending,
463463
})
464464
}
465-
for _, obj := range pruneIds {
465+
for _, obj := range pruneIDs {
466466
status = append(status,
467467
actuation.ObjectStatus{
468468
ObjectReference: ObjectReferenceFromObjMetadata(obj),

pkg/inventory/inventory-client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ func TestReplace(t *testing.T) {
409409
t.Fatalf("unexpected error received: %s", err)
410410
}
411411
if diff := cmp.Diff(data, tc.data); diff != "" {
412-
t.Fatalf(diff)
412+
t.Fatal(diff)
413413
}
414414
})
415415
}

pkg/inventory/inventorycm_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestBuildObjMap(t *testing.T) {
6565
t.Run(name, func(t *testing.T) {
6666
actual := buildObjMap(tc.objSet, tc.objStatus)
6767
if diff := cmp.Diff(actual, tc.expected); diff != "" {
68-
t.Errorf(diff)
68+
t.Error(diff)
6969
}
7070
})
7171
}

pkg/kstatus/polling/clusterreader/caching_reader_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,9 @@ func (f *fakeReader) List(_ context.Context, list client.ObjectList, opts ...cli
388388
}
389389
}
390390
end := start + listOpts.Limit
391-
max := int64(len(results))
392-
if end > max {
393-
end = max
391+
maxResult := int64(len(results))
392+
if end > maxResult {
393+
end = maxResult
394394
} else {
395395
// set continue if more results are available
396396
uList.SetContinue(strconv.FormatInt(end, 10))

pkg/object/unstructured_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1313
"k8s.io/apimachinery/pkg/runtime/schema"
1414
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
15-
. "sigs.k8s.io/cli-utils/pkg/object"
15+
. "sigs.k8s.io/cli-utils/pkg/object" //nolint:revive
1616
"sigs.k8s.io/cli-utils/pkg/testutil"
1717
)
1818

0 commit comments

Comments
 (0)