mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #106315 from josephburnett/e2e-v2
Use HPA v2 in E2E tests.
This commit is contained in:
commit
8d301e97f7
@ -24,7 +24,7 @@ import (
|
|||||||
gcm "google.golang.org/api/monitoring/v3"
|
gcm "google.golang.org/api/monitoring/v3"
|
||||||
"google.golang.org/api/option"
|
"google.golang.org/api/option"
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
as "k8s.io/api/autoscaling/v2beta1"
|
as "k8s.io/api/autoscaling/v2"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
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)
|
waitForReplicas(tc.deployment.ObjectMeta.Name, tc.framework.Namespace.ObjectMeta.Name, tc.kubeClient, 15*time.Minute, tc.initialReplicas)
|
||||||
|
|
||||||
// Autoscale the deployment
|
// 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 {
|
if err != nil {
|
||||||
framework.Failf("Failed to create HPA: %v", err)
|
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)
|
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{
|
metrics = append(metrics, as.MetricSpec{
|
||||||
Type: as.PodsMetricSourceType,
|
Type: as.PodsMetricSourceType,
|
||||||
Pods: &as.PodsMetricSource{
|
Pods: &as.PodsMetricSource{
|
||||||
MetricName: metric,
|
Metric: as.MetricIdentifier{
|
||||||
TargetAverageValue: *resource.NewQuantity(target, resource.DecimalSI),
|
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,
|
Type: as.ObjectMetricSourceType,
|
||||||
Object: &as.ObjectMetricSource{
|
Object: &as.ObjectMetricSource{
|
||||||
MetricName: monitoring.CustomMetricName,
|
Metric: as.MetricIdentifier{
|
||||||
Target: as.CrossVersionObjectReference{
|
Name: monitoring.CustomMetricName,
|
||||||
|
},
|
||||||
|
DescribedObject: as.CrossVersionObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Name: stackdriverExporterPod,
|
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{
|
metricSpec = as.MetricSpec{
|
||||||
Type: as.ExternalMetricSourceType,
|
Type: as.ExternalMetricSourceType,
|
||||||
External: &as.ExternalMetricSource{
|
External: &as.ExternalMetricSource{
|
||||||
MetricName: "custom.googleapis.com|" + metric,
|
Metric: as.MetricIdentifier{
|
||||||
MetricSelector: selector,
|
Name: "custom.googleapis.com|" + metric,
|
||||||
|
Selector: selector,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if target.isAverage {
|
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 {
|
} 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)
|
metricSpecs = append(metricSpecs, metricSpec)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
||||||
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
|
autoscalingv2 "k8s.io/api/autoscaling/v2"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
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
|
// CreateContainerResourceCPUHorizontalPodAutoscaler create a horizontal pod autoscaler with container resource target
|
||||||
// for consuming resources.
|
// for consuming resources.
|
||||||
func CreateContainerResourceCPUHorizontalPodAutoscaler(rc *ResourceConsumer, cpu, minReplicas, maxRepl int32) *autoscalingv2beta2.HorizontalPodAutoscaler {
|
func CreateContainerResourceCPUHorizontalPodAutoscaler(rc *ResourceConsumer, cpu, minReplicas, maxRepl int32) *autoscalingv2.HorizontalPodAutoscaler {
|
||||||
hpa := &autoscalingv2beta2.HorizontalPodAutoscaler{
|
hpa := &autoscalingv2.HorizontalPodAutoscaler{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: rc.name,
|
Name: rc.name,
|
||||||
Namespace: rc.nsName,
|
Namespace: rc.nsName,
|
||||||
},
|
},
|
||||||
Spec: autoscalingv2beta2.HorizontalPodAutoscalerSpec{
|
Spec: autoscalingv2.HorizontalPodAutoscalerSpec{
|
||||||
ScaleTargetRef: autoscalingv2beta2.CrossVersionObjectReference{
|
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
|
||||||
APIVersion: rc.kind.GroupVersion().String(),
|
APIVersion: rc.kind.GroupVersion().String(),
|
||||||
Kind: rc.kind.Kind,
|
Kind: rc.kind.Kind,
|
||||||
Name: rc.name,
|
Name: rc.name,
|
||||||
},
|
},
|
||||||
MinReplicas: &minReplicas,
|
MinReplicas: &minReplicas,
|
||||||
MaxReplicas: maxRepl,
|
MaxReplicas: maxRepl,
|
||||||
Metrics: []autoscalingv2beta2.MetricSpec{
|
Metrics: []autoscalingv2.MetricSpec{
|
||||||
{
|
{
|
||||||
Type: "ContainerResource",
|
Type: "ContainerResource",
|
||||||
ContainerResource: &autoscalingv2beta2.ContainerResourceMetricSource{
|
ContainerResource: &autoscalingv2.ContainerResourceMetricSource{
|
||||||
Name: "cpu",
|
Name: "cpu",
|
||||||
Container: rc.name,
|
Container: rc.name,
|
||||||
Target: autoscalingv2beta2.MetricTarget{
|
Target: autoscalingv2.MetricTarget{
|
||||||
Type: "Utilization",
|
Type: "Utilization",
|
||||||
AverageUtilization: &cpu,
|
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)
|
framework.ExpectNoError(errHPA)
|
||||||
return hpa
|
return hpa
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteContainerResourceHPA delete the horizontalPodAutoscaler for consuming resources.
|
// DeleteContainerResourceHPA delete the horizontalPodAutoscaler for consuming resources.
|
||||||
func DeleteContainerResourceHPA(rc *ResourceConsumer, autoscalerName string) {
|
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
|
//SidecarStatusType type for sidecar status
|
||||||
|
Loading…
Reference in New Issue
Block a user