Skip to content

Commit efbbc3a

Browse files
josephburnettknative-prow-robot
authored andcommitted
Do not modify config-map in autoscale test. (knative#2144)
* Do not modify config-map. * Remove comment about changing config map. * Remove unnecessary variable.
1 parent 7ab275c commit efbbc3a

File tree

2 files changed

+13
-36
lines changed

2 files changed

+13
-36
lines changed

test/e2e/autoscale_test.go

+11-35
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ const (
4040
)
4141

4242
var (
43-
initialScaleToZeroThreshold string
44-
initialScaleToZeroGracePeriod string
43+
scaleToZeroThreshold time.Duration
4544
)
4645

4746
func isDeploymentScaledUp() func(d *v1beta1.Deployment) (bool, error) {
@@ -118,45 +117,22 @@ func generateTraffic(clients *test.Clients, logger *logging.BaseLogger, concurre
118117
return nil
119118
}
120119

121-
func getAutoscalerConfigMap(clients *test.Clients) (*v1.ConfigMap, error) {
122-
return test.GetConfigMap(clients.KubeClient).Get("config-autoscaler", metav1.GetOptions{})
123-
}
124-
125-
func setScaleToZeroThreshold(clients *test.Clients, threshold string, gracePeriod string) error {
126-
configMap, err := getAutoscalerConfigMap(clients)
127-
if err != nil {
128-
return err
129-
}
130-
configMap.Data["scale-to-zero-threshold"] = threshold
131-
configMap.Data["scale-to-zero-grace-period"] = gracePeriod
132-
_, err = test.GetConfigMap(clients.KubeClient).Update(configMap)
133-
return err
134-
}
135-
136120
func setup(t *testing.T, logger *logging.BaseLogger) *test.Clients {
137121
clients := Setup(t)
138122

139-
configMap, err := getAutoscalerConfigMap(clients)
123+
configMap, err := test.GetConfigMap(clients.KubeClient).Get("config-autoscaler", metav1.GetOptions{})
140124
if err != nil {
141-
logger.Infof("Unable to retrieve the autoscale configMap. Assuming a ScaleToZero value of '5m'. %v", err)
142-
initialScaleToZeroThreshold = "5m"
143-
initialScaleToZeroGracePeriod = "2m"
144-
} else {
145-
initialScaleToZeroThreshold = configMap.Data["scale-to-zero-threshold"]
146-
initialScaleToZeroGracePeriod = configMap.Data["scale-to-zero-grace-period"]
125+
t.Fatalf("Unable to get autoscaler config map: %v", err)
147126
}
148-
149-
err = setScaleToZeroThreshold(clients, "1m", "30s")
127+
scaleToZeroThreshold, err = time.ParseDuration(configMap.Data["scale-to-zero-threshold"])
150128
if err != nil {
151-
t.Fatalf(`Unable to set ScaleToZeroThreshold to '1m'. This will
152-
cause the test to time out. Failing fast instead. %v`, err)
129+
t.Fatalf("Unable to parse scale-to-zero-threshold as duration: %v", err)
153130
}
154131

155132
return clients
156133
}
157134

158135
func tearDown(clients *test.Clients, names test.ResourceNames, logger *logging.BaseLogger) {
159-
setScaleToZeroThreshold(clients, initialScaleToZeroThreshold, initialScaleToZeroGracePeriod)
160136
TearDown(clients, names, logger)
161137
}
162138

@@ -232,7 +208,8 @@ func TestAutoscaleUpDownUp(t *testing.T) {
232208
clients.KubeClient,
233209
deploymentName,
234210
isDeploymentScaledUp(),
235-
"DeploymentIsScaledUp")
211+
"DeploymentIsScaledUp",
212+
2*time.Minute)
236213
if err != nil {
237214
logger.Fatalf(`Unable to observe the Deployment named %s scaling
238215
up. %s`, deploymentName, err)
@@ -241,15 +218,13 @@ func TestAutoscaleUpDownUp(t *testing.T) {
241218
logger.Infof(`The autoscaler successfully scales down when devoid of
242219
traffic.`)
243220

244-
logger.Infof(`Manually setting ScaleToZeroThreshold to '1m' to facilitate
245-
faster testing.`)
246-
247221
logger.Infof("Waiting for scale to zero")
248222
err = test.WaitForDeploymentState(
249223
clients.KubeClient,
250224
deploymentName,
251225
isDeploymentScaledToZero(),
252-
"DeploymentScaledToZero")
226+
"DeploymentScaledToZero",
227+
scaleToZeroThreshold+2*time.Minute)
253228
if err != nil {
254229
logger.Fatalf(`Unable to observe the Deployment named %s scaling
255230
down. %s`, deploymentName, err)
@@ -283,7 +258,8 @@ func TestAutoscaleUpDownUp(t *testing.T) {
283258
clients.KubeClient,
284259
deploymentName,
285260
isDeploymentScaledUp(),
286-
"DeploymentScaledUp")
261+
"DeploymentScaledUp",
262+
2*time.Minute)
287263
if err != nil {
288264
logger.Fatalf(`Unable to observe the Deployment named %s scaling
289265
up. %s`, deploymentName, err)

test/kube_checks.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package test
2222
import (
2323
"context"
2424
"fmt"
25+
"time"
2526

2627
pkgTest "github.com/knative/pkg/test"
2728
"go.opencensus.io/trace"
@@ -35,7 +36,7 @@ import (
3536
// from client every interval until inState returns `true` indicating it
3637
// is done, returns an error or timeout. desc will be used to name the metric
3738
// that is emitted to track how long it took for name to get into the state checked by inState.
38-
func WaitForDeploymentState(client *pkgTest.KubeClient, name string, inState func(d *apiv1beta1.Deployment) (bool, error), desc string) error {
39+
func WaitForDeploymentState(client *pkgTest.KubeClient, name string, inState func(d *apiv1beta1.Deployment) (bool, error), desc string, timeout time.Duration) error {
3940
d := client.Kube.ExtensionsV1beta1().Deployments(ServingNamespace)
4041
metricName := fmt.Sprintf("WaitForDeploymentState/%s/%s", name, desc)
4142
_, span := trace.StartSpan(context.Background(), metricName)

0 commit comments

Comments
 (0)