Skip to content

Commit

Permalink
Add e2e test for HPA deletion at downscaling (#539)
Browse files Browse the repository at this point in the history
* Add e2e test for HPA deletion at downscaling

* check that the HPA with traffic is not deleted

* check if deleted HPA is created if has traffic

---------

Co-authored-by: Milad Barazandeh <[email protected]>
  • Loading branch information
miladbarazandeh and Milad Barazandeh authored Oct 25, 2023
1 parent 424c532 commit 08354e8
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions cmd/e2e/generated_autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"testing"
"time"

"github.com/stretchr/testify/require"
zv1 "github.com/zalando-incubator/stackset-controller/pkg/apis/zalando.org/v1"
Expand Down Expand Up @@ -64,3 +65,63 @@ func TestGenerateAutoscaler(t *testing.T) {
require.EqualValues(t, v2beta1.ResourceMetricSourceType, metric3.Type)
require.EqualValues(t, 50, *metric3.Resource.Target.AverageUtilization)
}

func TestAutoscalerWithoutTraffic(t *testing.T) {
t.Parallel()
stacksetName := "autoscaler-without-traffic"
metrics := []zv1.AutoscalerMetrics{
makeCPUAutoscalerMetrics(50),
}
factory := NewTestStacksetSpecFactory(stacksetName).Ingress().Autoscaler(1, 3, metrics).StackGC(1, 30)
firstStack := "v1"
fullFirstStack := fmt.Sprintf("%s-%s", stacksetName, firstStack)
spec := factory.Create(firstStack)
err := createStackSet(stacksetName, 0, spec)
require.NoError(t, err)
_, err = waitForStack(t, stacksetName, firstStack)
require.NoError(t, err)
_, err = waitForHPA(t, fullFirstStack)
require.NoError(t, err)

secondStack := "v2"
fullSecondStack := fmt.Sprintf("%s-%s", stacksetName, secondStack)
spec = factory.Create(secondStack)
err = updateStackset(stacksetName, spec)
require.NoError(t, err)
_, err = waitForStack(t, stacksetName, secondStack)
require.NoError(t, err)
_, err = waitForHPA(t, fullSecondStack)
require.NoError(t, err)

desiredTraffic := map[string]float64{
fullFirstStack: 100,
fullSecondStack: 0,
}

err = setDesiredTrafficWeightsStackset(stacksetName, desiredTraffic)
require.NoError(t, err)
err = trafficWeightsUpdatedStackset(t, stacksetName, weightKindActual, desiredTraffic, nil).withTimeout(time.Minute * 1).await()
require.NoError(t, err)

err = resourceDeleted(t, "hpa", fullSecondStack, hpaInterface()).withTimeout(time.Minute * 1).await()
require.NoError(t, err)

_, err = waitForHPA(t, fullFirstStack)
require.NoError(t, err)

// Switch traffic to 50 - 50
desiredTraffic = map[string]float64{
fullFirstStack: 50,
fullSecondStack: 50,
}

err = setDesiredTrafficWeightsStackset(stacksetName, desiredTraffic)
require.NoError(t, err)
err = trafficWeightsUpdatedStackset(t, stacksetName, weightKindActual, desiredTraffic, nil).withTimeout(time.Minute * 1).await()
require.NoError(t, err)
_, err = waitForHPA(t, fullFirstStack)
require.NoError(t, err)

_, err = waitForHPA(t, fullSecondStack)
require.NoError(t, err)
}

0 comments on commit 08354e8

Please sign in to comment.