Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an optional golang runner to the conformance test image #79284

Merged
merged 1 commit into from Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions build/BUILD
Expand Up @@ -172,6 +172,7 @@ filegroup(
"//cmd/linkcheck",
"//test/e2e:e2e.test_binary",
"//vendor/github.com/onsi/ginkgo/ginkgo",
"//cluster/images/conformance/go-runner",
],
)),
)
Expand Down
6 changes: 5 additions & 1 deletion cluster/images/conformance/BUILD
Expand Up @@ -13,6 +13,7 @@ container_layer(
name = "bins",
directory = "/usr/local/bin",
files = [
"//cluster/images/conformance/go-runner",
"//cmd/kubectl",
"//test/e2e:e2e.test_binary",
"//vendor/github.com/onsi/ginkgo/ginkgo",
Expand Down Expand Up @@ -62,7 +63,10 @@ filegroup(

filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
srcs = [
":package-srcs",
"//cluster/images/conformance/go-runner:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions cluster/images/conformance/Dockerfile
Expand Up @@ -18,6 +18,7 @@ COPY ginkgo /usr/local/bin/
COPY e2e.test /usr/local/bin/
COPY kubectl /usr/local/bin/
COPY run_e2e.sh /run_e2e.sh
COPY gorunner /gorunner
COPY cluster /kubernetes/cluster
WORKDIR /usr/local/bin

Expand Down
3 changes: 3 additions & 0 deletions cluster/images/conformance/Makefile
Expand Up @@ -27,6 +27,7 @@ DOCKERIZED_OUTPUT_PATH=$(shell pwd)/../../../$(OUT_DIR)/dockerized/bin/linux/$(A
GINKGO_BIN?=$(shell test -f $(LOCAL_OUTPUT_PATH)/ginkgo && echo $(LOCAL_OUTPUT_PATH)/ginkgo || echo $(DOCKERIZED_OUTPUT_PATH)/ginkgo)
KUBECTL_BIN?=$(shell test -f $(LOCAL_OUTPUT_PATH)/kubectl && echo $(LOCAL_OUTPUT_PATH)/kubectl || echo $(DOCKERIZED_OUTPUT_PATH)/kubectl)
E2E_TEST_BIN?=$(shell test -f $(LOCAL_OUTPUT_PATH)/e2e.test && echo $(LOCAL_OUTPUT_PATH)/e2e.test || echo $(DOCKERIZED_OUTPUT_PATH)/e2e.test)
E2E_GO_RUNNER_BIN?=$(shell test -f $(LOCAL_OUTPUT_PATH)/go-runner && echo $(LOCAL_OUTPUT_PATH)/go-runner || echo $(DOCKERIZED_OUTPUT_PATH)/go-runner)

CLUSTER_DIR?=$(shell pwd)/../../../cluster/

Expand All @@ -45,11 +46,13 @@ endif
cp ${GINKGO_BIN} ${TEMP_DIR}
cp ${KUBECTL_BIN} ${TEMP_DIR}
cp ${E2E_TEST_BIN} ${TEMP_DIR}
cp ${E2E_GO_RUNNER_BIN} ${TEMP_DIR}/gorunner
cp -r ${CLUSTER_DIR} ${TEMP_DIR}/cluster

chmod a+rx ${TEMP_DIR}/ginkgo
chmod a+rx ${TEMP_DIR}/kubectl
chmod a+rx ${TEMP_DIR}/e2e.test
chmod a+rx ${TEMP_DIR}/gorunner

cd ${TEMP_DIR} && sed -i.back "s|BASEIMAGE|${BASEIMAGE}|g" Dockerfile

Expand Down
2 changes: 1 addition & 1 deletion cluster/images/conformance/README.md
Expand Up @@ -7,7 +7,7 @@

```console
# First, build the binaries by running make from the root directory
$ make WHAT="test/e2e/e2e.test vendor/github.com/onsi/ginkgo/ginkgo cmd/kubectl"
$ make WHAT="test/e2e/e2e.test vendor/github.com/onsi/ginkgo/ginkgo cmd/kubectl cluster/images/conformance/go-runner"

# Build for linux/amd64 (default)
# export REGISTRY=$HOST/$ORG to switch from k8s.gcr.io
Expand Down
47 changes: 47 additions & 0 deletions cluster/images/conformance/go-runner/BUILD
@@ -0,0 +1,47 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = [
"cmd.go",
"const.go",
"e2erunner.go",
"env.go",
"tar.go",
],
importpath = "k8s.io/kubernetes/cluster/images/conformance/go-runner",
visibility = ["//visibility:private"],
deps = ["//vendor/github.com/pkg/errors:go_default_library"],
)

go_binary(
name = "go-runner",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)

filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)

filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

go_test(
name = "go_default_test",
srcs = [
"cmd_test.go",
"env_test.go",
"tar_test.go",
],
data = glob(["testdata/**"]),
embed = [":go_default_library"],
deps = ["//vendor/github.com/pkg/errors:go_default_library"],
)
27 changes: 27 additions & 0 deletions cluster/images/conformance/go-runner/Makefile
@@ -0,0 +1,27 @@
# Copyright 2019 The Kubernetes 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.

HOST_GOOS ?= $(shell go env GOOS)
HOST_GOARCH ?= $(shell go env GOARCH)
GO_BUILD ?= go build

.PHONY: all build clean

all: build

build:
$(GO_BUILD)

clean:
rm done e2e.log e2e.tar.gz go-runner
Empty file.
96 changes: 96 additions & 0 deletions cluster/images/conformance/go-runner/cmd.go
@@ -0,0 +1,96 @@
/*
Copyright 2019 The Kubernetes 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 main

import (
"fmt"
"io"
"os/exec"
"strings"
)

// getCmd uses the given environment to form the ginkgo command to run tests. It will
// set the stdout/stderr to the given writer.
func getCmd(env Getenver, w io.Writer) *exec.Cmd {
ginkgoArgs := []string{}

// The logic of the parallel env var impacting the skip value necessitates it
// being placed before the rest of the flag resolution.
skip := env.Getenv(skipEnvKey)
switch env.Getenv(parallelEnvKey) {
case "y", "Y", "true":
ginkgoArgs = append(ginkgoArgs, "--p")
if len(skip) == 0 {
skip = serialTestsRegexp
}
}

ginkgoArgs = append(ginkgoArgs, []string{
"--focus=" + env.Getenv(focusEnvKey),
"--skip=" + skip,
"--noColor=true",
}...)

extraArgs := []string{
"--disable-log-dump",
"--repo-root=/kubernetes",
"--provider=" + env.Getenv(providerEnvKey),
"--report-dir=" + env.Getenv(resultsDirEnvKey),
"--kubeconfig=" + env.Getenv(kubeconfigEnvKey),
}

// Extra args handling
sep := " "
if len(env.Getenv(extraArgsSeparaterEnvKey)) > 0 {
sep = env.Getenv(extraArgsSeparaterEnvKey)
}

if len(env.Getenv(extraGinkgoArgsEnvKey)) > 0 {
ginkgoArgs = append(ginkgoArgs, strings.Split(env.Getenv(extraGinkgoArgsEnvKey), sep)...)
}

if len(env.Getenv(extraArgsEnvKey)) > 0 {
fmt.Printf("sep is %q args are %q", sep, env.Getenv(extraArgsEnvKey))
fmt.Println("split", strings.Split(env.Getenv(extraArgsEnvKey), sep))
extraArgs = append(extraArgs, strings.Split(env.Getenv(extraArgsEnvKey), sep)...)
}

if len(env.Getenv(dryRunEnvKey)) > 0 {
ginkgoArgs = append(ginkgoArgs, "--dryRun=true")
}

args := []string{}
args = append(args, ginkgoArgs...)
args = append(args, env.Getenv(testBinEnvKey))
args = append(args, "--")
args = append(args, extraArgs...)

cmd := exec.Command(env.Getenv(ginkgoEnvKey), args...)
cmd.Stdout = w
cmd.Stderr = w
return cmd
}

// cmdInfo generates a useful look at what the command is for printing/debug.
func cmdInfo(cmd *exec.Cmd) string {
return fmt.Sprintf(
`Command env: %v
Run from directory: %v
Executable path: %v
Args (comma-delimited): %v`, cmd.Env, cmd.Dir, cmd.Path, strings.Join(cmd.Args, ","),
)
}
129 changes: 129 additions & 0 deletions cluster/images/conformance/go-runner/cmd_test.go
@@ -0,0 +1,129 @@
/*
Copyright 2019 The Kubernetes 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 main

import (
"os"
"reflect"
"testing"
)

func TestGetCmd(t *testing.T) {
testCases := []struct {
desc string
env Getenver
expectArgs []string
}{
{
desc: "Default",
env: &explicitEnv{
vals: map[string]string{
ginkgoEnvKey: "ginkgobin",
testBinEnvKey: "testbin",
},
},
expectArgs: []string{
"ginkgobin",
"--focus=", "--skip=",
"--noColor=true", "testbin", "--",
"--disable-log-dump", "--repo-root=/kubernetes",
"--provider=", "--report-dir=", "--kubeconfig=",
},
}, {
desc: "Filling in defaults",
env: &explicitEnv{
vals: map[string]string{
ginkgoEnvKey: "ginkgobin",
testBinEnvKey: "testbin",
focusEnvKey: "focus",
skipEnvKey: "skip",
providerEnvKey: "provider",
resultsDirEnvKey: "results",
kubeconfigEnvKey: "kubeconfig",
},
},
expectArgs: []string{
"ginkgobin",
"--focus=focus", "--skip=skip",
"--noColor=true", "testbin", "--",
"--disable-log-dump", "--repo-root=/kubernetes",
"--provider=provider", "--report-dir=results", "--kubeconfig=kubeconfig",
},
}, {
desc: "Parallel gets set and skips serial",
env: &explicitEnv{
vals: map[string]string{
ginkgoEnvKey: "ginkgobin",
testBinEnvKey: "testbin",
parallelEnvKey: "true",
},
},
expectArgs: []string{
"ginkgobin", "--p",
"--focus=", "--skip=[Serial]",
"--noColor=true", "testbin", "--",
"--disable-log-dump", "--repo-root=/kubernetes",
"--provider=", "--report-dir=", "--kubeconfig=",
},
}, {
desc: "Arbitrary options before and after double dash split by space",
env: &explicitEnv{
vals: map[string]string{
ginkgoEnvKey: "ginkgobin",
testBinEnvKey: "testbin",
extraArgsEnvKey: "--extra=1 --extra=2",
extraGinkgoArgsEnvKey: "--ginkgo1 --ginkgo2",
},
},
expectArgs: []string{
"ginkgobin", "--focus=", "--skip=",
"--noColor=true", "--ginkgo1", "--ginkgo2",
"testbin", "--",
"--disable-log-dump", "--repo-root=/kubernetes",
"--provider=", "--report-dir=", "--kubeconfig=",
"--extra=1", "--extra=2",
},
}, {
desc: "Arbitrary options can be split by other tokens",
env: &explicitEnv{
vals: map[string]string{
ginkgoEnvKey: "ginkgobin",
testBinEnvKey: "testbin",
extraArgsEnvKey: "--extra=value with spaces:--extra=value with % anything!$$",
extraGinkgoArgsEnvKey: `--ginkgo='with "quotes" and ':--ginkgo2=true$(foo)`,
extraArgsSeparaterEnvKey: ":",
},
},
expectArgs: []string{
"ginkgobin", "--focus=", "--skip=",
"--noColor=true", `--ginkgo='with "quotes" and '`, "--ginkgo2=true$(foo)",
"testbin", "--",
"--disable-log-dump", "--repo-root=/kubernetes",
"--provider=", "--report-dir=", "--kubeconfig=",
"--extra=value with spaces", "--extra=value with % anything!$$",
},
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
c := getCmd(tc.env, os.Stdout)
if !reflect.DeepEqual(c.Args, tc.expectArgs) {
t.Errorf("Expected args %q but got %q", tc.expectArgs, c.Args)
}
})
}
}