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 1/3] 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 { From 28396b7e913ae644ecea8839ce5128a6fb0433f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Suszy=C5=84ski?= Date: Fri, 21 Aug 2020 20:05:15 +0200 Subject: [PATCH 2/3] Using kelseyhightower/envconfig after code review --- test/upgrade/prober/configuration.go | 16 ------- test/upgrade/prober/prober.go | 17 ++++--- .../{configuration_test.go => prober_test.go} | 45 ++++++++++--------- 3 files changed, 33 insertions(+), 45 deletions(-) rename test/upgrade/prober/{configuration_test.go => prober_test.go} (55%) diff --git a/test/upgrade/prober/configuration.go b/test/upgrade/prober/configuration.go index 440f982901c..795c7835ab6 100644 --- a/test/upgrade/prober/configuration.go +++ b/test/upgrade/prober/configuration.go @@ -19,10 +19,8 @@ import ( "bytes" "fmt" "io/ioutil" - "os" "path" "runtime" - "strings" "text/template" "github.com/wavesoftware/go-ensure" @@ -120,17 +118,3 @@ 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/prober.go b/test/upgrade/prober/prober.go index 8b553f71a6b..bf8179e1839 100644 --- a/test/upgrade/prober/prober.go +++ b/test/upgrade/prober/prober.go @@ -19,17 +19,13 @@ import ( "testing" "time" + "github.com/kelseyhightower/envconfig" "github.com/wavesoftware/go-ensure" "go.uber.org/zap" testlib "knative.dev/eventing/test/lib" "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 @@ -68,15 +64,18 @@ type ServingConfig struct { } func NewConfig(namespace string) *Config { + servingConfig := ServingConfig{ + Use: false, + ScaleToZero: true, + } + err := envconfig.Process("e2e_upgrade_tests_serving", &servingConfig) + ensure.NoError(err) return &Config{ Namespace: namespace, Interval: Interval, FinishedSleep: 5 * time.Second, FailOnErrors: true, - Serving: ServingConfig{ - Use: envflag(ServingUseFlag, false), - ScaleToZero: envflag(ServingScaleToZeroFlag, true), - }, + Serving: servingConfig, } } diff --git a/test/upgrade/prober/configuration_test.go b/test/upgrade/prober/prober_test.go similarity index 55% rename from test/upgrade/prober/configuration_test.go rename to test/upgrade/prober/prober_test.go index 04fddb65fb2..0ae29e19278 100644 --- a/test/upgrade/prober/configuration_test.go +++ b/test/upgrade/prober/prober_test.go @@ -23,33 +23,38 @@ import ( "github.com/stretchr/testify/assert" ) -func TestEnvflag(t *testing.T) { - envname := "TestEnvflag" +type envValue uint + +const ( + EnvFalse envValue = iota + EnvTrue + EnvUnset +) + +func TestNewConfig(t *testing.T) { + envname := "E2E_UPGRADE_TESTS_SERVING_USE" suite := []struct { - env string - envSet bool - defaultValue bool - out bool + env envValue + 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}, + {EnvFalse, false}, + {EnvTrue, true}, + {EnvUnset, 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)) + t.Run(fmt.Sprintf("env=%v,out=%t", s.env, s.out), func(t *testing.T) { + if s.env != EnvUnset { + val := "false" + if s.env == EnvTrue { + val = "true" + } + assert.NoError(t, os.Setenv(envname, val)) defer func() { assert.NoError(t, os.Unsetenv(envname)) }() } - result := envflag(envname, s.defaultValue) + config := NewConfig("test-ns") - assert.Equal(t, s.out, result) + assert.Equal(t, s.out, config.Serving.Use) + assert.True(t, config.Serving.ScaleToZero) }) } } From 4f4b5a3b3ee437dad8759c10d32d5c3e302acd9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Suszy=C5=84ski?= Date: Mon, 24 Aug 2020 21:54:51 +0200 Subject: [PATCH 3/3] Docs for Eventing upgrade tests config overrides. --- test/upgrade/README.md | 20 ++++++++++++++++++++ test/upgrade/prober/prober.go | 19 ++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/test/upgrade/README.md b/test/upgrade/README.md index 10c477e1534..e39a9566157 100644 --- a/test/upgrade/README.md +++ b/test/upgrade/README.md @@ -83,3 +83,23 @@ Diagram below describe the setup: +--------+ +---------+ | (default) +----------+ ``` + +#### Probe test configuration + +Probe test behavior can be influenced from outside without modifying its source +code. That can be beneficial if one would like to run upgrade tests in different +context. One such example might be running Eventing upgrade tests in place that +have Serving and Eventing both installed. In such environment one can set +environment variable `E2E_UPGRADE_TESTS_SERVING_USE` to enable usage of ksvc +forwarder (which is disabled by default): + +``` +$ export E2E_UPGRADE_TESTS_SERVING_USE=true +``` + +Any option, apart from namespace, in +[`knative.dev/eventing/test/upgrade/prober.Config`](https://github.com/knative/eventing/blob/022e281/test/upgrade/prober/prober.go#L52-L63) +struct can be influenced, by using `E2E_UPGRADE_TESTS_XXXXX` environmental +variable prefix (using +[kelseyhightower/envconfig](https://github.com/kelseyhightower/envconfig#usage) +usage). diff --git a/test/upgrade/prober/prober.go b/test/upgrade/prober/prober.go index bf8179e1839..081448df3c6 100644 --- a/test/upgrade/prober/prober.go +++ b/test/upgrade/prober/prober.go @@ -64,19 +64,20 @@ type ServingConfig struct { } func NewConfig(namespace string) *Config { - servingConfig := ServingConfig{ - Use: false, - ScaleToZero: true, - } - err := envconfig.Process("e2e_upgrade_tests_serving", &servingConfig) - ensure.NoError(err) - return &Config{ - Namespace: namespace, + config := &Config{ + Namespace: "", Interval: Interval, FinishedSleep: 5 * time.Second, FailOnErrors: true, - Serving: servingConfig, + Serving: ServingConfig{ + Use: false, + ScaleToZero: true, + }, } + err := envconfig.Process("e2e_upgrade_tests", config) + ensure.NoError(err) + config.Namespace = namespace + return config } // RunEventProber starts a single Prober of the given domain.