From 2c2ec1e9610859aa126dbb1374349c3ddf813af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Suszy=C5=84ski?= Date: Thu, 20 Aug 2020 22:42:05 +0200 Subject: [PATCH] Flags to configure eventing upgrade tests forwarder (ksvc) This change is required to complete https://github.com/knative/operator/issues/252 It enables configuring of wathola forwarder implemented as Knative Service. Configuration is done by using new optional environment variables. --- test/upgrade/prober/configuration.go | 16 +++++++ test/upgrade/prober/configuration_test.go | 55 +++++++++++++++++++++++ test/upgrade/prober/prober.go | 11 +++-- 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 test/upgrade/prober/configuration_test.go diff --git a/test/upgrade/prober/configuration.go b/test/upgrade/prober/configuration.go index 795c7835ab6..440f982901c 100644 --- a/test/upgrade/prober/configuration.go +++ b/test/upgrade/prober/configuration.go @@ -19,8 +19,10 @@ import ( "bytes" "fmt" "io/ioutil" + "os" "path" "runtime" + "strings" "text/template" "github.com/wavesoftware/go-ensure" @@ -118,3 +120,17 @@ func (p *prober) compileTemplate(templateName string, brokerUrl *apis.URL) strin ensure.NoError(tmpl.Execute(&buff, data)) return buff.String() } + +func envflag(name string, defaultValue bool) bool { + if value, ok := os.LookupEnv(name); ok { + valid := []string{"true", "yes", "enable"} + value = strings.ToLower(value) + for _, candidate := range valid { + if value == candidate { + return true + } + } + return false + } + return defaultValue +} diff --git a/test/upgrade/prober/configuration_test.go b/test/upgrade/prober/configuration_test.go new file mode 100644 index 00000000000..04fddb65fb2 --- /dev/null +++ b/test/upgrade/prober/configuration_test.go @@ -0,0 +1,55 @@ +/* + * Copyright 2020 The Knative Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package prober + +import ( + "fmt" + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestEnvflag(t *testing.T) { + envname := "TestEnvflag" + suite := []struct { + env string + envSet bool + defaultValue bool + out bool + }{ + {"", false, true, true}, + {"", true, true, false}, + {"yes", true, false, true}, + {"y", true, false, false}, + {"y", true, true, false}, + {"true", true, false, true}, + {"true", true, true, true}, + {"enable", true, false, true}, + {"enabled", true, false, false}, + } + for _, s := range suite { + t.Run(fmt.Sprintf("env(%t)=%q,def=%t", s.envSet, s.env, s.defaultValue), func(t *testing.T) { + if s.envSet { + assert.NoError(t, os.Setenv(envname, s.env)) + defer func() { assert.NoError(t, os.Unsetenv(envname)) }() + } + result := envflag(envname, s.defaultValue) + + assert.Equal(t, s.out, result) + }) + } +} diff --git a/test/upgrade/prober/prober.go b/test/upgrade/prober/prober.go index ea0a9f79b12..8b553f71a6b 100644 --- a/test/upgrade/prober/prober.go +++ b/test/upgrade/prober/prober.go @@ -25,6 +25,11 @@ import ( "knative.dev/eventing/test/lib/resources" ) +const ( + ServingUseFlag = "E2E_UPGRADE_TESTS_SERVING_USE" + ServingScaleToZeroFlag = "E2E_UPGRADE_TESTS_SERVING_SCALE_TO_ZERO" +) + var ( // FIXME: Interval is set to 200 msec, as lower values will result in errors: knative/eventing#2357 // Interval = 10 * time.Millisecond @@ -69,8 +74,8 @@ func NewConfig(namespace string) *Config { FinishedSleep: 5 * time.Second, FailOnErrors: true, Serving: ServingConfig{ - Use: false, - ScaleToZero: true, + Use: envflag(ServingUseFlag, false), + ScaleToZero: envflag(ServingScaleToZeroFlag, true), }, } } @@ -151,7 +156,7 @@ func (p *prober) remove() { if p.config.Serving.Use { p.removeForwarder() } - p.client.Tracker.Clean(true) + ensure.NoError(p.client.Tracker.Clean(true)) } func newProber(log *zap.SugaredLogger, client *testlib.Client, config *Config) Prober {