Skip to content

Commit 2037b8f

Browse files
committed
chore: Migrate to golangci-lint v2
1 parent b528c28 commit 2037b8f

File tree

16 files changed

+51
-44
lines changed

16 files changed

+51
-44
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ env:
2121
E2E_SETUP_KUBECTL: yes
2222
SUDO: sudo
2323
GO_VERSION: "^1.24"
24-
GOLANGCI_LINT_VERSION: "v1.64.6"
24+
GOLANGCI_LINT_VERSION: "v2.0.2"
2525

2626
jobs:
2727
ci-go-lint:

.golangci.yml

+33-26
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
run:
2-
timeout: 10m
3-
1+
version: "2"
42
linters:
5-
disable-all: true
3+
default: none
64
enable:
75
- gocritic
86
- gocyclo
9-
- gofmt
10-
- goimports
117
- gosec
12-
- gosimple
138
- govet
149
- ineffassign
1510
- misspell
@@ -18,22 +13,34 @@ linters:
1813
- staticcheck
1914
- unconvert
2015
- unused
21-
22-
linters-settings:
23-
goimports:
24-
local-prefixes: k8s.io/kube-state-metrics,k8s.io/kube-state-metrics/v2
25-
26-
issues:
27-
exclude-use-default: false
28-
exclude-rules:
29-
# We don't check metrics naming in the tests.
30-
- path: _test\.go
31-
linters:
32-
- promlinter
33-
# TODO(mrueg) Improve error handling
34-
- text: "G104:"
35-
linters:
36-
- gosec
37-
- text: "package-comments:"
38-
linters:
39-
- revive
16+
exclusions:
17+
generated: lax
18+
rules:
19+
- linters:
20+
- promlinter
21+
path: _test\.go
22+
- linters:
23+
- gosec
24+
text: 'G104:'
25+
- linters:
26+
- revive
27+
text: 'package-comments:'
28+
paths:
29+
- third_party$
30+
- builtin$
31+
- examples$
32+
formatters:
33+
enable:
34+
- gofmt
35+
- goimports
36+
settings:
37+
goimports:
38+
local-prefixes:
39+
- k8s.io/kube-state-metrics
40+
- k8s.io/kube-state-metrics/v2
41+
exclusions:
42+
generated: lax
43+
paths:
44+
- third_party$
45+
- builtin$
46+
- examples$

internal/store/clusterrole.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func clusterRoleMetricFamilies(allowAnnotationsList, allowLabelsList []string) [
131131
"",
132132
wrapClusterRoleFunc(func(r *rbacv1.ClusterRole) *metric.Family {
133133
return &metric.Family{
134-
Metrics: resourceVersionMetric(r.ObjectMeta.ResourceVersion),
134+
Metrics: resourceVersionMetric(r.ResourceVersion),
135135
}
136136
}),
137137
),

internal/store/clusterrolebinding.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func clusterRoleBindingMetricFamilies(allowAnnotationsList, allowLabelsList []st
133133
"",
134134
wrapClusterRoleBindingFunc(func(r *rbacv1.ClusterRoleBinding) *metric.Family {
135135
return &metric.Family{
136-
Metrics: resourceVersionMetric(r.ObjectMeta.ResourceVersion),
136+
Metrics: resourceVersionMetric(r.ResourceVersion),
137137
}
138138
}),
139139
),

internal/store/configmap.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func configMapMetricFamilies(allowAnnotationsList, allowLabelsList []string) []g
127127
"",
128128
wrapConfigMapFunc(func(c *v1.ConfigMap) *metric.Family {
129129
return &metric.Family{
130-
Metrics: resourceVersionMetric(c.ObjectMeta.ResourceVersion),
130+
Metrics: resourceVersionMetric(c.ResourceVersion),
131131
}
132132
}),
133133
),

internal/store/cronjob.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
273273
"",
274274
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
275275
return &metric.Family{
276-
Metrics: resourceVersionMetric(j.ObjectMeta.ResourceVersion),
276+
Metrics: resourceVersionMetric(j.ResourceVersion),
277277
}
278278
}),
279279
),
@@ -358,7 +358,7 @@ func getNextScheduledTime(schedule string, lastScheduleTime *metav1.Time, create
358358

359359
sched, err := cron.ParseStandard(schedule)
360360
if err != nil {
361-
return time.Time{}, fmt.Errorf("Failed to parse cron job schedule '%s': %w", schedule, err)
361+
return time.Time{}, fmt.Errorf("failed to parse cron job schedule '%s': %w", schedule, err)
362362
}
363363
if !lastScheduleTime.IsZero() {
364364
return sched.Next(lastScheduleTime.Time), nil

internal/store/daemonset.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func daemonSetMetricFamilies(allowAnnotationsList, allowLabelsList []string) []g
217217
{
218218
LabelKeys: []string{},
219219
LabelValues: []string{},
220-
Value: float64(d.ObjectMeta.Generation),
220+
Value: float64(d.Generation),
221221
},
222222
},
223223
}

