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 Jul 3, 2024
1 parent 3628de0 commit a3bea1c
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 56 deletions.
3 changes: 3 additions & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4756,6 +4756,7 @@ core,k8s.io/kube-state-metrics/v2/pkg/metric_generator,Apache-2.0,Copyright 2014
core,k8s.io/kube-state-metrics/v2/pkg/metrics_store,Apache-2.0,Copyright 2014 The Kubernetes Authors.
core,k8s.io/kube-state-metrics/v2/pkg/options,Apache-2.0,Copyright 2014 The Kubernetes Authors.
core,k8s.io/kube-state-metrics/v2/pkg/sharding,Apache-2.0,Copyright 2014 The Kubernetes Authors.
core,k8s.io/kube-state-metrics/v2/pkg/util,Apache-2.0,Copyright 2014 The Kubernetes Authors.
core,k8s.io/kube-state-metrics/v2/pkg/watch,Apache-2.0,Copyright 2014 The Kubernetes Authors.
core,k8s.io/kubectl/pkg/cmd/util,Apache-2.0,Copyright 2014 The Kubernetes Authors.
core,k8s.io/kubectl/pkg/cmd/util/podcmd,Apache-2.0,Copyright 2014 The Kubernetes Authors.
Expand All @@ -4768,6 +4769,8 @@ core,k8s.io/metrics/pkg/apis/custom_metrics/v1beta2,Apache-2.0,Copyright 2014 Th
core,k8s.io/metrics/pkg/apis/external_metrics,Apache-2.0,Copyright 2014 The Kubernetes Authors.
core,k8s.io/metrics/pkg/apis/external_metrics/install,Apache-2.0,Copyright 2014 The Kubernetes Authors.
core,k8s.io/metrics/pkg/apis/external_metrics/v1beta1,Apache-2.0,Copyright 2014 The Kubernetes Authors.
core,k8s.io/sample-controller/pkg/apis/samplecontroller,Apache-2.0,Copyright 2014 The Kubernetes Authors.
core,k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1,Apache-2.0,Copyright 2014 The Kubernetes Authors.
core,k8s.io/utils/buffer,Apache-2.0,Copyright 2014 The Kubernetes Authors.
core,k8s.io/utils/clock,Apache-2.0,Copyright 2014 The Kubernetes Authors.
core,k8s.io/utils/clock/testing,Apache-2.0,Copyright 2014 The Kubernetes Authors.
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,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 @@ -1293,6 +1293,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
lukechampine.com/uint128 v1.3.0 // indirect
modernc.org/strutil v1.2.0 // indirect
modernc.org/token v1.1.0 // 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
6 changes: 3 additions & 3 deletions pkg/collector/corechecks/cluster/ksm/kubernetes_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ func (k *KSMCheck) Configure(senderManager sender.SenderManager, integrationConf
allowedAnnotations[collector] = []string{"*"}
}

builder.WithAllowAnnotations(allowedAnnotations)
if err := builder.WithAllowAnnotations(allowedAnnotations); err != nil {
log.Warnf("Failed to set allowed annotations: %v: %s", allowedAnnotations, err)
}

// Prepare watched namespaces
namespaces := k.instance.Namespaces
Expand All @@ -298,8 +300,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
12 changes: 2 additions & 10 deletions pkg/kubestatemetrics/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
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 @@ -39,7 +38,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 @@ -87,12 +85,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 Expand Up @@ -131,8 +123,8 @@ func (b *Builder) WithAllowLabels(l map[string][]string) error {
}

// WithAllowAnnotations configures which annotations can be returned for metrics
func (b *Builder) WithAllowAnnotations(l map[string][]string) {
b.ksmBuilder.WithAllowAnnotations(l)
func (b *Builder) WithAllowAnnotations(l map[string][]string) error {
return b.ksmBuilder.WithAllowAnnotations(l)
}

// Build initializes and registers all enabled stores.
Expand Down

0 comments on commit a3bea1c

Please sign in to comment.