Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[corechecks/ksm] Support HPA v2beta2 again #18580

Merged
merged 4 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions pkg/collector/corechecks/cluster/ksm/customresources/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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)
},
}
}
Expand Down
7 changes: 2 additions & 5 deletions pkg/collector/corechecks/cluster/ksm/kubernetes_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Comment on lines +434 to +435
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also support v2beta1 ? and v1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could address that separately if needed. This PR only fixes the regression introduced in 7.44.

Just to clarify, metrics for HPA v2beta1 objects are still reported in clusters that support v2beta2.

},
}

Expand Down
11 changes: 11 additions & 0 deletions releasenotes-dca/ksm-support-hpa-v2beta2-e745b1d2519a7d6c.yaml
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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.
Loading