Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update on scaler limited to Max #2446

Merged
merged 8 commits into from
Jan 27, 2022
Merged
8 changes: 7 additions & 1 deletion pkg/fleetautoscalers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,13 @@ func (c *Controller) updateStatus(ctx context.Context, fas *autoscalingv1.FleetA

if !apiequality.Semantic.DeepEqual(fas.Status, fasCopy.Status) {
if scalingLimited {
c.recorder.Eventf(fas, corev1.EventTypeWarning, "ScalingLimited", "Scaling fleet %s was limited to maximum size of %d", fas.Spec.FleetName, desiredReplicas)
// scalingLimited indicates that the calculated scale would be above or below the range defined by MinReplicas and MaxReplicas
msg := "Scaling fleet %s was limited to minimum size of %d"
if currentReplicas > desiredReplicas {
msg = "Scaling fleet %s was limited to maximum size of %d"
}

c.recorder.Eventf(fas, corev1.EventTypeWarning, "ScalingLimited", msg, fas.Spec.FleetName, desiredReplicas)
}

_, err := c.fleetAutoscalerGetter.FleetAutoscalers(fas.ObjectMeta.Namespace).UpdateStatus(ctx, fasCopy, metav1.UpdateOptions{})
Expand Down
18 changes: 18 additions & 0 deletions pkg/fleetautoscalers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,24 @@ func TestControllerUpdateStatus(t *testing.T) {
assert.Nil(t, err)
agtesting.AssertEventContains(t, m.FakeRecorder.Events, "ScalingLimited")
})

t.Run("update with a scaling limit with minimum", func(t *testing.T) {
c, m := newFakeController()
fas, _ := defaultFixtures()

err := c.updateStatus(context.Background(), fas, 1, 3, true, true)
assert.Nil(t, err)
agtesting.AssertEventContains(t, m.FakeRecorder.Events, "limited to minimum size of 3")
})

t.Run("update with a scaling limit with maximum", func(t *testing.T) {
c, m := newFakeController()
fas, _ := defaultFixtures()

err := c.updateStatus(context.Background(), fas, 12, 10, true, true)
assert.Nil(t, err)
agtesting.AssertEventContains(t, m.FakeRecorder.Events, "limited to maximum size of 10")
})
}

func TestControllerUpdateStatusUnableToScale(t *testing.T) {
Expand Down