From d2e5a4b0527344c3c3809910a91540d05f3bf78b Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Tue, 9 Jul 2019 12:46:57 -0700 Subject: [PATCH] build gvisor image locally in integration tests; add temporary error to make sure that image is used --- Makefile | 2 +- deploy/addons/gvisor/gvisor-pod.yaml.tmpl | 2 +- deploy/gvisor/Dockerfile | 8 +++++++- pkg/gvisor/enable.go | 1 + pkg/minikube/assets/addons.go | 2 -- pkg/minikube/constants/constants.go | 3 +-- test/integration/functional_test.go | 19 +++++-------------- 7 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 661fa59dbe..336c07995a 100755 --- a/Makefile +++ b/Makefile @@ -381,7 +381,7 @@ out/gvisor-addon: GOOS=linux CGO_ENABLED=0 go build -o $@ cmd/gvisor/gvisor.go .PHONY: gvisor-addon-image -gvisor-addon-image: out/gvisor-addon +gvisor-addon-image: docker build -t $(REGISTRY)/gvisor-addon:latest -f deploy/gvisor/Dockerfile . .PHONY: push-gvisor-addon-image diff --git a/deploy/addons/gvisor/gvisor-pod.yaml.tmpl b/deploy/addons/gvisor/gvisor-pod.yaml.tmpl index 4cd5de513f..08ecd7225f 100644 --- a/deploy/addons/gvisor/gvisor-pod.yaml.tmpl +++ b/deploy/addons/gvisor/gvisor-pod.yaml.tmpl @@ -24,7 +24,7 @@ spec: hostPID: true containers: - name: gvisor - image: {{default "gcr.io/k8s-minikube" .GvisorImageRepo}}/gvisor-addon:latest + image: {{default "gcr.io/k8s-minikube" .ImageRepository}}/gvisor-addon:latest securityContext: privileged: true volumeMounts: diff --git a/deploy/gvisor/Dockerfile b/deploy/gvisor/Dockerfile index 9dacfa5466..43a7c4f9ba 100644 --- a/deploy/gvisor/Dockerfile +++ b/deploy/gvisor/Dockerfile @@ -12,9 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +FROM golang:1.12.5 +WORKDIR $GOPATH/src/k8s.io/minikube +COPY . . +ENV GO111MODULE=on +RUN GOOS=linux CGO_ENABLED=0 go build -o /out/gvisor-addon cmd/gvisor/gvisor.go + FROM ubuntu:18.04 RUN apt-get update && \ apt-get install -y kmod gcc wget xz-utils libc6-dev bc libelf-dev bison flex openssl libssl-dev libidn2-0 sudo libcap2 && \ rm -rf /var/lib/apt/lists/* -COPY out/gvisor-addon /gvisor-addon +COPY --from=0 /out/gvisor-addon /gvisor-addon CMD ["/gvisor-addon"] diff --git a/pkg/gvisor/enable.go b/pkg/gvisor/enable.go index 7eacf10f9a..269a6a2eab 100644 --- a/pkg/gvisor/enable.go +++ b/pkg/gvisor/enable.go @@ -44,6 +44,7 @@ const ( // 3. copies necessary containerd config files // 4. restarts containerd func Enable() error { + return fmt.Errorf("local image used correctly") if err := makeGvisorDirs(); err != nil { return errors.Wrap(err, "creating directories on node") } diff --git a/pkg/minikube/assets/addons.go b/pkg/minikube/assets/addons.go index 3df10a7604..75c462bec0 100644 --- a/pkg/minikube/assets/addons.go +++ b/pkg/minikube/assets/addons.go @@ -403,12 +403,10 @@ func GenerateTemplateData(cfg config.KubernetesConfig) interface{} { Arch string ExoticArch string ImageRepository string - GvisorImageRepo string }{ Arch: a, ExoticArch: ea, ImageRepository: cfg.ImageRepository, - GvisorImageRepo: os.Getenv(constants.MinikubeGvisorAddonImageRepo), } return opts diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index 14bf4a136c..83742dd30b 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -431,8 +431,7 @@ const ( // GvisorURL is the url to download gvisor GvisorURL = "https://storage.googleapis.com/gvisor/releases/nightly/2018-12-07/runsc" - // MinikubeGvisorAddonImageRepo is the environment variable set by integration tests to change the gvisor image repo. - MinikubeGvisorAddonImageRepo = "MINIKUBE_GVISOR_ADDON_IMAGE_REPO" + GvisorImage = "gcr.io/k8s-minikube/gvisor-addon:latest" ) const ( diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 5a4425a6ed..597c0d9f9a 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -19,13 +19,9 @@ limitations under the License. package integration import ( - "fmt" - "os" "os/exec" - "path/filepath" "strings" "testing" - "time" "github.com/docker/machine/libmachine/state" "k8s.io/minikube/pkg/minikube/constants" @@ -66,12 +62,8 @@ func TestFunctionalContainerd(t *testing.T) { r.RunCommand("delete", true) } - // Build and push new gvisor image for testing. - repo := fmt.Sprintf("gcr.io/k8s-minikube/test/gvisor-image/%d", time.Now().Unix()) - pushGvisorImage(t, repo) - - defer os.Setenv(constants.MinikubeGvisorAddonImageRepo, "") - os.Setenv(constants.MinikubeGvisorAddonImageRepo, repo) + // Build current version of the gvisor image. + buildGvisorImage(t) r.Start("--container-runtime=containerd", "--docker-opt containerd=/var/run/containerd/containerd.sock") t.Run("Gvisor", testGvisor) @@ -79,10 +71,9 @@ func TestFunctionalContainerd(t *testing.T) { r.RunCommand("delete", true) } -func pushGvisorImage(t *testing.T, repo string) { - cmd := exec.Command("make", "push-gvisor-addon-image") - cmd.Env = append(os.Environ(), []string{fmt.Sprintf("REGISTRY=%s", repo)}...) - cmd.Dir = filepath.Join(os.Getenv("GOPATH"), "src/k8s.io/minikube") +func buildGvisorImage(t *testing.T) { + cmd := exec.Command("docker", "build", "-t", constants.GvisorImage, "-f", "deploy/gvisor/Dockerfile", ".") + cmd.Dir = "../../" stdout, err := cmd.CombinedOutput() if err != nil { t.Fatalf("Error running command: %s in directory: %s %v. Output: %s", cmd.Args, cmd.Dir, err, string(stdout))