Skip to content

Commit

Permalink
Allow to specify target cluster architecture for tests
Browse files Browse the repository at this point in the history
When e2e or examples tests are started, hardware architectutere of the host
is always used. However test cases can be exectuted on cluster with another architecture,
using `--kubeconfig` parameter.
`TEST_RUNTIME_ARCH` allows to specify target cluster architecture to be able to use
correct restrictions and modifications, specific to concrete arch.

Signed-off-by: Yulia Gaponenko <yulia.gaponenko1@de.ibm.com>
  • Loading branch information
barthy1 committed Aug 24, 2020
1 parent 0de5401 commit acdf150
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ go test -v -count=1 -tags=e2e -timeout=20m ./test
go test -v -count=1 -tags=e2e -timeout=20m ./test --kubeconfig ~/special/kubeconfig --cluster myspecialcluster
```
If tests are applied to the cluster with hardware architecture different to the base one
(for instance `go test` starts on amd64 architecture and `--kubeconfig` points to s390x Kubernetes cluster),
use `TEST_RUNTIME_ARCH` environment variable to specify the target hardware architecture(amd64, s390x, ppc64le, arm, arm64, etc)
You can also use
[all of flags defined in `knative/pkg/test`](https://github.com/knative/pkg/tree/master/test#flags).
Expand Down
17 changes: 14 additions & 3 deletions test/multiarch_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package test

import (
"os"
"runtime"
"testing"
)
Expand All @@ -33,10 +34,20 @@ const (
Registry
)

// return architecture of the cluster where test suites will be executed.
// default value is similar to build architecture, TEST_RUNTIME_ARCH is used when test target cluster has another architecture
func getTestArch() string {
val, ok := os.LookupEnv("TEST_RUNTIME_ARCH")
if ok {
return val
}
return runtime.GOARCH
}

func initImageNames() map[int]string {
mapping := make(map[int]string)

switch arch := runtime.GOARCH; arch {
switch getTestArch() {
case "s390x":
mapping[BusyboxSha] = "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977"
mapping[Registry] = "ibmcom/registry:2.6.2.5"
Expand All @@ -51,7 +62,7 @@ func initImageNames() map[int]string {
func initExcludedTests() map[string]bool {
mapping := make(map[string]bool)
tests := []string{}
switch arch := runtime.GOARCH; arch {
switch getTestArch() {
case "s390x":
//examples
tests = []string{
Expand Down Expand Up @@ -131,6 +142,6 @@ func GetTestImage(image int) string {
// check if test name is in the excluded list and skip it
func SkipIfExcluded(t *testing.T) {
if excludedTests[t.Name()] {
t.Skipf("skip for %s architecture", runtime.GOARCH)
t.Skipf("skip for %s architecture", getTestArch())
}
}

0 comments on commit acdf150

Please sign in to comment.