Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
E2E_SETUP_KUBECTL: yes
SUDO: sudo
GO_VERSION: "^1.24"
GOLANGCI_LINT_VERSION: "v1.64.6"
GOLANGCI_LINT_VERSION: "v2.0.2"

jobs:
ci-go-lint:
Expand Down
60 changes: 35 additions & 25 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
run:
timeout: 10m

version: "2"
linters:
disable-all: true
default: none
enable:
- gocritic
- gocyclo
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- misspell
Expand All @@ -18,22 +13,37 @@ linters:
- staticcheck
- unconvert
- unused

linters-settings:
goimports:
local-prefixes: k8s.io/kube-state-metrics,k8s.io/kube-state-metrics/v2

exclusions:
generated: lax
rules:
- linters:
- promlinter
path: _test\.go
- linters:
- gosec
text: 'G104:'
- linters:
- revive
text: 'package-comments:'
paths:
- third_party$
- builtin$
- examples$
issues:
exclude-use-default: false
exclude-rules:
# We don't check metrics naming in the tests.
- path: _test\.go
linters:
- promlinter
# TODO(mrueg) Improve error handling
- text: "G104:"
linters:
- gosec
- text: "package-comments:"
linters:
- revive
max-issues-per-linter: 0
max-same-issues: 0
formatters:
enable:
- gofmt
- goimports
settings:
goimports:
local-prefixes:
- k8s.io/kube-state-metrics
- k8s.io/kube-state-metrics/v2
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion internal/store/clusterrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func clusterRoleMetricFamilies(allowAnnotationsList, allowLabelsList []string) [
"",
wrapClusterRoleFunc(func(r *rbacv1.ClusterRole) *metric.Family {
return &metric.Family{
Metrics: resourceVersionMetric(r.ObjectMeta.ResourceVersion),
Metrics: resourceVersionMetric(r.ResourceVersion),
}
}),
),
Expand Down
2 changes: 1 addition & 1 deletion internal/store/clusterrolebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func clusterRoleBindingMetricFamilies(allowAnnotationsList, allowLabelsList []st
"",
wrapClusterRoleBindingFunc(func(r *rbacv1.ClusterRoleBinding) *metric.Family {
return &metric.Family{
Metrics: resourceVersionMetric(r.ObjectMeta.ResourceVersion),
Metrics: resourceVersionMetric(r.ResourceVersion),
}
}),
),
Expand Down
2 changes: 1 addition & 1 deletion internal/store/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func configMapMetricFamilies(allowAnnotationsList, allowLabelsList []string) []g
"",
wrapConfigMapFunc(func(c *v1.ConfigMap) *metric.Family {
return &metric.Family{
Metrics: resourceVersionMetric(c.ObjectMeta.ResourceVersion),
Metrics: resourceVersionMetric(c.ResourceVersion),
}
}),
),
Expand Down
4 changes: 2 additions & 2 deletions internal/store/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
"",
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
return &metric.Family{
Metrics: resourceVersionMetric(j.ObjectMeta.ResourceVersion),
Metrics: resourceVersionMetric(j.ResourceVersion),
}
}),
),
Expand Down Expand Up @@ -358,7 +358,7 @@ func getNextScheduledTime(schedule string, lastScheduleTime *metav1.Time, create

sched, err := cron.ParseStandard(schedule)
if err != nil {
return time.Time{}, fmt.Errorf("Failed to parse cron job schedule '%s': %w", schedule, err)
return time.Time{}, fmt.Errorf("failed to parse cron job schedule '%s': %w", schedule, err)
}
if !lastScheduleTime.IsZero() {
return sched.Next(lastScheduleTime.Time), nil
Expand Down
2 changes: 1 addition & 1 deletion internal/store/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func daemonSetMetricFamilies(allowAnnotationsList, allowLabelsList []string) []g
{
LabelKeys: []string{},
LabelValues: []string{},
Value: float64(d.ObjectMeta.Generation),
Value: float64(d.Generation),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/store/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func deploymentMetricFamilies(allowAnnotationsList, allowLabelsList []string) []
return &metric.Family{
Metrics: []*metric.Metric{
{
Value: float64(d.ObjectMeta.Generation),
Value: float64(d.Generation),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/store/horizontalpodautoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func createHPAMetaDataGeneration() generator.FamilyGenerator {
return &metric.Family{
Metrics: []*metric.Metric{
{
Value: float64(a.ObjectMeta.Generation),
Value: float64(a.Generation),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/store/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func ingressMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
"",
wrapIngressFunc(func(i *networkingv1.Ingress) *metric.Family {
return &metric.Family{
Metrics: resourceVersionMetric(i.ObjectMeta.ResourceVersion),
Metrics: resourceVersionMetric(i.ResourceVersion),
}
}),
),
Expand Down
2 changes: 1 addition & 1 deletion internal/store/mutatingwebhookconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var (
"",
wrapMutatingWebhookConfigurationFunc(func(mwc *admissionregistrationv1.MutatingWebhookConfiguration) *metric.Family {
return &metric.Family{
Metrics: resourceVersionMetric(mwc.ObjectMeta.ResourceVersion),
Metrics: resourceVersionMetric(mwc.ResourceVersion),
}
}),
),
Expand Down
69 changes: 35 additions & 34 deletions internal/store/persistentvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,50 +243,50 @@ func createPersistentVolumeInfo() generator.FamilyGenerator {
)

switch {
case p.Spec.PersistentVolumeSource.GCEPersistentDisk != nil:
gcePDDiskName = p.Spec.PersistentVolumeSource.GCEPersistentDisk.PDName
case p.Spec.PersistentVolumeSource.AWSElasticBlockStore != nil:
ebsVolumeID = p.Spec.PersistentVolumeSource.AWSElasticBlockStore.VolumeID
case p.Spec.PersistentVolumeSource.AzureDisk != nil:
azureDiskName = p.Spec.PersistentVolumeSource.AzureDisk.DiskName
case p.Spec.PersistentVolumeSource.FC != nil:
if p.Spec.PersistentVolumeSource.FC.Lun != nil {
fcLun = strconv.FormatInt(int64(*p.Spec.PersistentVolumeSource.FC.Lun), 10)
case p.Spec.GCEPersistentDisk != nil:
gcePDDiskName = p.Spec.GCEPersistentDisk.PDName
case p.Spec.AWSElasticBlockStore != nil:
ebsVolumeID = p.Spec.AWSElasticBlockStore.VolumeID
case p.Spec.AzureDisk != nil:
azureDiskName = p.Spec.AzureDisk.DiskName
case p.Spec.FC != nil:
if p.Spec.FC.Lun != nil {
fcLun = strconv.FormatInt(int64(*p.Spec.FC.Lun), 10)
}
for _, wwn := range p.Spec.PersistentVolumeSource.FC.TargetWWNs {
for _, wwn := range p.Spec.FC.TargetWWNs {
if len(fcTargetWWNs) != 0 {
fcTargetWWNs += ","
}
fcTargetWWNs += wwn
}
for _, wwid := range p.Spec.PersistentVolumeSource.FC.WWIDs {
for _, wwid := range p.Spec.FC.WWIDs {
if len(fcWWIDs) != 0 {
fcWWIDs += ","
}
fcWWIDs += wwid
}
case p.Spec.PersistentVolumeSource.ISCSI != nil:
iscsiTargetPortal = p.Spec.PersistentVolumeSource.ISCSI.TargetPortal
iscsiIQN = p.Spec.PersistentVolumeSource.ISCSI.IQN
iscsiLun = strconv.FormatInt(int64(p.Spec.PersistentVolumeSource.ISCSI.Lun), 10)
if p.Spec.PersistentVolumeSource.ISCSI.InitiatorName != nil {
iscsiInitiatorName = *p.Spec.PersistentVolumeSource.ISCSI.InitiatorName
case p.Spec.ISCSI != nil:
iscsiTargetPortal = p.Spec.ISCSI.TargetPortal
iscsiIQN = p.Spec.ISCSI.IQN
iscsiLun = strconv.FormatInt(int64(p.Spec.ISCSI.Lun), 10)
if p.Spec.ISCSI.InitiatorName != nil {
iscsiInitiatorName = *p.Spec.ISCSI.InitiatorName
}
case p.Spec.PersistentVolumeSource.NFS != nil:
nfsServer = p.Spec.PersistentVolumeSource.NFS.Server
nfsPath = p.Spec.PersistentVolumeSource.NFS.Path
case p.Spec.PersistentVolumeSource.CSI != nil:
csiDriver = p.Spec.PersistentVolumeSource.CSI.Driver
csiVolumeHandle = p.Spec.PersistentVolumeSource.CSI.VolumeHandle
case p.Spec.PersistentVolumeSource.Local != nil:
localPath = p.Spec.PersistentVolumeSource.Local.Path
if p.Spec.PersistentVolumeSource.Local.FSType != nil {
localFS = *p.Spec.PersistentVolumeSource.Local.FSType
case p.Spec.NFS != nil:
nfsServer = p.Spec.NFS.Server
nfsPath = p.Spec.NFS.Path
case p.Spec.CSI != nil:
csiDriver = p.Spec.CSI.Driver
csiVolumeHandle = p.Spec.CSI.VolumeHandle
case p.Spec.Local != nil:
localPath = p.Spec.Local.Path
if p.Spec.Local.FSType != nil {
localFS = *p.Spec.Local.FSType
}
case p.Spec.PersistentVolumeSource.HostPath != nil:
hostPath = p.Spec.PersistentVolumeSource.HostPath.Path
if p.Spec.PersistentVolumeSource.HostPath.Type != nil {
hostPathType = string(*p.Spec.PersistentVolumeSource.HostPath.Type)
case p.Spec.HostPath != nil:
hostPath = p.Spec.HostPath.Path
if p.Spec.HostPath.Type != nil {
hostPathType = string(*p.Spec.HostPath.Type)
}
}

Expand Down Expand Up @@ -430,11 +430,12 @@ func createPersistentVolumeCSIAttributes() generator.FamilyGenerator {
}

var csiMounter, csiMapOptions string
for k, v := range p.Spec.PersistentVolumeSource.CSI.VolumeAttributes {
for k, v := range p.Spec.CSI.VolumeAttributes {
// storage attributes handled by external CEPH CSI driver
if k == "mapOptions" {
switch k {
case "mapOptions":
csiMapOptions = v
} else if k == "mounter" {
case "mounter":
csiMounter = v
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/store/replicaset.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func replicaSetMetricFamilies(allowAnnotationsList, allowLabelsList []string) []
return &metric.Family{
Metrics: []*metric.Metric{
{
Value: float64(r.ObjectMeta.Generation),
Value: float64(r.Generation),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/store/replicationcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ var (
return &metric.Family{
Metrics: []*metric.Metric{
{
Value: float64(r.ObjectMeta.Generation),
Value: float64(r.Generation),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/store/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func roleMetricFamilies(allowAnnotationsList, allowLabelsList []string) []genera
"",
wrapRoleFunc(func(r *rbacv1.Role) *metric.Family {
return &metric.Family{
Metrics: resourceVersionMetric(r.ObjectMeta.ResourceVersion),
Metrics: resourceVersionMetric(r.ResourceVersion),
}
}),
),
Expand Down
2 changes: 1 addition & 1 deletion internal/store/rolebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func roleBindingMetricFamilies(allowAnnotationsList, allowLabelsList []string) [
"",
wrapRoleBindingFunc(func(r *rbacv1.RoleBinding) *metric.Family {
return &metric.Family{
Metrics: resourceVersionMetric(r.ObjectMeta.ResourceVersion),
Metrics: resourceVersionMetric(r.ResourceVersion),
}
}),
),
Expand Down
2 changes: 1 addition & 1 deletion internal/store/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func secretMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gene
"",
wrapSecretFunc(func(s *v1.Secret) *metric.Family {
return &metric.Family{
Metrics: resourceVersionMetric(s.ObjectMeta.ResourceVersion),
Metrics: resourceVersionMetric(s.ResourceVersion),
}
}),
),
Expand Down
2 changes: 1 addition & 1 deletion internal/store/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func statefulSetMetricFamilies(allowAnnotationsList, allowLabelsList []string) [
return &metric.Family{
Metrics: []*metric.Metric{
{
Value: float64(s.ObjectMeta.Generation),
Value: float64(s.Generation),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/store/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func TestKubeLabelsToPrometheusLabels(t *testing.T) {
}

for i := range tc.expectKeys {
if !(tc.expectKeys[i] == labelKeys[i] && tc.expectValues[i] == labelValues[i]) {
if tc.expectKeys[i] != labelKeys[i] || tc.expectValues[i] != labelValues[i] {
t.Errorf("Got Prometheus label %q: %q but expected %q: %q", labelKeys[i], labelValues[i], tc.expectKeys[i], tc.expectValues[i])
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/store/validatingwebhookconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var (
"",
wrapValidatingWebhookConfigurationFunc(func(vwc *admissionregistrationv1.ValidatingWebhookConfiguration) *metric.Family {
return &metric.Family{
Metrics: resourceVersionMetric(vwc.ObjectMeta.ResourceVersion),
Metrics: resourceVersionMetric(vwc.ResourceVersion),
}
}),
),
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func resolveCustomResourceConfig(opts *options.Options) (customresourcestate.Con
if file := opts.CustomResourceConfigFile; file != "" {
f, err := os.Open(filepath.Clean(file))
if err != nil {
return nil, fmt.Errorf("Custom Resource State Metrics file could not be opened: %v", err)
return nil, fmt.Errorf("unable to open Custom Resource State Metrics file: %v", err)
}
return yaml.NewDecoder(f), nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/customresourcestate/registry_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func compileCommon(c MetricMeta) (*compiledCommon, error) {
}

func compileFamily(f Generator, resource Resource) (*compiledFamily, error) {
labels := resource.Labels.Merge(f.Labels)
labels := resource.Merge(f.Labels)

if f.Each.Type == metric.Info && !strings.HasSuffix(f.Name, "_info") {
klog.InfoS("Info metric does not have _info suffix", "gvk", resource.GroupVersionKind.String(), "name", f.Name)
Expand Down Expand Up @@ -652,7 +652,7 @@ func compilePath(path []string) (out valuePath, _ error) {
// negative index
i += len(s)
}
if !(0 <= i && i < len(s)) {
if i < 0 || i > len(s) {
return fmt.Errorf("list index out of range: %s", part)
}
return s[i]
Expand Down
2 changes: 1 addition & 1 deletion pkg/options/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestResourceSetSet(t *testing.T) {
for _, test := range tests {
cs := &ResourceSet{}
gotError := cs.Set(test.Value)
if !(((gotError == nil && !test.WantedError) || (gotError != nil && test.WantedError)) && reflect.DeepEqual(*cs, test.Wanted)) {
if ((gotError != nil || test.WantedError) && (gotError == nil || !test.WantedError)) || !reflect.DeepEqual(*cs, test.Wanted) {
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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sharding/listwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *shardedListWatch) List(options metav1.ListOptions) (runtime.Object, err
res.Items = append(res.Items, runtime.RawExtension{Object: item})
}
}
res.ListMeta.ResourceVersion = metaObj.GetResourceVersion()
res.ResourceVersion = metaObj.GetResourceVersion()

return res, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sharding/listwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestSharding(t *testing.T) {
totalShards: 2,
}

if !(s1.keep(cm) || s2.keep(cm)) {
if !s1.keep(cm) && !s2.keep(cm) {
t.Fatal("One shard must pick up the object.")
}

Expand Down
Loading