Skip to content

Commit

Permalink
Flags to configure eventing upgrade tests forwarder (ksvc) (#3899)
Browse files Browse the repository at this point in the history
* Flags to configure eventing upgrade tests forwarder (ksvc)

This change is required to complete knative/operator#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.
  • Loading branch information
cardil authored Aug 26, 2020
1 parent f7f934c commit 38b6ca1
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
20 changes: 20 additions & 0 deletions test/upgrade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
11 changes: 8 additions & 3 deletions test/upgrade/prober/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
60 changes: 60 additions & 0 deletions test/upgrade/prober/prober_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}

0 comments on commit 38b6ca1

Please sign in to comment.