Skip to content

Commit 0c029b6

Browse files
committed
chore: Migrate to golangci-lint v2
1 parent b528c28 commit 0c029b6

28 files changed

+99
-88
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 35 additions & 25 deletions
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,37 @@ 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-
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$
2632
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
33+
max-issues-per-linter: 0
34+
max-same-issues: 0
35+
formatters:
36+
enable:
37+
- gofmt
38+
- goimports
39+
settings:
40+
goimports:
41+
local-prefixes:
42+
- k8s.io/kube-state-metrics
43+
- k8s.io/kube-state-metrics/v2
44+
exclusions:
45+
generated: lax
46+
paths:
47+
- third_party$
48+
- builtin$
49+
- examples$

internal/store/clusterrole.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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
),

internal/store/mutatingwebhookconfiguration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var (
7878
"",
7979
wrapMutatingWebhookConfigurationFunc(func(mwc *admissionregistrationv1.MutatingWebhookConfiguration) *metric.Family {
8080
return &metric.Family{
81-
Metrics: resourceVersionMetric(mwc.ObjectMeta.ResourceVersion),
81+
Metrics: resourceVersionMetric(mwc.ResourceVersion),
8282
}
8383
}),
8484
),

internal/store/persistentvolume.go

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -243,50 +243,50 @@ func createPersistentVolumeInfo() generator.FamilyGenerator {
243243
)
244244

