mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2024-12-22 02:56:03 +00:00
Fix missing AverageValue on HPA (#769)
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
This commit is contained in:
parent
ca9031228b
commit
c26604c36b
@ -320,6 +320,10 @@ func highestActiveSchedule(hpa *autoscalingv2.HorizontalPodAutoscaler, activeSch
|
|||||||
|
|
||||||
scheduleName := metric.Object.DescribedObject.Name
|
scheduleName := metric.Object.DescribedObject.Name
|
||||||
|
|
||||||
|
if metric.Object.Target.AverageValue == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
target := int64(metric.Object.Target.AverageValue.MilliValue() / 1000)
|
target := int64(metric.Object.Target.AverageValue.MilliValue() / 1000)
|
||||||
if target == 0 {
|
if target == 0 {
|
||||||
continue
|
continue
|
||||||
|
@ -350,6 +350,12 @@ func TestAdjustScaling(t *testing.T) {
|
|||||||
desiredReplicas: 90,
|
desiredReplicas: 90,
|
||||||
targetValue: 10, // 1000/10 = 100
|
targetValue: 10, // 1000/10 = 100
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
msg: "invalid HPA should not do any adjustment",
|
||||||
|
currentReplicas: 95,
|
||||||
|
desiredReplicas: 95,
|
||||||
|
targetValue: 0, // this is treated as invalid in the test, thus the HPA is ingored and no adjustment happens.
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.msg, func(t *testing.T) {
|
t.Run(tc.msg, func(t *testing.T) {
|
||||||
kubeClient := fake.NewSimpleClientset()
|
kubeClient := fake.NewSimpleClientset()
|
||||||
@ -419,8 +425,7 @@ func TestAdjustScaling(t *testing.T) {
|
|||||||
Name: "schedule-1",
|
Name: "schedule-1",
|
||||||
},
|
},
|
||||||
Target: v2.MetricTarget{
|
Target: v2.MetricTarget{
|
||||||
Type: v2.AverageValueMetricType,
|
Type: v2.AverageValueMetricType,
|
||||||
AverageValue: resource.NewQuantity(tc.targetValue, resource.DecimalSI),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -428,6 +433,10 @@ func TestAdjustScaling(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tc.targetValue != 0 {
|
||||||
|
hpa.Spec.Metrics[0].Object.Target.AverageValue = resource.NewQuantity(tc.targetValue, resource.DecimalSI)
|
||||||
|
}
|
||||||
|
|
||||||
hpa, err = kubeClient.AutoscalingV2().HorizontalPodAutoscalers("default").Create(context.Background(), hpa, metav1.CreateOptions{})
|
hpa, err = kubeClient.AutoscalingV2().HorizontalPodAutoscalers("default").Create(context.Background(), hpa, metav1.CreateOptions{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user