Skip to content

Commit

Permalink
Merge pull request #106315 from josephburnett/e2e-v2
Browse files Browse the repository at this point in the history
Use HPA v2 in E2E tests.
  • Loading branch information
k8s-ci-robot committed Nov 15, 2021
2 parents 1e6f3b5 + 13ea13a commit 8d301e9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
38 changes: 26 additions & 12 deletions test/e2e/autoscaling/custom_metrics_stackdriver_autoscaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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),
},
},
})
}
Expand Down Expand Up @@ -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),
},
},
},
},
Expand Down Expand Up @@ -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)
}
Expand Down
20 changes: 10 additions & 10 deletions test/e2e/framework/autoscaling/autoscaling_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
},
Expand All @@ -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
Expand Down

0 comments on commit 8d301e9

Please sign in to comment.