mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Add tests for handling scaling on unavailable metrics
Add three tests for handling invalid metrics when scaling on multiple metrics - one for scaling up successfully (new behaviour) and two for ensuring we don't scale down (existing behaviour).
This commit is contained in:
parent
f780ac028b
commit
ee4dbbcbff
@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
||||||
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
|
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/meta/testrestmapper"
|
"k8s.io/apimachinery/pkg/api/meta/testrestmapper"
|
||||||
"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"
|
||||||
@ -2668,4 +2668,98 @@ func TestNormalizeDesiredReplicas(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestScaleUpOneMetricEmpty(t *testing.T) {
|
||||||
|
tc := testCase{
|
||||||
|
minReplicas: 2,
|
||||||
|
maxReplicas: 6,
|
||||||
|
initialReplicas: 3,
|
||||||
|
expectedDesiredReplicas: 4,
|
||||||
|
CPUTarget: 30,
|
||||||
|
verifyCPUCurrent: true,
|
||||||
|
metricsTarget: []autoscalingv2.MetricSpec{
|
||||||
|
{
|
||||||
|
Type: autoscalingv2.ExternalMetricSourceType,
|
||||||
|
External: &autoscalingv2.ExternalMetricSource{
|
||||||
|
Metric: autoscalingv2.MetricIdentifier{
|
||||||
|
Name: "qps",
|
||||||
|
Selector: &metav1.LabelSelector{},
|
||||||
|
},
|
||||||
|
Target: autoscalingv2.MetricTarget{
|
||||||
|
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
reportedLevels: []uint64{300, 400, 500},
|
||||||
|
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
|
||||||
|
}
|
||||||
|
_, _, _, testEMClient, _ := tc.prepareTestClient(t)
|
||||||
|
testEMClient.PrependReactor("list", "*", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
||||||
|
return true, &emapi.ExternalMetricValueList{}, fmt.Errorf("something went wrong")
|
||||||
|
})
|
||||||
|
tc.testEMClient = testEMClient
|
||||||
|
tc.runTest(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoScaleDownOneMetricInvalid(t *testing.T) {
|
||||||
|
tc := testCase{
|
||||||
|
minReplicas: 2,
|
||||||
|
maxReplicas: 6,
|
||||||
|
initialReplicas: 5,
|
||||||
|
expectedDesiredReplicas: 5,
|
||||||
|
CPUTarget: 50,
|
||||||
|
metricsTarget: []autoscalingv2.MetricSpec{
|
||||||
|
{
|
||||||
|
Type: "CheddarCheese",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
reportedLevels: []uint64{100, 300, 500, 250, 250},
|
||||||
|
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
|
||||||
|
useMetricsAPI: true,
|
||||||
|
expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{
|
||||||
|
{Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededGetScale"},
|
||||||
|
{Type: autoscalingv1.ScalingActive, Status: v1.ConditionFalse, Reason: "InvalidMetricSourceType"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tc.runTest(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoScaleDownOneMetricEmpty(t *testing.T) {
|
||||||
|
tc := testCase{
|
||||||
|
minReplicas: 2,
|
||||||
|
maxReplicas: 6,
|
||||||
|
initialReplicas: 5,
|
||||||
|
expectedDesiredReplicas: 5,
|
||||||
|
CPUTarget: 50,
|
||||||
|
metricsTarget: []autoscalingv2.MetricSpec{
|
||||||
|
{
|
||||||
|
Type: autoscalingv2.ExternalMetricSourceType,
|
||||||
|
External: &autoscalingv2.ExternalMetricSource{
|
||||||
|
Metric: autoscalingv2.MetricIdentifier{
|
||||||
|
Name: "qps",
|
||||||
|
Selector: &metav1.LabelSelector{},
|
||||||
|
},
|
||||||
|
Target: autoscalingv2.MetricTarget{
|
||||||
|
Value: resource.NewMilliQuantity(1000, resource.DecimalSI),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
reportedLevels: []uint64{100, 300, 500, 250, 250},
|
||||||
|
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
|
||||||
|
useMetricsAPI: true,
|
||||||
|
expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{
|
||||||
|
{Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededGetScale"},
|
||||||
|
{Type: autoscalingv1.ScalingActive, Status: v1.ConditionFalse, Reason: "FailedGetExternalMetric"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_, _, _, testEMClient, _ := tc.prepareTestClient(t)
|
||||||
|
testEMClient.PrependReactor("list", "*", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
||||||
|
return true, &emapi.ExternalMetricValueList{}, fmt.Errorf("something went wrong")
|
||||||
|
})
|
||||||
|
tc.testEMClient = testEMClient
|
||||||
|
tc.runTest(t)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: add more tests
|
// TODO: add more tests
|
||||||
|
Loading…
Reference in New Issue
Block a user