Golangci linting configuration
- Configure Golangci linting tool with exclude-use-default=false. As noted in #800, Golangci did not reports some golint errors, such as missing comments on exported functions. That's because Golangci defaults to exclude-use-default=true, which exclude some errors based on regex (Check `golangci-lint run --help` for the list of excluded errors) - Fix issues now detected by Golangci, via golint
This commit is contained in:
parent
392572e1e7
commit
50b48ddb4f
|
|
@ -18,3 +18,6 @@ linters:
|
||||||
linters-settings:
|
linters-settings:
|
||||||
goimports:
|
goimports:
|
||||||
local-prefixes: k8s.io/kube-state-metrics
|
local-prefixes: k8s.io/kube-state-metrics
|
||||||
|
|
||||||
|
issues:
|
||||||
|
exclude-use-default: false
|
||||||
|
|
|
||||||
|
|
@ -28,17 +28,17 @@ import (
|
||||||
generator "k8s.io/kube-state-metrics/pkg/metric_generator"
|
generator "k8s.io/kube-state-metrics/pkg/metric_generator"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MetricTargetType int
|
type metricTargetType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Value MetricTargetType = iota
|
value metricTargetType = iota
|
||||||
Utilization
|
utilization
|
||||||
Average
|
average
|
||||||
|
|
||||||
MetricTargetTypeCount // Used as a length argument to arrays
|
metricTargetTypeCount // Used as a length argument to arrays
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m MetricTargetType) String() string {
|
func (m metricTargetType) String() string {
|
||||||
return [...]string{"value", "utilization", "average"}[m]
|
return [...]string{"value", "utilization", "average"}[m]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,40 +101,40 @@ var (
|
||||||
for _, m := range a.Spec.Metrics {
|
for _, m := range a.Spec.Metrics {
|
||||||
var metricName string
|
var metricName string
|
||||||
|
|
||||||
var v [MetricTargetTypeCount]int64
|
var v [metricTargetTypeCount]int64
|
||||||
var ok [MetricTargetTypeCount]bool
|
var ok [metricTargetTypeCount]bool
|
||||||
|
|
||||||
switch m.Type {
|
switch m.Type {
|
||||||
case autoscaling.ObjectMetricSourceType:
|
case autoscaling.ObjectMetricSourceType:
|
||||||
metricName = m.Object.MetricName
|
metricName = m.Object.MetricName
|
||||||
|
|
||||||
v[Value], ok[Value] = m.Object.TargetValue.AsInt64()
|
v[value], ok[value] = m.Object.TargetValue.AsInt64()
|
||||||
if m.Object.AverageValue != nil {
|
if m.Object.AverageValue != nil {
|
||||||
v[Average], ok[Average] = m.Object.AverageValue.AsInt64()
|
v[average], ok[average] = m.Object.AverageValue.AsInt64()
|
||||||
}
|
}
|
||||||
case autoscaling.PodsMetricSourceType:
|
case autoscaling.PodsMetricSourceType:
|
||||||
metricName = m.Pods.MetricName
|
metricName = m.Pods.MetricName
|
||||||
|
|
||||||
v[Average], ok[Average] = m.Pods.TargetAverageValue.AsInt64()
|
v[average], ok[average] = m.Pods.TargetAverageValue.AsInt64()
|
||||||
case autoscaling.ResourceMetricSourceType:
|
case autoscaling.ResourceMetricSourceType:
|
||||||
metricName = string(m.Resource.Name)
|
metricName = string(m.Resource.Name)
|
||||||
|
|
||||||
if ok[Utilization] = (m.Resource.TargetAverageUtilization != nil); ok[Utilization] {
|
if ok[utilization] = (m.Resource.TargetAverageUtilization != nil); ok[utilization] {
|
||||||
v[Utilization] = int64(*m.Resource.TargetAverageUtilization)
|
v[utilization] = int64(*m.Resource.TargetAverageUtilization)
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.Resource.TargetAverageValue != nil {
|
if m.Resource.TargetAverageValue != nil {
|
||||||
v[Average], ok[Average] = m.Resource.TargetAverageValue.AsInt64()
|
v[average], ok[average] = m.Resource.TargetAverageValue.AsInt64()
|
||||||
}
|
}
|
||||||
case autoscaling.ExternalMetricSourceType:
|
case autoscaling.ExternalMetricSourceType:
|
||||||
metricName = m.External.MetricName
|
metricName = m.External.MetricName
|
||||||
|
|
||||||
// The TargetValue and TargetAverageValue are mutually exclusive
|
// The TargetValue and TargetAverageValue are mutually exclusive
|
||||||
if m.External.TargetValue != nil {
|
if m.External.TargetValue != nil {
|
||||||
v[Value], ok[Value] = m.External.TargetValue.AsInt64()
|
v[value], ok[value] = m.External.TargetValue.AsInt64()
|
||||||
}
|
}
|
||||||
if m.External.TargetAverageValue != nil {
|
if m.External.TargetAverageValue != nil {
|
||||||
v[Average], ok[Average] = m.External.TargetAverageValue.AsInt64()
|
v[average], ok[average] = m.External.TargetAverageValue.AsInt64()
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
// Skip unsupported metric type
|
// Skip unsupported metric type
|
||||||
|
|
@ -145,7 +145,7 @@ var (
|
||||||
if ok[i] {
|
if ok[i] {
|
||||||
ms = append(ms, &metric.Metric{
|
ms = append(ms, &metric.Metric{
|
||||||
LabelKeys: targetMetricLabels,
|
LabelKeys: targetMetricLabels,
|
||||||
LabelValues: []string{metricName, MetricTargetType(i).String()},
|
LabelValues: []string{metricName, metricTargetType(i).String()},
|
||||||
Value: float64(v[i]),
|
Value: float64(v[i]),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue