From 13ea13a57ddfb043dd1f33eb78a42b9a6a1beb27 Mon Sep 17 00:00:00 2001 From: Joseph Burnett Date: Wed, 10 Nov 2021 09:57:37 +0000 Subject: [PATCH] Use HPA v2 in E2E tests. --- .../custom_metrics_stackdriver_autoscaling.go | 38 +++++++++++++------ .../autoscaling/autoscaling_utils.go | 20 +++++----- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/test/e2e/autoscaling/custom_metrics_stackdriver_autoscaling.go b/test/e2e/autoscaling/custom_metrics_stackdriver_autoscaling.go index a16a0c4e7d0..1732bd1b937 100644 --- a/test/e2e/autoscaling/custom_metrics_stackdriver_autoscaling.go +++ b/test/e2e/autoscaling/custom_metrics_stackdriver_autoscaling.go @@ -24,7 +24,7 @@ import ( gcm "google.golang.org/api/monitoring/v3" "google.golang.org/api/option" appsv1 "k8s.io/api/apps/v1" - as "k8s.io/api/autoscaling/v2beta1" + as "k8s.io/api/autoscaling/v2" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -280,11 +280,11 @@ func (tc *CustomMetricTestCase) Run() { waitForReplicas(tc.deployment.ObjectMeta.Name, tc.framework.Namespace.ObjectMeta.Name, tc.kubeClient, 15*time.Minute, tc.initialReplicas) // Autoscale the deployment - _, err = tc.kubeClient.AutoscalingV2beta1().HorizontalPodAutoscalers(tc.framework.Namespace.ObjectMeta.Name).Create(context.TODO(), tc.hpa, metav1.CreateOptions{}) + _, err = tc.kubeClient.AutoscalingV2().HorizontalPodAutoscalers(tc.framework.Namespace.ObjectMeta.Name).Create(context.TODO(), tc.hpa, metav1.CreateOptions{}) if err != nil { framework.Failf("Failed to create HPA: %v", err) } - defer tc.kubeClient.AutoscalingV2beta1().HorizontalPodAutoscalers(tc.framework.Namespace.ObjectMeta.Name).Delete(context.TODO(), tc.hpa.ObjectMeta.Name, metav1.DeleteOptions{}) + defer tc.kubeClient.AutoscalingV2().HorizontalPodAutoscalers(tc.framework.Namespace.ObjectMeta.Name).Delete(context.TODO(), tc.hpa.ObjectMeta.Name, metav1.DeleteOptions{}) waitForReplicas(tc.deployment.ObjectMeta.Name, tc.framework.Namespace.ObjectMeta.Name, tc.kubeClient, 15*time.Minute, tc.scaledReplicas) } @@ -325,8 +325,13 @@ func podsHPA(namespace string, deploymentName string, metricTargets map[string]i metrics = append(metrics, as.MetricSpec{ Type: as.PodsMetricSourceType, Pods: &as.PodsMetricSource{ - MetricName: metric, - TargetAverageValue: *resource.NewQuantity(target, resource.DecimalSI), + Metric: as.MetricIdentifier{ + Name: metric, + }, + Target: as.MetricTarget{ + Type: as.AverageValueMetricType, + AverageValue: resource.NewQuantity(target, resource.DecimalSI), + }, }, }) } @@ -360,12 +365,17 @@ func objectHPA(namespace string, metricTarget int64) *as.HorizontalPodAutoscaler { Type: as.ObjectMetricSourceType, Object: &as.ObjectMetricSource{ - MetricName: monitoring.CustomMetricName, - Target: as.CrossVersionObjectReference{ + Metric: as.MetricIdentifier{ + Name: monitoring.CustomMetricName, + }, + DescribedObject: as.CrossVersionObjectReference{ Kind: "Pod", Name: stackdriverExporterPod, }, - TargetValue: *resource.NewQuantity(metricTarget, resource.DecimalSI), + Target: as.MetricTarget{ + Type: as.ValueMetricType, + Value: resource.NewQuantity(metricTarget, resource.DecimalSI), + }, }, }, }, @@ -410,14 +420,18 @@ func externalHPA(namespace string, metricTargets map[string]externalMetricTarget metricSpec = as.MetricSpec{ Type: as.ExternalMetricSourceType, External: &as.ExternalMetricSource{ - MetricName: "custom.googleapis.com|" + metric, - MetricSelector: selector, + Metric: as.MetricIdentifier{ + Name: "custom.googleapis.com|" + metric, + Selector: selector, + }, }, } if target.isAverage { - metricSpec.External.TargetAverageValue = resource.NewQuantity(target.value, resource.DecimalSI) + metricSpec.External.Target.Type = as.AverageValueMetricType + metricSpec.External.Target.AverageValue = resource.NewQuantity(target.value, resource.DecimalSI) } else { - metricSpec.External.TargetValue = resource.NewQuantity(target.value, resource.DecimalSI) + metricSpec.External.Target.Type = as.ValueMetricType + metricSpec.External.Target.Value = resource.NewQuantity(target.value, resource.DecimalSI) } metricSpecs = append(metricSpecs, metricSpec) } diff --git a/test/e2e/framework/autoscaling/autoscaling_utils.go b/test/e2e/framework/autoscaling/autoscaling_utils.go index 91ec787d6f1..16a729f2401 100644 --- a/test/e2e/framework/autoscaling/autoscaling_utils.go +++ b/test/e2e/framework/autoscaling/autoscaling_utils.go @@ -24,7 +24,7 @@ import ( "time" autoscalingv1 "k8s.io/api/autoscaling/v1" - autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2" + autoscalingv2 "k8s.io/api/autoscaling/v2" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -628,27 +628,27 @@ func runReplicaSet(config testutils.ReplicaSetConfig) error { // CreateContainerResourceCPUHorizontalPodAutoscaler create a horizontal pod autoscaler with container resource target // for consuming resources. -func CreateContainerResourceCPUHorizontalPodAutoscaler(rc *ResourceConsumer, cpu, minReplicas, maxRepl int32) *autoscalingv2beta2.HorizontalPodAutoscaler { - hpa := &autoscalingv2beta2.HorizontalPodAutoscaler{ +func CreateContainerResourceCPUHorizontalPodAutoscaler(rc *ResourceConsumer, cpu, minReplicas, maxRepl int32) *autoscalingv2.HorizontalPodAutoscaler { + hpa := &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: rc.name, Namespace: rc.nsName, }, - Spec: autoscalingv2beta2.HorizontalPodAutoscalerSpec{ - ScaleTargetRef: autoscalingv2beta2.CrossVersionObjectReference{ + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ APIVersion: rc.kind.GroupVersion().String(), Kind: rc.kind.Kind, Name: rc.name, }, MinReplicas: &minReplicas, MaxReplicas: maxRepl, - Metrics: []autoscalingv2beta2.MetricSpec{ + Metrics: []autoscalingv2.MetricSpec{ { Type: "ContainerResource", - ContainerResource: &autoscalingv2beta2.ContainerResourceMetricSource{ + ContainerResource: &autoscalingv2.ContainerResourceMetricSource{ Name: "cpu", Container: rc.name, - Target: autoscalingv2beta2.MetricTarget{ + Target: autoscalingv2.MetricTarget{ Type: "Utilization", AverageUtilization: &cpu, }, @@ -657,14 +657,14 @@ func CreateContainerResourceCPUHorizontalPodAutoscaler(rc *ResourceConsumer, cpu }, }, } - hpa, errHPA := rc.clientSet.AutoscalingV2beta2().HorizontalPodAutoscalers(rc.nsName).Create(context.TODO(), hpa, metav1.CreateOptions{}) + hpa, errHPA := rc.clientSet.AutoscalingV2().HorizontalPodAutoscalers(rc.nsName).Create(context.TODO(), hpa, metav1.CreateOptions{}) framework.ExpectNoError(errHPA) return hpa } // DeleteContainerResourceHPA delete the horizontalPodAutoscaler for consuming resources. func DeleteContainerResourceHPA(rc *ResourceConsumer, autoscalerName string) { - rc.clientSet.AutoscalingV2beta2().HorizontalPodAutoscalers(rc.nsName).Delete(context.TODO(), autoscalerName, metav1.DeleteOptions{}) + rc.clientSet.AutoscalingV2().HorizontalPodAutoscalers(rc.nsName).Delete(context.TODO(), autoscalerName, metav1.DeleteOptions{}) } //SidecarStatusType type for sidecar status