Skip to content

Commit c4a1e08

Browse files
authored
Update HPA to autoscaling/v2 apiVersion (#551)
1 parent 61e0336 commit c4a1e08

24 files changed

+58
-63
lines changed

README.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Here's an example of a `HorizontalPodAutoscaler` resource configured to get
1717
`requests-per-second` metrics from each pod of the deployment `myapp`.
1818

1919
```yaml
20-
apiVersion: autoscaling/v2beta2
20+
apiVersion: autoscaling/v2
2121
kind: HorizontalPodAutoscaler
2222
metadata:
2323
name: myapp-hpa
@@ -54,10 +54,8 @@ policy](https://kubernetes.io/docs/setup/release/version-skew-policy/) offered
5454
for Kubernetes, this project aims to support the latest three minor releases of
5555
Kubernetes.
5656

57-
The default supported API is `autoscaling/v2beta2` (available since `v1.12`).
58-
This API MUST be available in the cluster which is the default. However for
59-
GKE, this requires GKE v1.15.7 according to this [GKE
60-
Issue](https://issuetracker.google.com/issues/135624588).
57+
The default supported API is `autoscaling/v2` (available since `v1.23`).
58+
This API MUST be available in the cluster which is the default.
6159

6260
## Building
6361

@@ -99,7 +97,7 @@ This is an example of using the pod collector to collect metrics from a json
9997
metrics endpoint of each pod matched by the HPA.
10098

10199
```yaml
102-
apiVersion: autoscaling/v2beta2
100+
apiVersion: autoscaling/v2
103101
kind: HorizontalPodAutoscaler
104102
metadata:
105103
name: myapp-hpa
@@ -219,7 +217,7 @@ with the result of the query.
219217
This allows having multiple prometheus queries associated with a single HPA.
220218

221219
```yaml
222-
apiVersion: autoscaling/v2beta2
220+
apiVersion: autoscaling/v2
223221
kind: HorizontalPodAutoscaler
224222
metadata:
225223
name: myapp-hpa
@@ -331,7 +329,7 @@ This is an example of an HPA that will scale based on `requests-per-second` for
331329
an ingress called `myapp`.
332330

333331
```yaml
334-
apiVersion: autoscaling/v2beta2
332+
apiVersion: autoscaling/v2
335333
kind: HorizontalPodAutoscaler
336334
metadata:
337335
name: myapp-hpa
@@ -365,7 +363,7 @@ This is an example of an HPA that will scale based on `requests-per-second` for
365363
a routegroup called `myapp`.
366364

367365
```yaml
368-
apiVersion: autoscaling/v2beta2
366+
apiVersion: autoscaling/v2
369367
kind: HorizontalPodAutoscaler
370368
metadata:
371369
name: myapp-hpa
@@ -426,7 +424,7 @@ the query name which will be associated with the result of the query. This
426424
allows having multiple flux queries associated with a single HPA.
427425

428426
```yaml
429-
apiVersion: autoscaling/v2beta2
427+
apiVersion: autoscaling/v2
430428
kind: HorizontalPodAutoscaler
431429
metadata:
432430
name: myapp-hpa
@@ -514,7 +512,7 @@ This is an example of an HPA that will scale based on the length of an SQS
514512
queue.
515513

516514
```yaml
517-
apiVersion: autoscaling/v2beta2
515+
apiVersion: autoscaling/v2
518516
kind: HorizontalPodAutoscaler
519517
metadata:
520518
name: myapp-hpa
@@ -566,7 +564,7 @@ This is an example of an HPA that will scale based on the specified value
566564
exposed by a ZMON check with id `1234`.
567565

568566
```yaml
569-
apiVersion: autoscaling/v2beta2
567+
apiVersion: autoscaling/v2
570568
kind: HorizontalPodAutoscaler
571569
metadata:
572570
name: myapp-hpa
@@ -663,7 +661,7 @@ This is an example of using the HTTP collector to collect metrics from a json
663661
metrics endpoint specified in the annotations.
664662

665663
```yaml
666-
apiVersion: autoscaling/v2beta2
664+
apiVersion: autoscaling/v2
667665
kind: HorizontalPodAutoscaler
668666
metadata:
669667
name: myapp-hpa
@@ -830,7 +828,7 @@ An HPA can reference the deployed `ClusterScalingSchedule` object as
830828
this example:
831829

832830
```yaml
833-
apiVersion: autoscaling/v2beta2
831+
apiVersion: autoscaling/v2
834832
kind: HorizontalPodAutoscaler
835833
metadata:
836834
name: "myapp-hpa"

pkg/annotations/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66
"time"
77

8-
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
8+
autoscalingv2 "k8s.io/api/autoscaling/v2"
99
)
1010

1111
const (

pkg/annotations/parser_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"testing"
55

66
"github.com/stretchr/testify/require"
7-
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
7+
autoscalingv2 "k8s.io/api/autoscaling/v2"
88
)
99

1010
func TestParser(t *testing.T) {

pkg/collector/aws_collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/aws/aws-sdk-go/aws/session"
1010
"github.com/aws/aws-sdk-go/service/sqs"
1111
"github.com/aws/aws-sdk-go/service/sqs/sqsiface"
12-
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
12+
autoscalingv2 "k8s.io/api/autoscaling/v2"
1313
"k8s.io/apimachinery/pkg/api/resource"
1414
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1515
"k8s.io/metrics/pkg/apis/external_metrics"

pkg/collector/collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
log "github.com/sirupsen/logrus"
88
"github.com/zalando-incubator/kube-metrics-adapter/pkg/annotations"
9-
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
9+
autoscalingv2 "k8s.io/api/autoscaling/v2"
1010
"k8s.io/metrics/pkg/apis/custom_metrics"
1111
"k8s.io/metrics/pkg/apis/external_metrics"
1212
)

pkg/collector/collector_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"time"
66

77
"github.com/stretchr/testify/require"
8-
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
8+
autoscalingv2 "k8s.io/api/autoscaling/v2"
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1010
)
1111

pkg/collector/http_collector.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/zalando-incubator/kube-metrics-adapter/pkg/collector/httpmetrics"
99

10-
"k8s.io/api/autoscaling/v2beta2"
10+
autoscalingv2 "k8s.io/api/autoscaling/v2"
1111
"k8s.io/apimachinery/pkg/api/resource"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1313
"k8s.io/metrics/pkg/apis/external_metrics"
@@ -26,7 +26,7 @@ func NewHTTPCollectorPlugin() (*HTTPCollectorPlugin, error) {
2626
return &HTTPCollectorPlugin{}, nil
2727
}
2828