245245
switch {
246-
case p.Spec.PersistentVolumeSource.GCEPersistentDisk != nil:
247-
gcePDDiskName = p.Spec.PersistentVolumeSource.GCEPersistentDisk.PDName
248-
case p.Spec.PersistentVolumeSource.AWSElasticBlockStore != nil:
249-
ebsVolumeID = p.Spec.PersistentVolumeSource.AWSElasticBlockStore.VolumeID
250-
case p.Spec.PersistentVolumeSource.AzureDisk != nil:
251-
azureDiskName = p.Spec.PersistentVolumeSource.AzureDisk.DiskName
252-
case p.Spec.PersistentVolumeSource.FC != nil:
253-
if p.Spec.PersistentVolumeSource.FC.Lun != nil {
254-
fcLun = strconv.FormatInt(int64(*p.Spec.PersistentVolumeSource.FC.Lun), 10)
246+
case p.Spec.GCEPersistentDisk != nil:
247+
gcePDDiskName = p.Spec.GCEPersistentDisk.PDName
248+
case p.Spec.AWSElasticBlockStore != nil:
249+
ebsVolumeID = p.Spec.AWSElasticBlockStore.VolumeID
250+
case p.Spec.AzureDisk != nil:
251+
azureDiskName = p.Spec.AzureDisk.DiskName
252+
case p.Spec.FC != nil:
253+
if p.Spec.FC.Lun != nil {
254+
fcLun = strconv.FormatInt(int64(*p.Spec.FC.Lun), 10)
255255
}
256-
for _, wwn := range p.Spec.PersistentVolumeSource.FC.TargetWWNs {
256+
for _, wwn := range p.Spec.FC.TargetWWNs {
257257
if len(fcTargetWWNs) != 0 {
258258
fcTargetWWNs += ","
259259
}
260260
fcTargetWWNs += wwn
261261
}
262-
for _, wwid := range p.Spec.PersistentVolumeSource.FC.WWIDs {
262+
for _, wwid := range p.Spec.FC.WWIDs {
263263
if len(fcWWIDs) != 0 {
264264
fcWWIDs += ","
265265
}
266266
fcWWIDs += wwid
267267
}
268-
case p.Spec.PersistentVolumeSource.ISCSI != nil:
269-
iscsiTargetPortal = p.Spec.PersistentVolumeSource.ISCSI.TargetPortal
270-
iscsiIQN = p.Spec.PersistentVolumeSource.ISCSI.IQN
271-
iscsiLun = strconv.FormatInt(int64(p.Spec.PersistentVolumeSource.ISCSI.Lun), 10)
272-
if p.Spec.PersistentVolumeSource.ISCSI.InitiatorName != nil {
273-
iscsiInitiatorName = *p.Spec.PersistentVolumeSource.ISCSI.InitiatorName
268+
case p.Spec.ISCSI != nil:
269+
iscsiTargetPortal = p.Spec.ISCSI.TargetPortal
270+
iscsiIQN = p.Spec.ISCSI.IQN
271+
iscsiLun = strconv.FormatInt(int64(p.Spec.ISCSI.Lun), 10)
272+
if p.Spec.ISCSI.InitiatorName != nil {
273+
iscsiInitiatorName = *p.Spec.ISCSI.InitiatorName
274274
}
275-
case p.Spec.PersistentVolumeSource.NFS != nil:
276-
nfsServer = p.Spec.PersistentVolumeSource.NFS.Server
277-
nfsPath = p.Spec.PersistentVolumeSource.NFS.Path
278-
case p.Spec.PersistentVolumeSource.CSI != nil:
279-
csiDriver = p.Spec.PersistentVolumeSource.CSI.Driver
280-
csiVolumeHandle = p.Spec.PersistentVolumeSource.CSI.VolumeHandle
281-
case p.Spec.PersistentVolumeSource.Local != nil:
282-
localPath = p.Spec.PersistentVolumeSource.Local.Path
283-
if p.Spec.PersistentVolumeSource.Local.FSType != nil {
284-
localFS = *p.Spec.PersistentVolumeSource.Local.FSType
275+
case p.Spec.NFS != nil:
276+
nfsServer = p.Spec.NFS.Server
277+
nfsPath = p.Spec.NFS.Path
278+
case p.Spec.CSI != nil:
279+
csiDriver = p.Spec.CSI.Driver
280+
csiVolumeHandle = p.Spec.CSI.VolumeHandle
281+
case p.Spec.Local != nil:
282+
localPath = p.Spec.Local.Path
283+
if p.Spec.Local.FSType != nil {
284+
localFS = *p.Spec.Local.FSType
285285
}
286-
case p.Spec.PersistentVolumeSource.HostPath != nil:
287-
hostPath = p.Spec.PersistentVolumeSource.HostPath.Path
288-
if p.Spec.PersistentVolumeSource.HostPath.Type != nil {
289-
hostPathType = string(*p.Spec.PersistentVolumeSource.HostPath.Type)
286+
case p.Spec.HostPath != nil:
287+
hostPath = p.Spec.HostPath.Path
288+
if p.Spec.HostPath.Type != nil {
289+
hostPathType = string(*p.Spec.HostPath.Type)
290290
}
291291
}
292292

@@ -430,11 +430,12 @@ func createPersistentVolumeCSIAttributes() generator.FamilyGenerator {
430430
}
431431

432432
var csiMounter, csiMapOptions string
433-
for k, v := range p.Spec.PersistentVolumeSource.CSI.VolumeAttributes {
433+
for k, v := range p.Spec.CSI.VolumeAttributes {
434434
// storage attributes handled by external CEPH CSI driver
435-
if k == "mapOptions" {
435+
switch k {
436+
case "mapOptions":
436437
csiMapOptions = v
437-
} else if k == "mounter" {
438+
case "mounter":
438439
csiMounter = v
439440
}
440441
}

internal/store/replicaset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func replicaSetMetricFamilies(allowAnnotationsList, allowLabelsList []string) []
158158
return &metric.Family{
159159
Metrics: []*metric.Metric{
160160
{
161-
Value: float64(r.ObjectMeta.Generation),
161+
Value: float64(r.Generation),
162162
},
163163
},
164164
}

internal/store/replicationcontroller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ var (
166166
return &metric.Family{
167167
Metrics: []*metric.Metric{
168168
{
169-
Value: float64(r.ObjectMeta.Generation),
169+
Value: float64(r.Generation),
170170
},
171171
},
172172
}

internal/store/role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func roleMetricFamilies(allowAnnotationsList, allowLabelsList []string) []genera
131131
"",
132132
wrapRoleFunc(func(r *rbacv1.Role) *metric.Family {
133133
return &metric.Family{
134-
Metrics: resourceVersionMetric(r.ObjectMeta.ResourceVersion),
134+
Metrics: resourceVersionMetric(r.ResourceVersion),
135135
}
136136
}),
137137
),

internal/store/rolebinding.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func roleBindingMetricFamilies(allowAnnotationsList, allowLabelsList []string) [
133133
"",
134134
wrapRoleBindingFunc(func(r *rbacv1.RoleBinding) *metric.Family {
135135
return &metric.Family{
136-
Metrics: resourceVersionMetric(r.ObjectMeta.ResourceVersion),
136+
Metrics: resourceVersionMetric(r.ResourceVersion),
137137
}
138138
}),
139139
),

internal/store/secret.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func secretMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gene
150150
"",
151151
wrapSecretFunc(func(s *v1.Secret) *metric.Family {
152152
return &metric.Family{
153-
Metrics: resourceVersionMetric(s.ObjectMeta.ResourceVersion),
153+
Metrics: resourceVersionMetric(s.ResourceVersion),
154154
}
155155
}),
156156
),

internal/store/statefulset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func statefulSetMetricFamilies(allowAnnotationsList, allowLabelsList []string) [
208208
return &metric.Family{
209209
Metrics: []*metric.Metric{
210210
{
211-
Value: float64(s.ObjectMeta.Generation),
211+
Value: float64(s.Generation),
212212
},
213213
},
214214
}

internal/store/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func TestKubeLabelsToPrometheusLabels(t *testing.T) {
257257
}
258258

259259
for i := range tc.expectKeys {
260-
if !(tc.expectKeys[i] == labelKeys[i] && tc.expectValues[i] == labelValues[i]) {
260+
if tc.expectKeys[i] != labelKeys[i] || tc.expectValues[i] != labelValues[i] {
261261
t.Errorf("Got Prometheus label %q: %q but expected %q: %q", labelKeys[i], labelValues[i], tc.expectKeys[i], tc.expectValues[i])
262262
}
263263
}

internal/store/validatingwebhookconfiguration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var (
7878
"",
7979
wrapValidatingWebhookConfigurationFunc(func(vwc *admissionregistrationv1.ValidatingWebhookConfiguration) *metric.Family {
8080
return &metric.Family{
81-
Metrics: resourceVersionMetric(vwc.ObjectMeta.ResourceVersion),
81+
Metrics: resourceVersionMetric(vwc.ResourceVersion),
8282
}
8383
}),
8484
),

pkg/app/server.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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/options/types_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestResourceSetSet(t *testing.T) {
5050
for _, test := range tests {
5151
cs := &ResourceSet{}
5252
gotError := cs.Set(test.Value)
53-
if !(((gotError == nil && !test.WantedError) || (gotError != nil && test.WantedError)) && reflect.DeepEqual(*cs, test.Wanted)) {
53+
if ((gotError != nil || test.WantedError) && (gotError == nil || !test.WantedError)) || !reflect.DeepEqual(*cs, test.Wanted) {
5454
t.Errorf("Test error for Desc: %s. Want: %+v. Got: %+v. Wanted Error: %v, Got Error: %v", test.Desc, test.Wanted, *cs, test.WantedError, gotError)
5555
}
5656
}

pkg/sharding/listwatch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (s *shardedListWatch) List(options metav1.ListOptions) (runtime.Object, err
6969
res.Items = append(res.Items, runtime.RawExtension{Object: item})
7070
}
7171
}
72-
res.ListMeta.ResourceVersion = metaObj.GetResourceVersion()
72+
res.ResourceVersion = metaObj.GetResourceVersion()
7373

7474
return res, nil
7575
}

pkg/sharding/listwatch_test.go

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy