Skip to content

Use kind to run integration tests on TravisCI #2196

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

Merged
merged 2 commits into from
Jun 8, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ jobs:
script:
- go build -o out/skaffold.exe cmd/skaffold/skaffold.go
- go test -short -timeout 60s ./...
- stage: integration
os: linux
go: "1.11.x"
before_install:
- curl -Lo ${HOME}/bin/kind https://github.com/kubernetes-sigs/kind/releases/download/v0.3.0/kind-linux-amd64
- chmod +x ${HOME}/bin/kind
script: make integration-in-kind
30 changes: 24 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ GSC_BUILD_LATEST ?= gs://$(RELEASE_BUCKET)/builds/latest
GSC_RELEASE_PATH ?= gs://$(RELEASE_BUCKET)/releases/$(VERSION)
GSC_RELEASE_LATEST ?= gs://$(RELEASE_BUCKET)/releases/latest

REMOTE_INTEGRATION ?= false
GCP_ONLY ?= false
GCP_PROJECT ?= k8s-skaffold
GKE_CLUSTER_NAME ?= integration-tests
GKE_ZONE ?= us-central1-a
Expand Down Expand Up @@ -90,13 +90,13 @@ install: $(GO_FILES) $(BUILD_DIR)

.PHONY: integration
integration: install
ifeq ($(REMOTE_INTEGRATION),true)
ifeq ($(GCP_ONLY),true)
gcloud container clusters get-credentials \
$(GKE_CLUSTER_NAME) \
--zone $(GKE_ZONE) \
--project $(GCP_PROJECT)
endif
REMOTE_INTEGRATION=$(REMOTE_INTEGRATION) go test -v $(REPOPATH)/integration -timeout 15m
GCP_ONLY=$(GCP_ONLY) go test -v $(REPOPATH)/integration -timeout 15m

.PHONY: release
release: cross $(BUILD_DIR)/VERSION
Expand Down Expand Up @@ -148,19 +148,37 @@ release-build-in-docker:
clean:
rm -rf $(BUILD_DIR)

.PHONY: integration-in-docker
integration-in-docker:
.PHONY: kind-cluster
kind-cluster:
kind get clusters | grep -q kind || kind create cluster

.PHONY: skaffold-builder
skaffold-builder:
-docker pull gcr.io/$(GCP_PROJECT)/skaffold-builder
docker build \
--cache-from gcr.io/$(GCP_PROJECT)/skaffold-builder \
-f deploy/skaffold/Dockerfile \
--target integration \
-t gcr.io/$(GCP_PROJECT)/skaffold-integration .

.PHONY: integration-in-kind
integration-in-kind: kind-cluster skaffold-builder
docker exec -it kind-control-plane cat /etc/kubernetes/admin.conf > /tmp/kind-config
echo '{}' > /tmp/docker-config
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp/kind-config:/kind-config \
-v /tmp/docker-config:/root/.docker/config.json \
-e KUBECONFIG=/kind-config \
gcr.io/$(GCP_PROJECT)/skaffold-integration