29-
func (p *HTTPCollectorPlugin) NewCollector(hpa *v2beta2.HorizontalPodAutoscaler, config *MetricConfig, interval time.Duration) (Collector, error) {
29+
func (p *HTTPCollectorPlugin) NewCollector(hpa *autoscalingv2.HorizontalPodAutoscaler, config *MetricConfig, interval time.Duration) (Collector, error) {
3030
collector := &HTTPCollector{
3131
namespace: hpa.Namespace,
3232
}
@@ -73,9 +73,9 @@ type HTTPCollector struct {
7373
endpoint *url.URL
7474
interval time.Duration
7575
namespace string
76-
metricType v2beta2.MetricSourceType
76+
metricType autoscalingv2.MetricSourceType
7777
metricsGetter *httpmetrics.JSONPathMetricsGetter
78-
metric v2beta2.MetricIdentifier
78+
metric autoscalingv2.MetricIdentifier
7979
}
8080

8181
func (c *HTTPCollector) GetMetrics() ([]CollectedMetric, error) {

pkg/collector/http_collector_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/require"
10-
"k8s.io/api/autoscaling/v2beta2"
11-
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
10+
autoscalingv2 "k8s.io/api/autoscaling/v2"
1211
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1312
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1413
)
@@ -81,8 +80,8 @@ func TestHTTPCollector(t *testing.T) {
8180
func makeTestHTTPCollectorConfig(endpoint, aggregator string) *MetricConfig {
8281
config := &MetricConfig{
8382
MetricTypeName: MetricTypeName{
84-
Type: v2beta2.ExternalMetricSourceType,
85-
Metric: v2beta2.MetricIdentifier{
83+
Type: autoscalingv2.ExternalMetricSourceType,
84+
Metric: autoscalingv2.MetricIdentifier{
8685
Name: "test-metric",
8786
Selector: &v1.LabelSelector{
8887
MatchLabels: map[string]string{"type": HTTPJSONPathType},

pkg/collector/influxdb_collector.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
"time"
77

88
"github.com/influxdata/influxdb-client-go"
9-
"k8s.io/api/autoscaling/v2beta2"
10-
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
9+
autoscalingv2 "k8s.io/api/autoscaling/v2"
1110
"k8s.io/apimachinery/pkg/api/resource"
1211
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1312
"k8s.io/client-go/kubernetes"
@@ -39,7 +38,7 @@ func NewInfluxDBCollectorPlugin(client kubernetes.Interface, address, token, org
3938
}, nil
4039
}
4140

42-
func (p *InfluxDBCollectorPlugin) NewCollector(hpa *v2beta2.HorizontalPodAutoscaler, config *MetricConfig, interval time.Duration) (Collector, error) {
41+
func (p *InfluxDBCollectorPlugin) NewCollector(hpa *autoscalingv2.HorizontalPodAutoscaler, config *MetricConfig, interval time.Duration) (Collector, error) {
4342
return NewInfluxDBCollector(hpa, p.address, p.token, p.org, config, interval)
4443
}
4544

@@ -56,7 +55,7 @@ type InfluxDBCollector struct {
5655
namespace string
5756
}
5857

59-
func NewInfluxDBCollector(hpa *v2beta2.HorizontalPodAutoscaler, address string, token string, org string, config *MetricConfig, interval time.Duration) (*InfluxDBCollector, error) {
58+
func NewInfluxDBCollector(hpa *autoscalingv2.HorizontalPodAutoscaler, address string, token string, org string, config *MetricConfig, interval time.Duration) (*InfluxDBCollector, error) {
6059
collector := &InfluxDBCollector{
6160
interval: interval,
6261
metric: config.Metric,

pkg/collector/influxdb_collector_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import (
55
"testing"
66
"time"
77

8-
"k8s.io/api/autoscaling/v2beta2"
9-
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
8+
autoscalingv2 "k8s.io/api/autoscaling/v2"
109
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1110
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1211
)
@@ -20,8 +19,8 @@ func TestInfluxDBCollector_New(t *testing.T) {
2019
t.Run("simple", func(t *testing.T) {
2120
m := &MetricConfig{
2221
MetricTypeName: MetricTypeName{
23-
Type: v2beta2.ExternalMetricSourceType,
24-
Metric: v2beta2.MetricIdentifier{
22+
Type: autoscalingv2.ExternalMetricSourceType,
23+
Metric: autoscalingv2.MetricIdentifier{
2524
Name: "flux-query",
2625
// This is actually useless, because the selector should be flattened in Config when parsing.
2726
Selector: &v1.LabelSelector{
@@ -59,8 +58,8 @@ func TestInfluxDBCollector_New(t *testing.T) {
5958
t.Run("override params", func(t *testing.T) {
6059
m := &MetricConfig{
6160
MetricTypeName: MetricTypeName{
62-
Type: v2beta2.ExternalMetricSourceType,
63-
Metric: v2beta2.MetricIdentifier{
61+
Type: autoscalingv2.ExternalMetricSourceType,
62+
Metric: autoscalingv2.MetricIdentifier{
6463
Name: "flux-query",
6564
Selector: &v1.LabelSelector{
6665
MatchLabels: map[string]string{
@@ -107,15 +106,15 @@ func TestInfluxDBCollector_New(t *testing.T) {
107106
{
108107
name: "object metric",
109108
mTypeName: MetricTypeName{
110-
Type: v2beta2.ObjectMetricSourceType,
109+
Type: autoscalingv2.ObjectMetricSourceType,
111110
},
112111
errorStartsWith: "InfluxDB does not support object",
113112
},
114113
{
115114
name: "no selector",
116115
mTypeName: MetricTypeName{
117-
Type: v2beta2.ExternalMetricSourceType,
118-
Metric: v2beta2.MetricIdentifier{
116+
Type: autoscalingv2.ExternalMetricSourceType,
117+
Metric: autoscalingv2.MetricIdentifier{
119118
Name: "flux-query",
120119
},
121120
},
@@ -130,8 +129,8 @@ func TestInfluxDBCollector_New(t *testing.T) {
130129
{
131130
name: "referencing non-existing query",
132131
mTypeName: MetricTypeName{
133-
Type: v2beta2.ExternalMetricSourceType,
134-
Metric: v2beta2.MetricIdentifier{
132+
Type: autoscalingv2.ExternalMetricSourceType,
133+
Metric: autoscalingv2.MetricIdentifier{
135134
Name: "flux-query",
136135
},
137136
},

0 commit comments

Comments
 (0)