internal/store/deployment.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func deploymentMetricFamilies(allowAnnotationsList, allowLabelsList []string) []
277277
return &metric.Family{
278278
Metrics: []*metric.Metric{
279279
{
280-
Value: float64(d.ObjectMeta.Generation),
280+
Value: float64(d.Generation),
281281
},
282282
},
283283
}

internal/store/horizontalpodautoscaler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func createHPAMetaDataGeneration() generator.FamilyGenerator {
134134
return &metric.Family{
135135
Metrics: []*metric.Metric{
136136
{
137-
Value: float64(a.ObjectMeta.Generation),
137+
Value: float64(a.Generation),
138138
},
139139
},
140140
}

internal/store/ingress.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func ingressMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
140140
"",
141141
wrapIngressFunc(func(i *networkingv1.Ingress) *metric.Family {
142142
return &metric.Family{
143-
Metrics: resourceVersionMetric(i.ObjectMeta.ResourceVersion),
143+
Metrics: resourceVersionMetric(i.ResourceVersion),
144144
}
145145
}),
146146
),

pkg/app/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ func resolveCustomResourceConfig(opts *options.Options) (customresourcestate.Con
497497
if file := opts.CustomResourceConfigFile; file != "" {
498498
f, err := os.Open(filepath.Clean(file))
499499
if err != nil {
500-
return nil, fmt.Errorf("Custom Resource State Metrics file could not be opened: %v", err)
500+
return nil, fmt.Errorf("unable to open Custom Resource State Metrics file: %v", err)
501501
}
502502
return yaml.NewDecoder(f), nil
503503
}

pkg/customresourcestate/registry_factory.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func compileCommon(c MetricMeta) (*compiledCommon, error) {
7070
}
7171

7272
func compileFamily(f Generator, resource Resource) (*compiledFamily, error) {
73-
labels := resource.Labels.Merge(f.Labels)
73+
labels := resource.Merge(f.Labels)
7474

7575
if f.Each.Type == metric.Info && !strings.HasSuffix(f.Name, "_info") {
7676
klog.InfoS("Info metric does not have _info suffix", "gvk", resource.GroupVersionKind.String(), "name", f.Name)
@@ -652,7 +652,7 @@ func compilePath(path []string) (out valuePath, _ error) {
652652
// negative index
653653
i += len(s)
654654
}
655-
if !(0 <= i && i < len(s)) {
655+
if i < 0 || i > len(s) {
656656
return fmt.Errorf("list index out of range: %s", part)
657657
}
658658
return s[i]

pkg/sharding/listwatch_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestSharding(t *testing.T) {
4242
totalShards: 2,
4343
}
4444

45-
if !(s1.keep(cm) || s2.keep(cm)) {
45+
if !s1.keep(cm) && !s2.keep(cm) {
4646
t.Fatal("One shard must pick up the object.")
4747
}
4848

pkg/util/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func GVRFromType(resourceName string, expectedType interface{}) (*schema.GroupVe
135135
}
136136
t, err := meta.TypeAccessor(expectedType)
137137
if err != nil {
138-
return nil, fmt.Errorf("Failed to get type accessor for %T: %w", expectedType, err)
138+
return nil, fmt.Errorf("failed to get type accessor for %T: %w", expectedType, err)
139139
}
140140
apiVersion := t.GetAPIVersion()
141141
g, v, found := strings.Cut(apiVersion, "/")

tests/e2e/framework/framework.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (k *KSMClient) IsHealthz() (bool, error) {
118118

119119
func (k *KSMClient) writeMetrics(endpoint *url.URL, w io.Writer) error {
120120
if endpoint == nil {
121-
return errors.New("Endpoint is nil")
121+
return errors.New("endpoint is nil")
122122
}
123123

124124
u := *endpoint
@@ -165,7 +165,7 @@ func (f *Framework) ParseMetrics(metrics func(io.Writer) error) (map[string]*dto
165165
buf := &bytes.Buffer{}
166166
err := metrics(buf)
167167
if err != nil {
168-
return nil, fmt.Errorf("Failed to get metrics: %w", err)
168+
return nil, fmt.Errorf("failed to get metrics: %w", err)
169169
}
170170

171171
parser := &expfmt.TextParser{}

tests/lib/lib_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestAsLibrary(t *testing.T) {
6262
}
6363
m := w.String()
6464

65-
if !strings.Contains(m, service.ObjectMeta.Name) {
65+
if !strings.Contains(m, service.Name) {
6666
t.Fatal("expected string to contain service name")
6767
}
6868
}

0 commit comments

Comments
 (0)