.PHONY: integration-in-docker
integration-in-docker: skaffold-builder
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(HOME)/.config/gcloud:/root/.config/gcloud \
-v $(GOOGLE_APPLICATION_CREDENTIALS):$(GOOGLE_APPLICATION_CREDENTIALS) \
-e REMOTE_INTEGRATION=true \
-e GCP_ONLY=$(GCP_ONLY) \
-e GCP_PROJECT=$(GCP_PROJECT) \
-e GKE_CLUSTER_NAME=$(GKE_CLUSTER_NAME) \
-e GKE_ZONE=$(GKE_ZONE) \
Expand Down
8 changes: 7 additions & 1 deletion cmd/skaffold/app/cmd/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package config
import (
"io/ioutil"
"path/filepath"
"strings"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context"
Expand Down Expand Up @@ -226,5 +227,10 @@ func GetInsecureRegistries() ([]string, error) {
func isDefaultLocal(kubeContext string) bool {
return kubeContext == constants.DefaultMinikubeContext ||
kubeContext == constants.DefaultDockerForDesktopContext ||
kubeContext == constants.DefaultDockerDesktopContext
kubeContext == constants.DefaultDockerDesktopContext ||
IsKindCluster(kubeContext)
}

func IsKindCluster(kubeContext string) bool {
return strings.HasSuffix(kubeContext, "@kind")
}
5 changes: 5 additions & 0 deletions deploy/skaffold/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ COPY . .
FROM builder as integration
ARG VERSION

ENV KIND_VERSION=v0.3.0
RUN curl -Lo kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64 && \
chmod +x kind && \
mv kind /usr/local/bin/

RUN make out/skaffold-linux-amd64 VERSION=$VERSION && mv out/skaffold-linux-amd64 /usr/bin/skaffold

CMD ["make", "integration"]
Expand Down
2 changes: 1 addition & 1 deletion hack/kokoro/presubmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export DOCKER_NAMESPACE=gcr.io/k8s-skaffold
source $KOKORO_GFILE_DIR/common.sh

pushd $KOKORO_ARTIFACTS_DIR/github/skaffold >/dev/null
make integration-in-docker
GCP_ONLY=true make integration-in-docker
popd

3 changes: 3 additions & 0 deletions integration/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func TestBuild(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

tests := []struct {
description string
Expand Down
15 changes: 15 additions & 0 deletions integration/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func TestConfigListForContext(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

out := skaffold.Config("list", "-c", "testdata/config/config.yaml", "-k", "test-context").RunOrFailOutput(t)

Expand All @@ -37,6 +40,9 @@ func TestConfigListForAll(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

out := skaffold.Config("list", "-c", "testdata/config/config.yaml", "--all").RunOrFailOutput(t)

Expand All @@ -54,6 +60,9 @@ func TestFailToSetUnrecognizedValue(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

err := skaffold.Config("set", "doubt-this-will-ever-be-a-config-key", "VALUE", "-c", "testdata/config/config.yaml", "--global").Run(t)

Expand All @@ -64,6 +73,9 @@ func TestSetDefaultRepoForContext(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

file, delete := testutil.TempFile(t, "config", nil)
defer delete()
Expand All @@ -78,6 +90,9 @@ func TestSetGlobalDefaultRepo(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

file, delete := testutil.TempFile(t, "config", nil)
defer delete()
Expand Down
3 changes: 3 additions & 0 deletions integration/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func TestDebug(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

tests := []struct {
description string
Expand Down
6 changes: 6 additions & 0 deletions integration/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func TestBuildDeploy(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

ns, client, deleteNs := SetupNamespace(t)
defer deleteNs()
Expand Down Expand Up @@ -79,6 +82,9 @@ func TestDeploy(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

ns, client, deleteNs := SetupNamespace(t)
defer deleteNs()
Expand Down
3 changes: 3 additions & 0 deletions integration/dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func TestDev(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

Run(t, "testdata/dev", "sh", "-c", "echo foo > foo")
defer Run(t, "testdata/dev", "rm", "foo")
Expand Down
3 changes: 3 additions & 0 deletions integration/diagnose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func TestDiagnose(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

tests := []struct {
name string
Expand Down
3 changes: 3 additions & 0 deletions integration/fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func TestFix(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

ns, _, deleteNs := SetupNamespace(t)
defer deleteNs()
Expand Down
5 changes: 2 additions & 3 deletions integration/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package integration

import (
"fmt"
"os"
"testing"

"github.com/GoogleContainerTools/skaffold/integration/skaffold"
Expand All @@ -33,8 +32,8 @@ func TestHelmDeploy(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if os.Getenv("REMOTE_INTEGRATION") != "true" {
t.Skip("skipping remote only test")
if !ShouldRunGCPOnlyTests() {
t.Skip("skipping gcp only test")
}

helmDir := "examples/helm-deployment"
Expand Down
3 changes: 3 additions & 0 deletions integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func TestInit(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

tests := []struct {
name string
Expand Down
3 changes: 3 additions & 0 deletions integration/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func TestEventLogRPC(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

rpcAddr := randomPort()
teardown := setupSkaffoldWithArgs(t, "--rpc-port", rpcAddr)
Expand Down
24 changes: 13 additions & 11 deletions integration/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package integration

import (
"os"
"testing"

"github.com/GoogleContainerTools/skaffold/integration/skaffold"
Expand All @@ -36,7 +35,7 @@ func TestRun(t *testing.T) {
deployments []string
pods []string
env []string
remoteOnly bool
gcpOnly bool
}{
{
description: "getting-started",
Expand Down Expand Up @@ -67,38 +66,38 @@ func TestRun(t *testing.T) {
description: "Google Cloud Build",
dir: "examples/google-cloud-build",
pods: []string{"getting-started"},
remoteOnly: true,
gcpOnly: true,
}, {
description: "Google Cloud Build with sub folder",
dir: "testdata/gcb-sub-folder",
pods: []string{"getting-started"},
remoteOnly: true,
gcpOnly: true,
}, {
description: "kaniko",
dir: "examples/kaniko",
pods: []string{"getting-started-kaniko"},
remoteOnly: true,
gcpOnly: true,
}, {
description: "kaniko local",
dir: "examples/kaniko-local",
pods: []string{"getting-started-kaniko"},
remoteOnly: true,
gcpOnly: true,
}, {
description: "kaniko local with sub folder",
dir: "testdata/kaniko-sub-folder",
pods: []string{"getting-started-kaniko"},
remoteOnly: true,
gcpOnly: true,
}, {
description: "kaniko microservices",
dir: "testdata/kaniko-microservices",
deployments: []string{"leeroy-app", "leeroy-web"},
remoteOnly: true,
gcpOnly: true,
}, {
description: "jib in googlecloudbuild",
dir: "testdata/jib",
args: []string{"-p", "gcb"},
deployments: []string{"web"},
remoteOnly: true,
gcpOnly: true,
}, {
description: "custom builder",
dir: "testdata/custom",
Expand All @@ -107,8 +106,11 @@ func TestRun(t *testing.T) {
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
if test.remoteOnly && os.Getenv("REMOTE_INTEGRATION") != "true" {
t.Skip("skipping remote only test")
if test.gcpOnly && !ShouldRunGCPOnlyTests() {
t.Skip("skipping gcp only test")
}
if !test.gcpOnly && ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

ns, client, deleteNs := SetupNamespace(t)
Expand Down
3 changes: 3 additions & 0 deletions integration/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func TestDevSync(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

ns, client, deleteNs := SetupNamespace(t)
defer deleteNs()
Expand Down
5 changes: 5 additions & 0 deletions integration/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package integration
import (
"context"
"fmt"
"os"
"os/exec"
"testing"
"time"
Expand All @@ -31,6 +32,10 @@ import (
"k8s.io/client-go/kubernetes"
)

func ShouldRunGCPOnlyTests() bool {
return os.Getenv("GCP_ONLY") == "true"
}

func Run(t *testing.T, dir, command string, args ...string) {
cmd := exec.Command(command, args...)
cmd.Dir = dir
Expand Down
Loading