Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/controller/scheduledscaling/scheduled_scaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var (
type now func() time.Time

type scalingScheduleStore interface {
List() []interface{}
List() []any
}

type Controller struct {
Expand Down Expand Up @@ -325,7 +325,7 @@ func highestActiveSchedule(hpa *autoscalingv2.HorizontalPodAutoscaler, activeSch
continue
}

target := int64(metric.Object.Target.AverageValue.MilliValue() / 1000)
target := float64(metric.Object.Target.AverageValue.MilliValue()) / 1000.0
if target == 0 {
continue
}
Expand All @@ -338,10 +338,10 @@ func highestActiveSchedule(hpa *autoscalingv2.HorizontalPodAutoscaler, activeSch
value = activeSchedules[scheduleName]
}

expected := int64(math.Ceil(float64(value) / float64(target)))
expected := int64(math.Ceil(float64(value) / target))
if expected > highestExpected {
highestExpected = expected
usageRatio = float64(value) / (float64(target) * float64(currentReplicas))
usageRatio = float64(value) / (target * float64(currentReplicas))
highestObject = metric.Object.DescribedObject
}
}
Expand Down
24 changes: 17 additions & 7 deletions pkg/controller/scheduledscaling/scheduled_scaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,35 +336,42 @@ func TestAdjustScaling(t *testing.T) {
msg string
currentReplicas int32
desiredReplicas int32
targetValue int64
targetValue string
scheduleTarget int64
}{
{
msg: "current less than 10%% below desired (target 10000)",
currentReplicas: 28, // 7.1% increase to desired
desiredReplicas: 31,
targetValue: 333, // 10000/333 ~= 31
targetValue: "333", // 10000/333 ~= 31
scheduleTarget: 10000,
},
{
msg: "current less than 10%% below desired",
currentReplicas: 95, // 5.3% increase to desired
desiredReplicas: 100,
targetValue: 10, // 1000/10 = 100
targetValue: "10", // 1000/10 = 100
scheduleTarget: 1000,
},
{
msg: "current more than 10%% below desired, no adjustment",
currentReplicas: 90, // 11% increase to desired
desiredReplicas: 90,
targetValue: 10, // 1000/10 = 100
targetValue: "10", // 1000/10 = 100
scheduleTarget: 1000,
},
{
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.
targetValue: "", // this is treated as invalid in the test, thus the HPA is ingored and no adjustment happens.
scheduleTarget: 1000,
},
{
msg: "handle milivalue as targetValue",
currentReplicas: 90, // 5.8% increase to desired
desiredReplicas: 96,
targetValue: "10500m", // 1000/10.5 ~= 96
scheduleTarget: 1000,
},
} {
Expand Down Expand Up @@ -444,8 +451,11 @@ func TestAdjustScaling(t *testing.T) {
},
}

if tc.targetValue != 0 {
hpa.Spec.Metrics[0].Object.Target.AverageValue = resource.NewQuantity(tc.targetValue, resource.DecimalSI)
if tc.targetValue != "" {
quantity, err := resource.ParseQuantity(tc.targetValue)
require.NoError(t, err)

hpa.Spec.Metrics[0].Object.Target.AverageValue = &quantity
}

hpa, err = kubeClient.AutoscalingV2().HorizontalPodAutoscalers("default").Create(context.Background(), hpa, metav1.CreateOptions{})
Expand Down