diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 992cdbb8c4ec9f..dc9a5615ad95ce 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -4781,6 +4781,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. @@ -4795,6 +4796,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. diff --git a/go.mod b/go.mod index 7ddb9271b6a82d..c5aaa73620dfd3 100644 --- a/go.mod +++ b/go.mod @@ -314,7 +314,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 @@ -1288,6 +1288,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.1.3 // indirect modernc.org/token v1.1.0 // indirect diff --git a/go.sum b/go.sum index 2f2267bf1a9a79..7af762afd8ca6a 100644 --- a/go.sum +++ b/go.sum @@ -4562,12 +4562,14 @@ k8s.io/kube-openapi v0.0.0-20230901164831-6c774f458599 h1:nVKRi5eItf3x9kkIMfdT4D k8s.io/kube-openapi v0.0.0-20230901164831-6c774f458599/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA= k8s.io/kube-state-metrics/v2 v2.8.2 h1:P/9wJF26kkCF3Iy52e+MFijjeCAFtqNLFvpKJW5+CR8= k8s.io/kube-state-metrics/v2 v2.8.2/go.mod h1:kulGw0iSIvo1cjWdDExkeGW1muV/OV4C2TZOaHxqvyc= +k8s.io/kube-state-metrics/v2 v2.12.0/go.mod h1:s1Iq7mNhtbb4fnwMw39uUOrpdIaeoyDQDWA7OZoOqhc= k8s.io/kubectl v0.28.6 h1:46O3gGJYlpqy7wtwYlggieemyIcuZqmflnQVDci3MgY= k8s.io/kubectl v0.28.6/go.mod h1:FS5ugZhi3kywpMQSCnp8MN+gctdFHJACzC6mH3fZ6lc= k8s.io/kubelet v0.29.3 h1:X9h0ZHzc+eUeNTaksbN0ItHyvGhQ7Z0HPjnQD2oHdwU= k8s.io/kubelet v0.29.3/go.mod h1:jDiGuTkFOUynyBKzOoC1xRSWlgAZ9UPcTYeFyjr6vas= k8s.io/metrics v0.28.6 h1:7BZqPSl356LG98AaoOqTcPKbl5aloXNrThj2AtS15Rg= k8s.io/metrics v0.28.6/go.mod h1:eeqj1hFqI14iSsKVfa8Vu/+OIfi7s8lxpnCJOA7teLg= +k8s.io/sample-controller v0.29.3/go.mod h1:zjhfoVX5Bcf7G4yNUoUmhXbVMMqM+TUoz3pILzH0OLo= k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 h1:jgGTlFYnhF1PM1Ax/lAlxUPE+KfCIXHaathvJg1C3ak= diff --git a/pkg/collector/corechecks/cluster/ksm/customresources/apiservice.go b/pkg/collector/corechecks/cluster/ksm/customresources/apiservice.go index 36b7600ab94ed4..79b89b98b10c26 100644 --- a/pkg/collector/corechecks/cluster/ksm/customresources/apiservice.go +++ b/pkg/collector/corechecks/cluster/ksm/customresources/apiservice.go @@ -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, @@ -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{ { @@ -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{ { diff --git a/pkg/collector/corechecks/cluster/ksm/customresources/crd.go b/pkg/collector/corechecks/cluster/ksm/customresources/crd.go index a3b3d5ac248289..487205185c74d4 100644 --- a/pkg/collector/corechecks/cluster/ksm/customresources/crd.go +++ b/pkg/collector/corechecks/cluster/ksm/customresources/crd.go @@ -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" @@ -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, @@ -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{ { @@ -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{ { diff --git a/pkg/collector/corechecks/cluster/ksm/customresources/cronjob.go b/pkg/collector/corechecks/cluster/ksm/customresources/cronjob.go index 0e95b62e95f817..1412bc26ef252a 100644 --- a/pkg/collector/corechecks/cluster/ksm/customresources/cronjob.go +++ b/pkg/collector/corechecks/cluster/ksm/customresources/cronjob.go @@ -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, @@ -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{ { @@ -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{ { diff --git a/pkg/collector/corechecks/cluster/ksm/customresources/hpa.go b/pkg/collector/corechecks/cluster/ksm/customresources/hpa.go index 9e0dfbe8c70d8d..b1d8556632903c 100644 --- a/pkg/collector/corechecks/cluster/ksm/customresources/hpa.go +++ b/pkg/collector/corechecks/cluster/ksm/customresources/hpa.go @@ -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", @@ -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{ { @@ -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{ { diff --git a/pkg/collector/corechecks/cluster/ksm/customresources/job.go b/pkg/collector/corechecks/cluster/ksm/customresources/job.go index 58385a837e229a..d05494a781b89f 100644 --- a/pkg/collector/corechecks/cluster/ksm/customresources/job.go +++ b/pkg/collector/corechecks/cluster/ksm/customresources/job.go @@ -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", diff --git a/pkg/collector/corechecks/cluster/ksm/customresources/node.go b/pkg/collector/corechecks/cluster/ksm/customresources/node.go index 97cea70c660164..ec4c6d283e3a79 100644 --- a/pkg/collector/corechecks/cluster/ksm/customresources/node.go +++ b/pkg/collector/corechecks/cluster/ksm/customresources/node.go @@ -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 diff --git a/pkg/collector/corechecks/cluster/ksm/customresources/pdb.go b/pkg/collector/corechecks/cluster/ksm/customresources/pdb.go index 76979ea2899f7a..9bd98a182e62da 100644 --- a/pkg/collector/corechecks/cluster/ksm/customresources/pdb.go +++ b/pkg/collector/corechecks/cluster/ksm/customresources/pdb.go @@ -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, @@ -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{ { @@ -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{ { diff --git a/pkg/collector/corechecks/cluster/ksm/customresources/pod.go b/pkg/collector/corechecks/cluster/ksm/customresources/pod.go index ee749c094c1288..f45fe600c9d387 100644 --- a/pkg/collector/corechecks/cluster/ksm/customresources/pod.go +++ b/pkg/collector/corechecks/cluster/ksm/customresources/pod.go @@ -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 diff --git a/pkg/collector/corechecks/cluster/ksm/customresources/utils.go b/pkg/collector/corechecks/cluster/ksm/customresources/utils.go index 1553479b79dce3..01cf2f1ed333aa 100644 --- a/pkg/collector/corechecks/cluster/ksm/customresources/utils.go +++ b/pkg/collector/corechecks/cluster/ksm/customresources/utils.go @@ -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" @@ -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) diff --git a/pkg/collector/corechecks/cluster/ksm/kubernetes_state.go b/pkg/collector/corechecks/cluster/ksm/kubernetes_state.go index 58282ae695a841..cf7d431ad1ecc5 100644 --- a/pkg/collector/corechecks/cluster/ksm/kubernetes_state.go +++ b/pkg/collector/corechecks/cluster/ksm/kubernetes_state.go @@ -271,7 +271,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 @@ -295,8 +297,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) diff --git a/pkg/kubestatemetrics/builder/builder.go b/pkg/kubestatemetrics/builder/builder.go index 6301f09ef019f6..7c054126cb1aac 100644 --- a/pkg/kubestatemetrics/builder/builder.go +++ b/pkg/kubestatemetrics/builder/builder.go @@ -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" @@ -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 @@ -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) @@ -136,8 +128,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.