From 38b6ca16d09b6012ac16ad4d7c3aa449cbcbeb06 Mon Sep 17 00:00:00 2001 From: Chris Suszynski Date: Wed, 26 Aug 2020 20:02:06 +0200 Subject: [PATCH] Flags to configure eventing upgrade tests forwarder (ksvc) (#3899) * 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. * Using kelseyhightower/envconfig after code review * Docs for Eventing upgrade tests config overrides. --- test/upgrade/README.md | 20 ++++++++++ test/upgrade/prober/prober.go | 11 ++++-- test/upgrade/prober/prober_test.go | 60 ++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 test/upgrade/prober/prober_test.go 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 ea0a9f79b12..081448df3c6 100644 --- a/test/upgrade/prober/prober.go +++ b/test/upgrade/prober/prober.go @@ -19,6 +19,7 @@ import ( "testing" "time" + "github.com/kelseyhightower/envconfig" "github.com/wavesoftware/go-ensure" "go.uber.org/zap" testlib "knative.dev/eventing/test/lib" @@ -63,8 +64,8 @@ type ServingConfig struct { } func NewConfig(namespace string) *Config { - return &Config{ - Namespace: namespace, + config := &Config{ + Namespace: "", Interval: Interval, FinishedSleep: 5 * time.Second, FailOnErrors: true, @@ -73,6 +74,10 @@ func NewConfig(namespace string) *Config { 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. @@ -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 { diff --git a/test/upgrade/prober/prober_test.go b/test/upgrade/prober/prober_test.go new file mode 100644 index 00000000000..0ae29e19278 --- /dev/null +++ b/test/upgrade/prober/prober_test.go @@ -0,0 +1,60 @@ +/* + * 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" +) + +type envValue uint + +const ( + EnvFalse envValue = iota + EnvTrue + EnvUnset +) + +func TestNewConfig(t *testing.T) { + envname := "E2E_UPGRADE_TESTS_SERVING_USE" + suite := []struct { + env envValue + out bool + }{ + {EnvFalse, false}, + {EnvTrue, true}, + {EnvUnset, false}, + } + for _, s := range suite { + 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)) }() + } + config := NewConfig("test-ns") + + assert.Equal(t, s.out, config.Serving.Use) + assert.True(t, config.Serving.ScaleToZero) + }) + } +}