Skip to content

Commit

Permalink
bump k8s.io/kube-state-metrics/v2
Browse files Browse the repository at this point in the history
  • Loading branch information
keisku committed Jun 15, 2024
1 parent 95cd819 commit 91692b0
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 53 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ require (
k8s.io/klog/v2 v2.120.1
k8s.io/kube-aggregator v0.28.6
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00
k8s.io/kube-state-metrics/v2 v2.8.2
k8s.io/kube-state-metrics/v2 v2.12.0
k8s.io/kubelet v0.29.3
k8s.io/metrics v0.28.6
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
Expand Down Expand Up @@ -1290,6 +1290,7 @@ require (
honnef.co/go/tools v0.4.5 // indirect
howett.net/plist v1.0.0 // indirect
k8s.io/kms v0.29.0 // indirect
k8s.io/sample-controller v0.29.3 // indirect
skywalking.apache.org/repo/goapi v0.0.0-20240104145220-ba7202308dd4 // indirect
)

Expand Down
6 changes: 4 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (f *apiserviceFactory) Name() string {
return "apiservices"
}

func (f *apiserviceFactory) MetricFamilyGenerators(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
func (f *apiserviceFactory) MetricFamilyGenerators() []generator.FamilyGenerator {
return []generator.FamilyGenerator{
*generator.NewFamilyGeneratorWithStability(
descAPIServiceAnnotationsName,
Expand All @@ -61,7 +61,7 @@ func (f *apiserviceFactory) MetricFamilyGenerators(allowAnnotationsList, allowLa
basemetrics.ALPHA,
"",
wrapAPIServiceFunc(func(a *v1.APIService) *metric.Family {
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", a.Annotations, allowAnnotationsList)
annotationKeys, annotationValues := kubeMapToPrometheusLabels("annotation", a.Annotations)
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -80,7 +80,7 @@ func (f *apiserviceFactory) MetricFamilyGenerators(allowAnnotationsList, allowLa
basemetrics.ALPHA,
"",
wrapAPIServiceFunc(func(a *v1.APIService) *metric.Family {
labelKeys, labelValues := createPrometheusLabelKeysValues("label", a.Labels, allowLabelsList)
labelKeys, labelValues := kubeMapToPrometheusLabels("label", a.Labels)
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand Down
7 changes: 4 additions & 3 deletions pkg/collector/corechecks/cluster/ksm/customresources/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/DataDog/datadog-agent/pkg/util/kubernetes/apiserver"
crd "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"

//nolint:revive // TODO(CINT) Fix revive linter
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -48,7 +49,7 @@ type crdFactory struct {
client interface{}
}

func (f *crdFactory) MetricFamilyGenerators(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
func (f *crdFactory) MetricFamilyGenerators() []generator.FamilyGenerator {
return []generator.FamilyGenerator{
*generator.NewFamilyGeneratorWithStability(
descCustomResourceDefinitionAnnotationsName,
Expand All @@ -57,7 +58,7 @@ func (f *crdFactory) MetricFamilyGenerators(allowAnnotationsList, allowLabelsLis
basemetrics.ALPHA,
"",
wrapCustomResourceDefinition(func(c *crd.CustomResourceDefinition) *metric.Family {
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", c.Annotations, allowAnnotationsList)
annotationKeys, annotationValues := kubeMapToPrometheusLabels("annotation", c.Annotations)
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -76,7 +77,7 @@ func (f *crdFactory) MetricFamilyGenerators(allowAnnotationsList, allowLabelsLis
basemetrics.ALPHA,
"",
wrapCustomResourceDefinition(func(c *crd.CustomResourceDefinition) *metric.Family {
labelKeys, labelValues := createPrometheusLabelKeysValues("label", c.Labels, allowLabelsList)
labelKeys, labelValues := kubeMapToPrometheusLabels("label", c.Labels)
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (f *cronjobv1beta1Factory) CreateClient(cfg *rest.Config) (interface{}, err
return f.client, nil
}

func (f *cronjobv1beta1Factory) MetricFamilyGenerators(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
func (f *cronjobv1beta1Factory) MetricFamilyGenerators() []generator.FamilyGenerator {
return []generator.FamilyGenerator{
*generator.NewFamilyGeneratorWithStability(
descCronJobAnnotationsName,
Expand All @@ -72,7 +72,7 @@ func (f *cronjobv1beta1Factory) MetricFamilyGenerators(allowAnnotationsList, all
basemetrics.ALPHA,
"",
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", j.Annotations, allowAnnotationsList)
annotationKeys, annotationValues := kubeMapToPrometheusLabels("annotation", j.Annotations)
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -91,7 +91,7 @@ func (f *cronjobv1beta1Factory) MetricFamilyGenerators(allowAnnotationsList, all
basemetrics.STABLE,
"",
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
labelKeys, labelValues := createPrometheusLabelKeysValues("label", j.Labels, allowLabelsList)
labelKeys, labelValues := kubeMapToPrometheusLabels("label", j.Labels)
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand Down
6 changes: 3 additions & 3 deletions pkg/collector/corechecks/cluster/ksm/customresources/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (f *hpav2Factory) CreateClient(cfg *rest.Config) (interface{}, error) {
return f.client, nil
}

func (f *hpav2Factory) MetricFamilyGenerators(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
func (f *hpav2Factory) MetricFamilyGenerators() []generator.FamilyGenerator {
return []generator.FamilyGenerator{
*generator.NewFamilyGeneratorWithStability(
"kube_horizontalpodautoscaler_info",
Expand Down Expand Up @@ -311,7 +311,7 @@ func (f *hpav2Factory) MetricFamilyGenerators(allowAnnotationsList, allowLabelsL
basemetrics.ALPHA,
"",
wrapHPAFunc(func(a *autoscaling.HorizontalPodAutoscaler) *metric.Family {
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", a.Annotations, allowAnnotationsList)
annotationKeys, annotationValues := kubeMapToPrometheusLabels("annotation", a.Annotations)
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -330,7 +330,7 @@ func (f *hpav2Factory) MetricFamilyGenerators(allowAnnotationsList, allowLabelsL
basemetrics.STABLE,
"",
wrapHPAFunc(func(a *autoscaling.HorizontalPodAutoscaler) *metric.Family {
labelKeys, labelValues := createPrometheusLabelKeysValues("label", a.Labels, allowLabelsList)
labelKeys, labelValues := kubeMapToPrometheusLabels("label", a.Labels)
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (f *extendedJobFactory) CreateClient(cfg *rest.Config) (interface{}, error)
// MetricFamilyGenerators returns the extended job metric family generators
//
//nolint:revive // TODO(CINT) Fix revive linter
func (f *extendedJobFactory) MetricFamilyGenerators(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
func (f *extendedJobFactory) MetricFamilyGenerators() []generator.FamilyGenerator {
return []generator.FamilyGenerator{
*generator.NewFamilyGeneratorWithStability(
"kube_job_duration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (f *extendedNodeFactory) CreateClient(cfg *rest.Config) (interface{}, error
// MetricFamilyGenerators returns the extended node metric family generators
//
//nolint:revive // TODO(CINT) Fix revive linter
func (f *extendedNodeFactory) MetricFamilyGenerators(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
func (f *extendedNodeFactory) MetricFamilyGenerators() []generator.FamilyGenerator {
// At the time of writing this, this is necessary in order for us to have access to the "kubernetes.io/network-bandwidth" resource
// type, as the default KSM offering explicitly filters out anything that is prefixed with "kubernetes.io/"
// More information can be found here: https://github.com/kubernetes/kube-state-metrics/issues/2027
Expand Down
6 changes: 3 additions & 3 deletions pkg/collector/corechecks/cluster/ksm/customresources/pdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (f *pdbv1beta1Factory) CreateClient(cfg *rest.Config) (interface{}, error)
return f.client, nil
}

func (f *pdbv1beta1Factory) MetricFamilyGenerators(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
func (f *pdbv1beta1Factory) MetricFamilyGenerators() []generator.FamilyGenerator {
return []generator.FamilyGenerator{
*generator.NewFamilyGeneratorWithStability(
descPodDisruptionBudgetAnnotationsName,
Expand All @@ -70,7 +70,7 @@ func (f *pdbv1beta1Factory) MetricFamilyGenerators(allowAnnotationsList, allowLa
metrics.ALPHA,
"",
wrapPodDisruptionBudgetFunc(func(p *policyv1beta1.PodDisruptionBudget) *metric.Family {
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", p.Annotations, allowAnnotationsList)
annotationKeys, annotationValues := kubeMapToPrometheusLabels("annotation", p.Annotations)
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -89,7 +89,7 @@ func (f *pdbv1beta1Factory) MetricFamilyGenerators(allowAnnotationsList, allowLa
metrics.ALPHA,
"",
wrapPodDisruptionBudgetFunc(func(p *policyv1beta1.PodDisruptionBudget) *metric.Family {
labelKeys, labelValues := createPrometheusLabelKeysValues("label", p.Labels, allowLabelsList)
labelKeys, labelValues := kubeMapToPrometheusLabels("label", p.Labels)
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (f *extendedPodFactory) CreateClient(cfg *rest.Config) (interface{}, error)
// MetricFamilyGenerators returns the extended pod metric family generators
//
//nolint:revive // TODO(CINT) Fix revive linter
func (f *extendedPodFactory) MetricFamilyGenerators(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
func (f *extendedPodFactory) MetricFamilyGenerators() []generator.FamilyGenerator {
// At the time of writing this, this is necessary in order for us to have access to the "kubernetes.io/network-bandwidth" resource
// type, as the default KSM offering explicitly filters out anything that is prefixed with "kubernetes.io/"
// More information can be found here: https://github.com/kubernetes/kube-state-metrics/issues/2027
Expand Down
22 changes: 0 additions & 22 deletions pkg/collector/corechecks/cluster/ksm/customresources/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
extension "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
"k8s.io/kube-state-metrics/v2/pkg/metric"
"k8s.io/kube-state-metrics/v2/pkg/options"
)

const networkBandwidthResourceName = "kubernetes.io/network-bandwidth"
Expand Down Expand Up @@ -130,27 +129,6 @@ func labelConflictSuffix(label string, count int) string {
return fmt.Sprintf("%s_conflict%d", label, count)
}

// createPrometheusLabelKeysValues takes in passed kubernetes annotations/labels
// and associated allowed list in kubernetes label format.
// It returns only those allowed annotations/labels that exist in the list and converts them to Prometheus labels.
func createPrometheusLabelKeysValues(prefix string, allKubeData map[string]string, allowList []string) ([]string, []string) {
allowedKubeData := make(map[string]string)

if len(allowList) > 0 {
if allowList[0] == options.LabelWildcard {
return kubeMapToPrometheusLabels(prefix, allKubeData)
}

for _, l := range allowList {
v, found := allKubeData[l]
if found {
allowedKubeData[l] = v
}
}
}
return kubeMapToPrometheusLabels(prefix, allowedKubeData)
}

// mergeKeyValues merges label keys and values slice pairs into a single slice pair.
// Arguments are passed as equal-length pairs of slices, where the first slice contains keys and second contains values.
// Example: mergeKeyValues(keys1, values1, keys2, values2) => (keys1+keys2, values1+values2)
Expand Down
2 changes: 0 additions & 2 deletions pkg/collector/corechecks/cluster/ksm/kubernetes_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,6 @@ func (k *KSMCheck) Configure(senderManager sender.SenderManager, integrationConf

builder.WithKubeClient(c.InformerCl)

builder.WithVPAClient(c.VPAInformerClient)

ctx, cancel := context.WithCancel(context.Background())
k.cancel = cancel
builder.WithContext(ctx)
Expand Down
8 changes: 0 additions & 8 deletions pkg/kubestatemetrics/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/prometheus/client_golang/prometheus"
corev1 "k8s.io/api/core/v1"
vpaclientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
ksmbuild "k8s.io/kube-state-metrics/v2/pkg/builder"
Expand All @@ -35,7 +34,6 @@ type Builder struct {

customResourceClients map[string]interface{}
kubeClient clientset.Interface
vpaClient vpaclientset.Interface
namespaces options.NamespaceList
fieldSelectorFilter string
ctx context.Context
Expand Down Expand Up @@ -92,12 +90,6 @@ func (b *Builder) WithCustomResourceClients(clients map[string]interface{}) {
b.ksmBuilder.WithCustomResourceClients(clients)
}

// WithVPAClient sets the vpaClient property of a Builder so that the verticalpodautoscaler collector can query VPA objects.
func (b *Builder) WithVPAClient(c vpaclientset.Interface) {
b.vpaClient = c
b.ksmBuilder.WithVPAClient(c)
}

// WithMetrics sets the metrics property of a Builder.
func (b *Builder) WithMetrics(r prometheus.Registerer) {
b.ksmBuilder.WithMetrics(r)
Expand Down

0 comments on commit 91692b0

Please sign in to comment.