Skip to content

Commit 42f0466

Browse files
refactor: migrate to golangci-lint v2 (#798)
* refactor: migrate to golangci-lint v2 Signed-off-by: Bruno Schaatsbergen <[email protected]> * refactor: fix staticcheck complaints (type inference and embedded fields) Signed-off-by: Bruno Schaatsbergen <[email protected]> * fix: disable QF1008 This reduces noise from the staticcheck linter, preventing it from discouraging the use of embedded struct fields. Signed-off-by: Bruno Schaatsbergen <[email protected]> --------- Signed-off-by: Bruno Schaatsbergen <[email protected]>
1 parent 035245e commit 42f0466

File tree

9 files changed

+54
-46
lines changed

9 files changed

+54
-46
lines changed

.github/workflows/golangci-lint.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ jobs:
2525
with:
2626
go-version: stable
2727
- name: golangci-lint
28-
uses: golangci/golangci-lint-action@v6
28+
uses: golangci/golangci-lint-action@0a35821d5c230e903fcfe077583637dea1b27b47 # v9
2929
with:
30-
args: --timeout=5m
31-
version: v1.64
30+
version: v2.6
3231
only-new-issues: true

.golangci.yml

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,49 @@
1+
version: "2"
12
run:
2-
timeout: 5m
33
allow-parallel-runners: true
4-
5-
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
11-
exclude-rules:
12-
- path: "api/*"
13-
linters:
14-
- lll
15-
- path: "pkg/*"
16-
linters:
17-
- dupl
18-
- lll
194
linters:
20-
disable-all: true
5+
default: none
216
enable:
7+
- copyloopvar
228
- dupl
239
- errcheck
24-
- copyloopvar
2510
- goconst
2611
- gocyclo
27-
- gofmt
28-
- goimports
29-
- gosimple
3012
- govet
3113
- ineffassign
3214
- lll
3315
- misspell
3416
- nakedret
3517
- prealloc
3618
- staticcheck
37-
- typecheck
3819
- unconvert
3920
- unparam
4021
- unused
22+
exclusions:
23+
generated: lax
24+
rules:
25+
- linters:
26+
- lll
27+
path: api/*
28+
- linters:
29+
- dupl
30+
- lll
31+
path: pkg/*
32+
paths:
33+
- third_party$
34+
- builtin$
35+
- examples$
36+
settings:
37+
staticcheck:
38+
checks:
39+
- -QF1008
40+
formatters:
41+
enable:
42+
- gofmt
43+
- goimports
44+
exclusions:
45+
generated: lax
46+
paths:
47+
- third_party$
48+
- builtin$
49+
- examples$

pkg/apis/condition_set.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func findMostUnhealthy(deps []v1alpha1.Condition) (v1alpha1.Condition, bool) {
269269
return true // non-nil comes before nil (opposite of Before)
270270
}
271271

272-
return deps[i].LastTransitionTime.Time.After(deps[j].LastTransitionTime.Time)
272+
return deps[i].LastTransitionTime.After(deps[j].LastTransitionTime.Time)
273273
})
274274

275275
// First check the conditions with Status == False.
@@ -316,7 +316,7 @@ func (c ConditionSet) findUnhealthyDependents() []v1alpha1.Condition {
316316
return true // non-nil comes before nil (opposite of Before)
317317
}
318318

319-
return deps[i].LastTransitionTime.Time.After(deps[j].LastTransitionTime.Time)
319+
return deps[i].LastTransitionTime.After(deps[j].LastTransitionTime.Time)
320320
})
321321
return deps
322322
}

pkg/applyset/applyset_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func TestApplySet_Prune(t *testing.T) {
310310

311311
// This CM will be pruned
312312
pruneCM := configMap("prune-cm", "default")
313-
pruneCM.Unstructured.SetLabels(map[string]string{
313+
pruneCM.SetLabels(map[string]string{
314314
ApplysetPartOfLabel: "applyset-wHf5Gity0G0nPN34KuNBIBBEOu2H9ED2KqsblMPFygM-v1",
315315
})
316316
aset, dynamicClient := newTestApplySet(t, parent, pruneCM)
@@ -437,11 +437,11 @@ func TestApplySet_PruneMultiNamespace(t *testing.T) {
437437

438438
// These CMs will be pruned
439439
pruneCM1 := configMap("prune-cm", "ns1")
440-
pruneCM1.Unstructured.SetLabels(map[string]string{
440+
pruneCM1.SetLabels(map[string]string{
441441
ApplysetPartOfLabel: "applyset-wHf5Gity0G0nPN34KuNBIBBEOu2H9ED2KqsblMPFygM-v1",
442442
})
443443
pruneCM2 := configMap("prune-cm", "ns2")
444-
pruneCM2.Unstructured.SetLabels(map[string]string{
444+
pruneCM2.SetLabels(map[string]string{
445445
ApplysetPartOfLabel: "applyset-wHf5Gity0G0nPN34KuNBIBBEOu2H9ED2KqsblMPFygM-v1",
446446
})
447447
aset, dynamicClient := newTestApplySet(t, parent, pruneCM1, pruneCM2)
@@ -501,7 +501,7 @@ func TestApplySet_PruneMultiNamespace(t *testing.T) {
501501
return true, &parentPatch, nil
502502
})
503503

504-
var pruned int = 0
504+
var pruned = 0
505505
dynamicClient.PrependReactor("delete", "configmaps", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
506506
deleteAction := action.(k8stesting.DeleteAction)
507507
assert.Equal(t, "prune-cm", deleteAction.GetName())
@@ -525,11 +525,11 @@ func TestApplySet_PruneOldNamespace(t *testing.T) {
525525

526526
// CM in old namespace should be pruned
527527
pruneCM1 := configMap("prune-cm", "oldns1")
528-
pruneCM1.Unstructured.SetLabels(map[string]string{
528+
pruneCM1.SetLabels(map[string]string{
529529
ApplysetPartOfLabel: "applyset-wHf5Gity0G0nPN34KuNBIBBEOu2H9ED2KqsblMPFygM-v1",
530530
})
531531
pruneCM2 := configMap("prune-cm", "ns2")
532-
pruneCM2.Unstructured.SetLabels(map[string]string{
532+
pruneCM2.SetLabels(map[string]string{
533533
ApplysetPartOfLabel: "applyset-wHf5Gity0G0nPN34KuNBIBBEOu2H9ED2KqsblMPFygM-v1",
534534
})
535535
aset, dynamicClient := newTestApplySet(t, parent, pruneCM1, pruneCM2)
@@ -589,7 +589,7 @@ func TestApplySet_PruneOldNamespace(t *testing.T) {
589589
return true, &parentPatch, nil
590590
})
591591

592-
var pruned int = 0
592+
var pruned = 0
593593
dynamicClient.PrependReactor("delete", "configmaps", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
594594
deleteAction := action.(k8stesting.DeleteAction)
595595
assert.Equal(t, "prune-cm", deleteAction.GetName())
@@ -613,7 +613,7 @@ func TestApplySet_PruneOldGVKs(t *testing.T) {
613613

614614
// Foo type should be pruned
615615
pruneFoo := foo("prune-foo", "ns1")
616-
pruneFoo.Unstructured.SetLabels(map[string]string{
616+
pruneFoo.SetLabels(map[string]string{
617617
ApplysetPartOfLabel: "applyset-wHf5Gity0G0nPN34KuNBIBBEOu2H9ED2KqsblMPFygM-v1",
618618
})
619619
aset, dynamicClient := newTestApplySet(t, parent, pruneFoo)
@@ -659,7 +659,7 @@ func TestApplySet_PruneOldGVKs(t *testing.T) {
659659
return true, &parentPatch, nil
660660
})
661661

662-
var pruned int = 0
662+
var pruned = 0
663663
dynamicClient.PrependReactor("delete", "foos", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
664664
deleteAction := action.(k8stesting.DeleteAction)
665665
assert.Equal(t, "prune-foo", deleteAction.GetName())

pkg/dynamiccontroller/dynamic_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ func TestInstanceUpdatePolicy(t *testing.T) {
364364
assert.Equal(t, dc.queue.Len(), 2)
365365
for dc.queue.Len() > 0 {
366366
name, _ := dc.queue.Get()
367-
_, ok := objs[name.NamespacedName.String()]
367+
_, ok := objs[name.String()]
368368
assert.True(t, ok)
369369
}
370370
}

pkg/graph/parser/parser.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func validateSchema(schema *spec.Schema, path string) error {
196196

197197
func parseObject(field map[string]interface{}, schema *spec.Schema, path string, expectedTypes []string) ([]variable.FieldDescriptor, error) {
198198
// Look for vendor schema extensions first
199-
if len(schema.VendorExtensible.Extensions) > 0 {
199+
if len(schema.Extensions) > 0 {
200200
// If the schema has the x-kubernetes-preserve-unknown-fields extension, we need to parse
201201
// this field using the schemaless parser. This allows us to extract CEL expressions from
202202
// fields that don't have a strict schema definition, while still preserving any unknown
@@ -233,7 +233,7 @@ func parseObject(field map[string]interface{}, schema *spec.Schema, path string,
233233

234234
func parseArray(field []interface{}, schema *spec.Schema, path string, expectedTypes []string) ([]variable.FieldDescriptor, error) {
235235
// Look for vendor schema extensions first
236-
if len(schema.VendorExtensible.Extensions) > 0 {
236+
if len(schema.Extensions) > 0 {
237237
// If the schema has the x-kubernetes-preserve-unknown-fields extension, we need to parse
238238
// this field using the schemaless parser. This allows us to extract CEL expressions from
239239
// fields that don't have a strict schema definition, while still preserving any unknown
@@ -419,7 +419,7 @@ func joinPathAndFieldName(path, fieldName string) string {
419419

420420
// hasStructuralSchemaMarkerEnabled checks if a schema has a specific marker enabled.
421421
func hasStructuralSchemaMarkerEnabled(schema *spec.Schema, marker string) bool {
422-
if ext, ok := schema.VendorExtensible.Extensions[marker]; ok {
422+
if ext, ok := schema.Extensions[marker]; ok {
423423
if enabled, ok := ext.(bool); ok && enabled {
424424
return true
425425
}

pkg/graph/schema/conversion_cel_type_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ func TestExtractSchemaFromDeclTypeWithCycleDetection(t *testing.T) {
221221
name: "no cycle - simple object",
222222
setupDeclType: func() *apiservercel.DeclType {
223223
schema := &spec.Schema{}
224-
schema.SchemaProps.Type = []string{"object"}
225-
schema.SchemaProps.Properties = map[string]spec.Schema{
224+
schema.Type = []string{"object"}
225+
schema.Properties = map[string]spec.Schema{
226226
"name": {SchemaProps: spec.SchemaProps{Type: []string{"string"}}},
227227
"value": {SchemaProps: spec.SchemaProps{Type: []string{"integer"}}},
228228
}
@@ -249,8 +249,8 @@ func TestExtractSchemaFromDeclTypeWithCycleDetection(t *testing.T) {
249249
name: "cycle detected - error out",
250250
setupDeclType: func() *apiservercel.DeclType {
251251
schema := &spec.Schema{}
252-
schema.SchemaProps.Type = []string{"object"}
253-
schema.SchemaProps.Properties = map[string]spec.Schema{
252+
schema.Type = []string{"object"}
253+
schema.Properties = map[string]spec.Schema{
254254
"name": {SchemaProps: spec.SchemaProps{Type: []string{"string"}}},
255255
}
256256
return openapi.SchemaDeclType(schema, false).MaybeAssignTypeName("CyclicType")

pkg/graph/schema/conversion_schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func ConvertJSONSchemaPropsToSpecSchema(props *extv1.JSONSchemaProps) (*spec.Sch
7373
}
7474

7575
if len(props.Type) > 0 {
76-
schema.SchemaProps.Type = []string{props.Type}
76+
schema.Type = []string{props.Type}
7777
}
7878

7979
if props.Items != nil {

pkg/runtime/resolver/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (r *Resolver) resolveField(field variable.FieldDescriptor) ResolutionResult
130130
result.Error = fmt.Errorf("no data provided for expression: %s", expr)
131131
return result
132132
}
133-
replaced = strings.Replace(replaced, "${"+expr+"}", fmt.Sprintf("%v", replacement), -1)
133+
replaced = strings.ReplaceAll(replaced, "${"+expr+"}", fmt.Sprintf("%v", replacement))
134134
}
135135

136136
err = r.setValueAtPath(field.Path, replaced)

0 commit comments

Comments
 (0)