Merge pull request #8779 from priyawadhwa/skaffold

Add integration test to test against latest skaffold release
pull/8835/head
Medya Ghazizadeh 2020-07-24 12:56:37 -07:00 committed by GitHub
commit a53f0ffb75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 271 additions and 11 deletions

View File

@ -695,7 +695,7 @@ jobs:
chmod a+x e2e-*
chmod a+x minikube-*
START_TIME=$(date -u +%s)
KUBECONFIG=$(pwd)/testhome/kubeconfig MINIKUBE_HOME=$(pwd)/testhome ./e2e-linux-amd64 -minikube-start-args=--driver=docker -test.run "(TestAddons|TestCertOptions)" -test.timeout=10m -test.v -timeout-multiplier=1.5 -binary=./minikube-linux-amd64 2>&1 | tee ./report/testout.txt
KUBECONFIG=$(pwd)/testhome/kubeconfig MINIKUBE_HOME=$(pwd)/testhome ./e2e-linux-amd64 -minikube-start-args=--driver=docker -test.run "(TestAddons|TestCertOptions|TestSkaffold)" -test.timeout=10m -test.v -timeout-multiplier=1.5 -binary=./minikube-linux-amd64 2>&1 | tee ./report/testout.txt
END_TIME=$(date -u +%s)
TIME_ELAPSED=$(($END_TIME-$START_TIME))
min=$((${TIME_ELAPSED}/60))
@ -733,7 +733,7 @@ jobs:
echo "-------------------------------------------------------"
if [ "$numFail" -gt 0 ];then echo "*** $numFail Failed ***";exit 2;fi
if [ "$numPass" -eq 0 ];then echo "*** 0 Passed! ***";exit 2;fi
if [ "$numPass" -lt 5 ];then echo "*** Failed to pass at least 5 ! ***";exit 2;fi
if [ "$numPass" -lt 6 ];then echo "*** Failed to pass at least 6 ! ***";exit 2;fi
addons_certs_virtualbox_macos:
runs-on: macos-10.15
env:
@ -788,9 +788,10 @@ jobs:
mkdir -p report
mkdir -p testhome
chmod a+x e2e-*
chmod a+x minikube-*
cp minikube-darwin-amd64 minikube
chmod a+x minikube*
START_TIME=$(date -u +%s)
KUBECONFIG=$(pwd)/testhome/kubeconfig MINIKUBE_HOME=$(pwd)/testhome ./e2e-darwin-amd64 -minikube-start-args=--vm-driver=virtualbox -test.run "(TestAddons|TestCertOptions)" -test.timeout=15m -test.v -timeout-multiplier=3 -binary=./minikube-darwin-amd64 2>&1 | tee ./report/testout.txt
KUBECONFIG=$(pwd)/testhome/kubeconfig MINIKUBE_HOME=$(pwd)/testhome ./e2e-darwin-amd64 -minikube-start-args=--vm-driver=virtualbox -test.run "(TestAddons|TestCertOptions|TestSkaffold)" -test.timeout=15m -test.v -timeout-multiplier=3 -binary=./minikube-darwin-amd64 2>&1 | tee ./report/testout.txt
END_TIME=$(date -u +%s)
TIME_ELAPSED=$(($END_TIME-$START_TIME))
min=$((${TIME_ELAPSED}/60))
@ -828,7 +829,7 @@ jobs:
echo "-------------------------------------------------------"
if [ "$numFail" -gt 0 ];then echo "*** $numFail Failed ***";exit 2;fi
if [ "$numPass" -eq 0 ];then echo "*** 0 Passed! ***";exit 2;fi
if [ "$numPass" -lt 5 ];then echo "*** Failed to pass at least 5 ! ***";exit 2;fi
if [ "$numPass" -lt 6 ];then echo "*** Failed to pass at least 6 ! ***";exit 2;fi
multinode_docker_ubuntu:
runs-on: ubuntu-18.04
env:

View File

@ -693,7 +693,7 @@ jobs:
chmod a+x e2e-*
chmod a+x minikube-*
START_TIME=$(date -u +%s)
KUBECONFIG=$(pwd)/testhome/kubeconfig MINIKUBE_HOME=$(pwd)/testhome ./e2e-linux-amd64 -minikube-start-args=--driver=docker -test.run "(TestAddons|TestCertOptions)" -test.timeout=10m -test.v -timeout-multiplier=1.5 -binary=./minikube-linux-amd64 2>&1 | tee ./report/testout.txt
KUBECONFIG=$(pwd)/testhome/kubeconfig MINIKUBE_HOME=$(pwd)/testhome ./e2e-linux-amd64 -minikube-start-args=--driver=docker -test.run "(TestAddons|TestCertOptions|TestSkaffold)" -test.timeout=10m -test.v -timeout-multiplier=1.5 -binary=./minikube-linux-amd64 2>&1 | tee ./report/testout.txt
END_TIME=$(date -u +%s)
TIME_ELAPSED=$(($END_TIME-$START_TIME))
min=$((${TIME_ELAPSED}/60))
@ -731,7 +731,7 @@ jobs:
echo "-------------------------------------------------------"
if [ "$numFail" -gt 0 ];then echo "*** $numFail Failed ***";exit 2;fi
if [ "$numPass" -eq 0 ];then echo "*** 0 Passed! ***";exit 2;fi
if [ "$numPass" -lt 5 ];then echo "*** Failed to pass at least 5 ! ***";exit 2;fi
if [ "$numPass" -lt 6 ];then echo "*** Failed to pass at least 6 ! ***";exit 2;fi
addons_certs_virtualbox_macos:
runs-on: macos-10.15
env:
@ -786,9 +786,10 @@ jobs:
mkdir -p report
mkdir -p testhome
chmod a+x e2e-*
chmod a+x minikube-*
cp minikube-darwin-amd64 minikube
chmod a+x minikube*
START_TIME=$(date -u +%s)
KUBECONFIG=$(pwd)/testhome/kubeconfig MINIKUBE_HOME=$(pwd)/testhome ./e2e-darwin-amd64 -minikube-start-args=--vm-driver=virtualbox -test.run "(TestAddons|TestCertOptions)" -test.timeout=15m -test.v -timeout-multiplier=3 -binary=./minikube-darwin-amd64 2>&1 | tee ./report/testout.txt
KUBECONFIG=$(pwd)/testhome/kubeconfig MINIKUBE_HOME=$(pwd)/testhome ./e2e-darwin-amd64 -minikube-start-args=--vm-driver=virtualbox -test.run "(TestAddons|TestCertOptions|TestSkaffold)" -test.timeout=15m -test.v -timeout-multiplier=3 -binary=./minikube-darwin-amd64 2>&1 | tee ./report/testout.txt
END_TIME=$(date -u +%s)
TIME_ELAPSED=$(($END_TIME-$START_TIME))
min=$((${TIME_ELAPSED}/60))
@ -826,7 +827,7 @@ jobs:
echo "-------------------------------------------------------"
if [ "$numFail" -gt 0 ];then echo "*** $numFail Failed ***";exit 2;fi
if [ "$numPass" -eq 0 ];then echo "*** 0 Passed! ***";exit 2;fi
if [ "$numPass" -lt 5 ];then echo "*** Failed to pass at least 5 ! ***";exit 2;fi
if [ "$numPass" -lt 6 ];then echo "*** Failed to pass at least 6 ! ***";exit 2;fi
multinode_docker_ubuntu:
runs-on: ubuntu-18.04
env:

View File

