diff --git a/pkg/collector/corechecks/cluster/ksm/customresources/hpa.go b/pkg/collector/corechecks/cluster/ksm/customresources/hpa.go index e591bbef9a1c2..0a0533b4dcea6 100644 --- a/pkg/collector/corechecks/cluster/ksm/customresources/hpa.go +++ b/pkg/collector/corechecks/cluster/ksm/customresources/hpa.go @@ -10,14 +10,15 @@ package customresources // This file has most of its logic copied from the KSM hpa metric family // generators available at // https://github.com/kubernetes/kube-state-metrics/blob/release-2.4/internal/store/horizontalpodautoscaler.go -// It exists here to provide backwards compatibility with k8s >1.25, as KSM 2.4 -// uses API v2beta2 instead of v2. +// It exists here to provide backwards compatibility with kubernetes versions +// that use autoscaling/v2beta2, as the KSM version that we depend on uses API +// v2 instead of v2beta2. import ( "context" "github.com/DataDog/datadog-agent/pkg/util/kubernetes/apiserver" - autoscaling "k8s.io/api/autoscaling/v2" + autoscaling "k8s.io/api/autoscaling/v2beta2" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" @@ -54,9 +55,9 @@ var ( targetMetricLabels = []string{"metric_name", "metric_target_type"} ) -// NewHorizontalPodAutoscalerV2Factory returns a new HorizontalPodAutoscaler -// metric family generator factory. -func NewHorizontalPodAutoscalerV2Factory(client *apiserver.APIClient) customresource.RegistryFactory { +// NewHorizontalPodAutoscalerV2Beta2Factory returns a new +// HorizontalPodAutoscaler metric family generator factory. +func NewHorizontalPodAutoscalerV2Beta2Factory(client *apiserver.APIClient) customresource.RegistryFactory { return &hpav2Factory{ client: client.Cl, } @@ -363,11 +364,11 @@ func (f *hpav2Factory) ListWatch(customResourceClient interface{}, ns string, fi return &cache.ListWatch{ ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) { opts.FieldSelector = fieldSelector - return client.AutoscalingV2().HorizontalPodAutoscalers(ns).List(context.TODO(), opts) + return client.AutoscalingV2beta2().HorizontalPodAutoscalers(ns).List(context.TODO(), opts) }, WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) { opts.FieldSelector = fieldSelector - return client.AutoscalingV2().HorizontalPodAutoscalers(ns).Watch(context.TODO(), opts) + return client.AutoscalingV2beta2().HorizontalPodAutoscalers(ns).Watch(context.TODO(), opts) }, } } diff --git a/pkg/collector/corechecks/cluster/ksm/kubernetes_state.go b/pkg/collector/corechecks/cluster/ksm/kubernetes_state.go index f5087facb0052..8feec7d6b2ee9 100644 --- a/pkg/collector/corechecks/cluster/ksm/kubernetes_state.go +++ b/pkg/collector/corechecks/cluster/ksm/kubernetes_state.go @@ -431,11 +431,8 @@ func manageResourcesReplacement(c *apiserver.APIClient, factories []customresour "policy/v1": { "PodDisruptionBudget": customresources.NewPodDisruptionBudgetV1Beta1Factory, }, - - // support for newer k8s versions where the newer resources are - // not yet supported by KSM - "autoscaling/v2beta2": { - "HorizontalPodAutoscaler": customresources.NewHorizontalPodAutoscalerV2Factory, + "autoscaling/v2": { + "HorizontalPodAutoscaler": customresources.NewHorizontalPodAutoscalerV2Beta2Factory, }, } diff --git a/releasenotes-dca/ksm-support-hpa-v2beta2-e745b1d2519a7d6c.yaml b/releasenotes-dca/ksm-support-hpa-v2beta2-e745b1d2519a7d6c.yaml new file mode 100644 index 0000000000000..c9458f8c1609a --- /dev/null +++ b/releasenotes-dca/ksm-support-hpa-v2beta2-e745b1d2519a7d6c.yaml @@ -0,0 +1,11 @@ +# Each section from every release note are combined when the +# CHANGELOG.rst is rendered. So the text needs to be worded so that +# it does not depend on any information only available in another +# section. This may mean repeating some details, but each section +# must be readable independently of the other. +# +# Each section note must be formatted as reStructuredText. +--- +fixes: + - | + Fixes the KSM check to support HPA v2beta2 again. This stopped working in Agent v7.44.0. diff --git a/releasenotes/notes/ksm-support-hpa-v2beta2-e745b1d2519a7d6c.yaml b/releasenotes/notes/ksm-support-hpa-v2beta2-e745b1d2519a7d6c.yaml new file mode 100644 index 0000000000000..c9458f8c1609a --- /dev/null +++ b/releasenotes/notes/ksm-support-hpa-v2beta2-e745b1d2519a7d6c.yaml @@ -0,0 +1,11 @@ +# Each section from every release note are combined when the +# CHANGELOG.rst is rendered. So the text needs to be worded so that +# it does not depend on any information only available in another +# section. This may mean repeating some details, but each section +# must be readable independently of the other. +# +# Each section note must be formatted as reStructuredText. +--- +fixes: + - | + Fixes the KSM check to support HPA v2beta2 again. This stopped working in Agent v7.44.0.