@ -32,7 +32,7 @@ var (
boilerplatedir = flag.String("boilerplate-dir", ".", "Boilerplate directory for boilerplate files")
rootdir = flag.String("rootdir", "../../", "Root directory to examine")
verbose = flag.Bool("v", false, "Verbose")
skippedPaths = regexp.MustCompile(`Godeps|third_party|_gopath|_output|\.git|cluster/env.sh|vendor|test/e2e/generated/bindata.go|site/themes/docsy`)
skippedPaths = regexp.MustCompile(`Godeps|third_party|_gopath|_output|\.git|cluster/env.sh|vendor|test/e2e/generated/bindata.go|site/themes/docsy|test/integration/testdata`)
windowdNewLine = regexp.MustCompile(`\r`)
txtExtension = regexp.MustCompile(`\.txt`)
goBuildTag = regexp.MustCompile(`(?m)^(// \+build.*\n)+\n`)

View File

@ -0,0 +1,119 @@
// +build integration
/*
Copyright 2020 The Kubernetes Authors All rights reserved.
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 integration
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
"time"
"github.com/docker/machine/libmachine/mcnutils"
"github.com/hashicorp/go-getter"
"k8s.io/minikube/pkg/util/retry"
)
func TestSkaffold(t *testing.T) {
if NoneDriver() {
t.Skip("none driver doesn't support `minikube docker-env`; skaffold depends on this command")
}
// can't use a unique profile, as skaffold only recognizes the
// profile name 'minikube' as a local cluster
profile := "minikube"
ctx, cancel := context.WithTimeout(context.Background(), Minutes(5))
defer CleanupWithLogs(t, profile, cancel)
// install latest skaffold release
tf, err := installSkaffold()
if err != nil {
t.Fatalf("skaffold release installation failed: %v", err)
}
defer os.Remove(tf.Name())
// start minikube cluster
args := append([]string{"start", "-p", profile, "--memory=2200"}, StartArgs()...)
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
if err != nil {
t.Fatalf("starting minikube: %v\n%s", err, rr.Output())
}
// make sure minikube binary is in path so that skaffold can access it
abs, err := filepath.Abs(Target())
// copy minikube binary to minikube
if err := mcnutils.CopyFile(Target(), filepath.Join(filepath.Dir(abs), "minikube")); err != nil {
t.Fatalf("error copying to minikube")
}
if err != nil {
t.Fatalf("absolute path to minikube binary: %v", err)
}
os.Setenv("PATH", fmt.Sprintf("%s:%s", filepath.Dir(abs), os.Getenv("PATH")))
// make sure 'docker' and 'minikube' are on PATH
for _, binary := range []string{"minikube", "docker"} {
rr, err := Run(t, exec.CommandContext(ctx, "which", binary))
if err != nil {
t.Fatalf("'which %v' failed: check if %v is on PATH\n%v", binary, binary, rr.Output())
}
}
// make sure "skaffold run" exits without failure
cmd := exec.CommandContext(ctx, tf.Name(), "run", "--kube-context", profile, "--status-check=true", "--port-forward=false")
cmd.Dir = "testdata/skaffold"
rr, err = Run(t, cmd)
if err != nil {
t.Fatalf("error running skaffold: %v\n%s", err, rr.Output())
}
// make sure expected deployment is running
if _, err := PodWait(ctx, t, profile, "default", "app=leeroy-app", Minutes(1)); err != nil {
t.Fatalf("failed waiting for pod leeroy-app: %v", err)
}
if _, err := PodWait(ctx, t, profile, "default", "app=leeroy-web", Minutes(1)); err != nil {
t.Fatalf("failed waiting for pod leeroy-web: %v", err)
}
}
// installSkaffold installs the latest release of skaffold
func installSkaffold() (f *os.File, err error) {
tf, err := ioutil.TempFile("", "skaffold.exe")
if err != nil {
return tf, err
}
tf.Close()
url := "https://storage.googleapis.com/skaffold/releases/latest/skaffold-%s-amd64"
url = fmt.Sprintf(url, runtime.GOOS)
if runtime.GOOS == "windows" {
url += ".exe"
}
if err := retry.Expo(func() error { return getter.GetFile(tf.Name(), url) }, 3*time.Second, Minutes(3)); err != nil {
return tf, err
}
if runtime.GOOS != "windows" {
if err := os.Chmod(tf.Name(), 0700); err != nil {
return tf, err
}
}
return tf, nil
}

View File

@ -0,0 +1,3 @@
This [example](https://github.com/GoogleContainerTools/skaffold/tree/master/integration/examples/microservices) is the microservices example and was copied from the skaffold repo.

View File

@ -0,0 +1,10 @@
FROM golang:1.12.9-alpine3.10 as builder
COPY app.go .
RUN go build -o /app .
FROM alpine:3.10
# Define GOTRACEBACK to mark this container as using the Go language runtime
# for `skaffold debug` (https://skaffold.dev/docs/workflows/debug/).
ENV GOTRACEBACK=single
CMD ["./app"]
COPY --from=builder /app .

View File

@ -0,0 +1,17 @@
package main
import (
"fmt"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "leeroooooy app!!\n")
}
func main() {
log.Print("leeroy app server ready")
http.HandleFunc("/", handler)
http.ListenAndServe(":50051", nil)
}

View File

@ -0,0 +1,35 @@
apiVersion: v1
kind: Service
metadata:
name: leeroy-app
labels:
app: leeroy-app
spec:
clusterIP: None
ports:
- port: 50051
name: leeroy-app
selector:
app: leeroy-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: leeroy-app
labels:
app: leeroy-app
spec:
replicas: 1
selector:
matchLabels:
app: leeroy-app
template:
metadata:
labels:
app: leeroy-app
spec:
containers:
- name: leeroy-app
image: leeroy-app
ports:
- containerPort: 50051

View File

@ -0,0 +1,10 @@
FROM golang:1.12.9-alpine3.10 as builder
COPY web.go .
RUN go build -o /web .
FROM alpine:3.10
# Define GOTRACEBACK to mark this container as using the Go language runtime
# for `skaffold debug` (https://skaffold.dev/docs/workflows/debug/).
ENV GOTRACEBACK=single
CMD ["./web"]
COPY --from=builder /web .

View File

@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: leeroy-web
labels:
app: leeroy-web
spec:
replicas: 1
selector:
matchLabels:
app: leeroy-web
template:
metadata:
labels:
app: leeroy-web
spec:
containers:
- name: leeroy-web
image: leeroy-web
ports:
- containerPort: 8080

View File

@ -0,0 +1,25 @@
package main
import (
"io"
"net/http"
"log"
)
func handler(w http.ResponseWriter, r *http.Request) {
resp, err := http.Get("http://leeroy-app:50051")
if err != nil {
panic(err)
}
defer resp.Body.Close()
if _, err := io.Copy(w, resp.Body); err != nil {
panic(err)
}
}
func main() {
log.Print("leeroy web server ready")
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}

View File

@ -0,0 +1,18 @@
apiVersion: skaffold/v2beta5
kind: Config
build:
artifacts:
- image: leeroy-web
context: leeroy-web
- image: leeroy-app
context: leeroy-app
deploy:
kubectl:
manifests:
- leeroy-web/kubernetes/*
- leeroy-app/kubernetes/*
portForward:
- resourceType: deployment
resourceName: leeroy-web
port: 8080
localPort: 9000