diff --git a/Makefile b/Makefile index 50ce7644c57..9cf2c1a7380 100644 --- a/Makefile +++ b/Makefile @@ -86,15 +86,17 @@ install: $(GO_FILES) $(BUILD_DIR) .PHONY: integration integration: install - go test -v -tags integration $(REPOPATH)/integration -timeout 10m \ - --remote=$(REMOTE_INTEGRATION) \ - --gcp-project=$(GCP_PROJECT) \ - --gke-cluster-name=$(GKE_CLUSTER_NAME) \ - --gke-zone=$(GKE_ZONE) +ifeq ($(REMOTE_INTEGRATION),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 10m .PHONY: coverage coverage: $(BUILD_DIR) - go test -coverprofile=$(BUILD_DIR)/coverage.txt -covermode=atomic ./... + go test -short -coverprofile=$(BUILD_DIR)/coverage.txt -covermode=atomic ./... .PHONY: release release: cross $(BUILD_DIR)/VERSION diff --git a/appveyor.yml b/appveyor.yml index e8743a1abf8..6281dd91a83 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,4 +5,4 @@ environment: build_script: - go build -o out/skaffold.exe cmd/skaffold/skaffold.go test_script: - - go test ./... \ No newline at end of file + - go test -short -v -timeout 60s ./... \ No newline at end of file diff --git a/integration/build_test.go b/integration/build_test.go index f7a0c99571c..ad30b991862 100644 --- a/integration/build_test.go +++ b/integration/build_test.go @@ -1,5 +1,3 @@ -// +build integration - /* Copyright 2019 The Skaffold Authors @@ -26,6 +24,10 @@ import ( ) func TestBuild(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + tests := []struct { description string dir string diff --git a/integration/config_test.go b/integration/config_test.go index 91dc60eadb2..d39f838f4e5 100644 --- a/integration/config_test.go +++ b/integration/config_test.go @@ -1,5 +1,3 @@ -// +build integration - /* Copyright 2019 The Skaffold Authors @@ -24,14 +22,17 @@ import ( "strings" "testing" - yaml "gopkg.in/yaml.v2" - "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" + yaml "gopkg.in/yaml.v2" ) func TestListConfig(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + baseConfig := &config.Config{ Global: &config.ContextConfig{ DefaultRepo: "global-repository", @@ -95,6 +96,10 @@ func TestListConfig(t *testing.T) { } func TestSetConfig(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + baseConfig := &config.Config{ Global: &config.ContextConfig{ DefaultRepo: "global-repository", diff --git a/integration/deploy_test.go b/integration/deploy_test.go index 5b2ce3a86ee..5f95e1ffe8e 100644 --- a/integration/deploy_test.go +++ b/integration/deploy_test.go @@ -1,5 +1,3 @@ -// +build integration - /* Copyright 2019 The Skaffold Authors @@ -20,27 +18,29 @@ package integration import ( "context" - "time" - - meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "testing" + "time" kubernetesutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" + meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestDeploy(t *testing.T) { - ns, deleteNs := SetupNamespace(t) + if testing.Short() { + t.Skip("skipping integration test") + } + + ns, client, deleteNs := SetupNamespace(t) defer deleteNs() RunSkaffold(t, "deploy", "examples/kustomize", ns.Name, "", nil, "--images", "index.docker.io/library/busybox:1") depName := "kustomize-test" - if err := kubernetesutil.WaitForDeploymentToStabilize(context.Background(), Client, ns.Name, depName, 10*time.Minute); err != nil { + if err := kubernetesutil.WaitForDeploymentToStabilize(context.Background(), client, ns.Name, depName, 10*time.Minute); err != nil { t.Fatalf("Timed out waiting for deployment to stabilize") } - dep, err := Client.AppsV1().Deployments(ns.Name).Get(depName, meta_v1.GetOptions{}) + dep, err := client.AppsV1().Deployments(ns.Name).Get(depName, meta_v1.GetOptions{}) if err != nil { t.Fatalf("Could not find deployment: %s %s", ns.Name, depName) } diff --git a/integration/dev_test.go b/integration/dev_test.go index 2e46ef68ff7..e31d2071d8f 100644 --- a/integration/dev_test.go +++ b/integration/dev_test.go @@ -1,5 +1,3 @@ -// +build integration - /* Copyright 2019 The Skaffold Authors @@ -29,38 +27,44 @@ import ( ) func TestDev(t *testing.T) { - ns, deleteNs := SetupNamespace(t) - defer deleteNs() + if testing.Short() { + t.Skip("skipping integration test") + } + + Run(t, "testdata/dev", "sh", "-c", "echo foo > foo") + defer Run(t, "testdata/dev", "rm", "foo") - Run(t, "examples/test-dev-job", "touch", "foo") - defer Run(t, "examples/test-dev-job", "rm", "foo") + // Run skaffold build first to fail quickly on a build failure + RunSkaffold(t, "build", "testdata/dev", "", "", nil) + + ns, client, deleteNs := SetupNamespace(t) + defer deleteNs() cancel := make(chan bool) - go RunSkaffoldNoFail(cancel, "dev", "examples/test-dev-job", ns.Name, "", nil) + go RunSkaffoldNoFail(cancel, "dev", "testdata/dev", ns.Name, "", nil) defer func() { cancel <- true }() - jobName := "test-dev-job" - if err := kubernetesutil.WaitForJobToStabilize(context.Background(), Client, ns.Name, jobName, 10*time.Minute); err != nil { - t.Fatalf("Timed out waiting for job to stabilize") + deployName := "test-dev" + if err := kubernetesutil.WaitForDeploymentToStabilize(context.Background(), client, ns.Name, deployName, 10*time.Minute); err != nil { + t.Fatalf("Timed out waiting for deployment to stabilize") } - job, err := Client.BatchV1().Jobs(ns.Name).Get(jobName, meta_v1.GetOptions{}) + dep, err := client.AppsV1().Deployments(ns.Name).Get(deployName, meta_v1.GetOptions{}) if err != nil { - t.Fatalf("Could not find job: %s %s", ns.Name, jobName) + t.Fatalf("Could not find dep: %s %s", ns.Name, deployName) } - time.Sleep(5 * time.Second) + // Make a change to foo so that dev is forced to delete the Deployment and redeploy + Run(t, "testdata/dev", "sh", "-c", "echo bar > foo") - // Make a change to foo so that dev is forced to delete the job and redeploy - Run(t, "examples/test-dev-job", "sh", "-c", "echo bar > foo") - - // Make sure the UID of the old Job and the UID of the new Job is different + // Make sure the old Deployment and the new Deployment are different err = wait.PollImmediate(time.Millisecond*500, 10*time.Minute, func() (bool, error) { - newJob, err := Client.BatchV1().Jobs(ns.Name).Get(job.Name, meta_v1.GetOptions{}) + newDep, err := client.AppsV1().Deployments(ns.Name).Get(deployName, meta_v1.GetOptions{}) if err != nil { return false, nil } - return job.GetUID() != newJob.GetUID(), nil + + return dep.GetGeneration() != newDep.GetGeneration(), nil }) if err != nil { t.Fatalf("redeploy failed: %v", err) diff --git a/integration/examples/test-dev-job/k8s-job.yaml b/integration/examples/test-dev-job/k8s-job.yaml deleted file mode 100644 index 34eb068da14..00000000000 --- a/integration/examples/test-dev-job/k8s-job.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: batch/v1 -kind: Job -metadata: - name: test-dev-job -spec: - template: - spec: - containers: - - name: test-dev-job - image: gcr.io/k8s-skaffold/test-dev-job - restartPolicy: OnFailure diff --git a/integration/examples/test-dev-job/skaffold.yaml b/integration/examples/test-dev-job/skaffold.yaml deleted file mode 100644 index 050dd98485c..00000000000 --- a/integration/examples/test-dev-job/skaffold.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: skaffold/v1beta6 -kind: Config -build: - artifacts: - - image: gcr.io/k8s-skaffold/test-dev-job -deploy: - kubectl: - manifests: - - k8s-* -profiles: - - name: gcb - build: - googleCloudBuild: - projectId: k8s-skaffold diff --git a/integration/fix_test.go b/integration/fix_test.go index 75cf7b5f51b..2cf7732aab7 100644 --- a/integration/fix_test.go +++ b/integration/fix_test.go @@ -1,5 +1,3 @@ -// +build integration - /* Copyright 2019 The Skaffold Authors @@ -27,21 +25,25 @@ import ( ) func TestFix(t *testing.T) { - ns, deleteNs := SetupNamespace(t) + if testing.Short() { + t.Skip("skipping integration test") + } + + ns, _, deleteNs := SetupNamespace(t) defer deleteNs() fixCmd := exec.Command("skaffold", "fix", "-f", "skaffold.yaml") fixCmd.Dir = "testdata/fix" out, err := util.RunCmdOut(fixCmd) if err != nil { - t.Fatalf("testing error: %v", err) + t.Fatalf("skaffold fix: %v", err) } runCmd := exec.Command("skaffold", "run", "--namespace", ns.Name, "-f", "-") runCmd.Dir = "testdata/fix" runCmd.Stdin = bytes.NewReader(out) - if err := util.RunCmd(runCmd); err != nil { - t.Fatalf("testing error: %v", err) + if out, err := util.RunCmdOut(runCmd); err != nil { + t.Fatalf("skaffold run: %v, %s", err, out) } } diff --git a/integration/init_test.go b/integration/init_test.go index 445ceb45bd3..e8341864126 100644 --- a/integration/init_test.go +++ b/integration/init_test.go @@ -1,5 +1,3 @@ -// +build integration - /* Copyright 2019 The Skaffold Authors @@ -29,6 +27,10 @@ import ( ) func TestInit(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + type testCase struct { name string dir string diff --git a/integration/main_test.go b/integration/main_test.go deleted file mode 100644 index d6edda82cd0..00000000000 --- a/integration/main_test.go +++ /dev/null @@ -1,59 +0,0 @@ -// +build integration - -/* -Copyright 2019 The Skaffold 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 integration - -import ( - "flag" - "os" - "os/exec" - "testing" - - kubernetesutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" - "github.com/sirupsen/logrus" -) - -var ( - gkeZone = flag.String("gke-zone", "us-central1-a", "gke zone") - gkeClusterName = flag.String("gke-cluster-name", "integration-tests", "name of the integration test cluster") - gcpProject = flag.String("gcp-project", "k8s-skaffold", "the gcp project where the integration test cluster lives") - remote = flag.Bool("remote", false, "if true, run tests on a remote GKE cluster") -) - -func TestMain(m *testing.M) { - flag.Parse() - if *remote { - cmd := exec.Command("gcloud", "container", "clusters", "get-credentials", *gkeClusterName, "--zone", *gkeZone, "--project", *gcpProject) - logrus.Infoln(cmd) - - if out, err := util.RunCmdOut(cmd); err != nil { - logrus.Fatalf("Error authenticating to GKE cluster: %v, stdout: %v", err, out) - } - } - - var err error - Client, err = kubernetesutil.GetClientset() - if err != nil { - logrus.Fatalf("Test setup error: getting kubernetes client: %s", err) - } - - exitCode := m.Run() - - os.Exit(exitCode) -} diff --git a/integration/rpc_test.go b/integration/rpc_test.go index d706a74c414..8d67e6d6550 100644 --- a/integration/rpc_test.go +++ b/integration/rpc_test.go @@ -1,5 +1,3 @@ -// +build integration - /* Copyright 2019 The Skaffold Authors @@ -27,32 +25,35 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event/proto" "github.com/GoogleContainerTools/skaffold/testutil" "github.com/golang/protobuf/ptypes/empty" - "google.golang.org/grpc" ) var ( - retries = 10 - maxErrors = 5 + retries = 20 numLogEntries = 5 waitTime = 1 * time.Second ) func TestEventLog(t *testing.T) { - addr := ":12345" + if testing.Short() { + t.Skip("skipping integration test") + } + + Run(t, "testdata/dev", "sh", "-c", "echo foo > foo") + defer Run(t, "testdata/dev", "rm", "foo") + + // Run skaffold build first to fail quickly on a build failure + RunSkaffold(t, "build", "testdata/dev", "", "", nil) + // start a skaffold dev loop on an example - ns, deleteNs := SetupNamespace(t) + ns, _, deleteNs := SetupNamespace(t) defer deleteNs() - Run(t, "examples/test-dev-job", "touch", "foo") - defer Run(t, "examples/test-dev-job", "rm", "foo") - cancel := make(chan bool) - go RunSkaffoldNoFail(cancel, "dev", "examples/test-dev-job", ns.Name, "", nil, "--rpc-port", addr) + addr := ":12345" + go RunSkaffoldNoFail(cancel, "dev", "testdata/dev", ns.Name, "", nil, "--rpc-port", addr) defer func() { cancel <- true }() - time.Sleep(5 * time.Second) // give skaffold time to start up - // start a grpc client and make sure we can connect properly var conn *grpc.ClientConn var err error @@ -62,28 +63,32 @@ func TestEventLog(t *testing.T) { conn, err = grpc.Dial(addr, grpc.WithInsecure()) if err != nil { t.Logf("unable to establish skaffold grpc connection: retrying...") + attempts++ + if attempts == retries { + t.Fatalf("error establishing skaffold grpc connection") + } + time.Sleep(waitTime) - attempts = attempts + 1 - } else { - defer conn.Close() - client = proto.NewSkaffoldServiceClient(conn) - break - } - if attempts == retries { - t.Fatalf("error establishing skaffold grpc connection") + continue } + defer conn.Close() + + client = proto.NewSkaffoldServiceClient(conn) + break } ctx, ctxCancel := context.WithCancel(context.Background()) defer ctxCancel() - var stream proto.SkaffoldService_EventLogClient + var stream proto.SkaffoldService_EventLogClient + attempts = 0 for { stream, err = client.EventLog(ctx) if err == nil { break - } else if retries < retries { - retries = retries + 1 + } + if attempts < retries { + attempts++ t.Logf("waiting for connection...") time.Sleep(3 * time.Second) continue @@ -92,7 +97,7 @@ func TestEventLog(t *testing.T) { } // read a preset number of entries from the event log - logEntries := make([]*proto.LogEntry, 0) + var logEntries []*proto.LogEntry entriesReceived := 0 for { entry, err := stream.Recv() @@ -101,7 +106,7 @@ func TestEventLog(t *testing.T) { } if entry != nil { logEntries = append(logEntries, entry) - entriesReceived = entriesReceived + 1 + entriesReceived++ } if entriesReceived == numLogEntries { break @@ -111,11 +116,11 @@ func TestEventLog(t *testing.T) { for _, entry := range logEntries { switch entry.Event.GetEventType().(type) { case *proto.Event_MetaEvent: - metaEntries = metaEntries + 1 + metaEntries++ case *proto.Event_BuildEvent: - buildEntries = buildEntries + 1 + buildEntries++ case *proto.Event_DeployEvent: - deployEntries = deployEntries + 1 + deployEntries++ default: } } @@ -126,20 +131,26 @@ func TestEventLog(t *testing.T) { } func TestGetState(t *testing.T) { - addr := ":12345" + if testing.Short() { + t.Skip("skipping integration test") + } + + Run(t, "testdata/dev", "sh", "-c", "echo foo > foo") + defer Run(t, "testdata/dev", "rm", "foo") + + // Run skaffold build first to fail quickly on a build failure + RunSkaffold(t, "build", "testdata/dev", "", "", nil) + // start a skaffold dev loop on an example - ns, deleteNs := SetupNamespace(t) + ns, _, deleteNs := SetupNamespace(t) defer deleteNs() - Run(t, "examples/test-dev-job", "touch", "foo") - defer Run(t, "examples/test-dev-job", "rm", "foo") - + // start a skaffold dev loop on an example cancel := make(chan bool) - go RunSkaffoldNoFail(cancel, "dev", "examples/test-dev-job", ns.Name, "", nil, "--rpc-port", addr) + addr := ":12345" + go RunSkaffoldNoFail(cancel, "dev", "testdata/dev", ns.Name, "", nil, "--rpc-port", addr) defer func() { cancel <- true }() - time.Sleep(5 * time.Second) // give skaffold time to start up - // start a grpc client and make sure we can connect properly var conn *grpc.ClientConn var err error @@ -149,26 +160,40 @@ func TestGetState(t *testing.T) { conn, err = grpc.Dial(addr, grpc.WithInsecure()) if err != nil { t.Logf("unable to establish skaffold grpc connection: retrying...") + attempts++ + if attempts == retries { + t.Fatalf("error establishing skaffold grpc connection") + } + time.Sleep(waitTime) - attempts = attempts + 1 - } else { - defer conn.Close() - client = proto.NewSkaffoldServiceClient(conn) - break - } - if attempts == retries { - t.Fatalf("error establishing skaffold grpc connection") + continue } + defer conn.Close() + + client = proto.NewSkaffoldServiceClient(conn) + break } ctx, ctxCancel := context.WithCancel(context.Background()) defer ctxCancel() // retrieve the state and make sure everything looks correct - r, err := client.GetState(ctx, &empty.Empty{}) - if err != nil { - t.Fatalf("error retrieving state: %v", err) + var r *proto.State + attempts = 0 + for { + r, err = client.GetState(ctx, &empty.Empty{}) + if err == nil { + break + } + if attempts < retries { + attempts++ + t.Logf("waiting for connection...") + time.Sleep(3 * time.Second) + continue + } + t.Fatalf("error retrieving state: %v\n", err) } + for _, v := range r.BuildState.Artifacts { testutil.CheckDeepEqual(t, event.Complete, v) } diff --git a/integration/run_test.go b/integration/run_test.go index 08d34242a4d..c8038d24e85 100644 --- a/integration/run_test.go +++ b/integration/run_test.go @@ -1,5 +1,3 @@ -// +build integration - /* Copyright 2019 The Skaffold Authors @@ -20,6 +18,7 @@ package integration import ( "context" + "os" "testing" "time" @@ -27,6 +26,10 @@ import ( ) func TestRun(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + tests := []struct { description string dir string @@ -95,38 +98,38 @@ func TestRun(t *testing.T) { remoteOnly: true, }, { description: "docker plugin in gcb exec environment", - dir: "examples/test-plugin/gcb", + dir: "testdata/plugin/gcb", deployments: []string{"leeroy-app", "leeroy-web"}, }, { description: "bazel plugin in local exec environment", - dir: "examples/test-plugin/local/bazel", + dir: "testdata/plugin/local/bazel", pods: []string{"bazel"}, }, { description: "docker plugin in local exec environment", - dir: "examples/test-plugin/local/docker", + dir: "testdata/plugin/local/docker", deployments: []string{"leeroy-app", "leeroy-web"}, }, } for _, test := range tests { t.Run(test.description, func(t *testing.T) { - if !*remote && test.remoteOnly { + if test.remoteOnly && os.Getenv("REMOTE_INTEGRATION") != "true" { t.Skip("skipping remote only test") } - ns, deleteNs := SetupNamespace(t) + ns, client, deleteNs := SetupNamespace(t) defer deleteNs() RunSkaffold(t, "run", test.dir, ns.Name, test.filename, test.env) for _, p := range test.pods { - if err := kubernetesutil.WaitForPodReady(context.Background(), Client.CoreV1().Pods(ns.Name), p); err != nil { + if err := kubernetesutil.WaitForPodReady(context.Background(), client.CoreV1().Pods(ns.Name), p); err != nil { t.Fatalf("Timed out waiting for pod ready") } } for _, d := range test.deployments { - if err := kubernetesutil.WaitForDeploymentToStabilize(context.Background(), Client, ns.Name, d, 10*time.Minute); err != nil { + if err := kubernetesutil.WaitForDeploymentToStabilize(context.Background(), client, ns.Name, d, 10*time.Minute); err != nil { t.Fatalf("Timed out waiting for deployment to stabilize") } } diff --git a/integration/sync_test.go b/integration/sync_test.go index 0b2bdcaf377..4a0bc484615 100644 --- a/integration/sync_test.go +++ b/integration/sync_test.go @@ -1,5 +1,3 @@ -// +build integration - /* Copyright 2019 The Skaffold Authors @@ -30,22 +28,26 @@ import ( ) func TestDevSync(t *testing.T) { - ns, deleteNs := SetupNamespace(t) + if testing.Short() { + t.Skip("skipping integration test") + } + + ns, client, deleteNs := SetupNamespace(t) defer deleteNs() - RunSkaffold(t, "build", "examples/test-file-sync", ns.Name, "", nil) + RunSkaffold(t, "build", "testdata/file-sync", ns.Name, "", nil) cancel := make(chan bool) - go RunSkaffoldNoFail(cancel, "dev", "examples/test-file-sync", ns.Name, "", nil) + go RunSkaffoldNoFail(cancel, "dev", "testdata/file-sync", ns.Name, "", nil) defer func() { cancel <- true }() - if err := kubernetesutil.WaitForPodReady(context.Background(), Client.CoreV1().Pods(ns.Name), "test-file-sync"); err != nil { + if err := kubernetesutil.WaitForPodReady(context.Background(), client.CoreV1().Pods(ns.Name), "test-file-sync"); err != nil { t.Fatalf("Timed out waiting for pod ready") } - Run(t, "examples/test-file-sync", "mkdir", "-p", "test") - Run(t, "examples/test-file-sync", "touch", "test/foobar") - defer Run(t, "examples/test-file-sync", "rm", "-rf", "test") + Run(t, "testdata/file-sync", "mkdir", "-p", "test") + Run(t, "testdata/file-sync", "touch", "test/foobar") + defer Run(t, "testdata/file-sync", "rm", "-rf", "test") err := wait.PollImmediate(time.Millisecond*500, 1*time.Minute, func() (bool, error) { cmd := exec.Command("kubectl", "exec", "test-file-sync", "-n", ns.Name, "--", "ls", "/test") diff --git a/integration/examples/test-dev-job/Dockerfile b/integration/testdata/dev/Dockerfile similarity index 55% rename from integration/examples/test-dev-job/Dockerfile rename to integration/testdata/dev/Dockerfile index 835af0b34ee..16a8be7008c 100644 --- a/integration/examples/test-dev-job/Dockerfile +++ b/integration/testdata/dev/Dockerfile @@ -1,3 +1,3 @@ FROM golang:1.10.1-alpine3.7 as builder COPY foo /foo -CMD sleep 600 +CMD while true; do cat /foo; sleep 1; done diff --git a/integration/testdata/dev/k8s-job.yaml b/integration/testdata/dev/k8s-job.yaml new file mode 100644 index 00000000000..843b1bd4344 --- /dev/null +++ b/integration/testdata/dev/k8s-job.yaml @@ -0,0 +1,16 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-dev +spec: + selector: + matchLabels: + app: test-dev + template: + metadata: + labels: + app: test-dev + spec: + containers: + - name: test-dev + image: gcr.io/k8s-skaffold/test-dev diff --git a/integration/testdata/dev/skaffold.yaml b/integration/testdata/dev/skaffold.yaml new file mode 100644 index 00000000000..dee4a2749ae --- /dev/null +++ b/integration/testdata/dev/skaffold.yaml @@ -0,0 +1,9 @@ +apiVersion: skaffold/v1beta6 +kind: Config +build: + artifacts: + - image: gcr.io/k8s-skaffold/test-dev +deploy: + kubectl: + manifests: + - k8s-* diff --git a/integration/examples/test-file-sync/Dockerfile b/integration/testdata/file-sync/Dockerfile similarity index 100% rename from integration/examples/test-file-sync/Dockerfile rename to integration/testdata/file-sync/Dockerfile diff --git a/integration/examples/test-file-sync/foo b/integration/testdata/file-sync/foo similarity index 100% rename from integration/examples/test-file-sync/foo rename to integration/testdata/file-sync/foo diff --git a/integration/examples/test-file-sync/pod.yaml b/integration/testdata/file-sync/pod.yaml similarity index 100% rename from integration/examples/test-file-sync/pod.yaml rename to integration/testdata/file-sync/pod.yaml diff --git a/integration/examples/test-file-sync/skaffold.yaml b/integration/testdata/file-sync/skaffold.yaml similarity index 100% rename from integration/examples/test-file-sync/skaffold.yaml rename to integration/testdata/file-sync/skaffold.yaml diff --git a/integration/testdata/fix/Dockerfile b/integration/testdata/fix/Dockerfile index 08660c165d6..368cfde2af7 100644 --- a/integration/testdata/fix/Dockerfile +++ b/integration/testdata/fix/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.9.4-alpine3.7 +FROM golang:1.10.1-alpine3.7 WORKDIR /go/src/github.com/GoogleContainerTools/skaffold/examples/getting-started CMD ["./app"] diff --git a/integration/examples/test-plugin/gcb/leeroy-app/Dockerfile b/integration/testdata/plugin/gcb/leeroy-app/Dockerfile similarity index 100% rename from integration/examples/test-plugin/gcb/leeroy-app/Dockerfile rename to integration/testdata/plugin/gcb/leeroy-app/Dockerfile diff --git a/integration/examples/test-plugin/gcb/leeroy-app/app.go b/integration/testdata/plugin/gcb/leeroy-app/app.go similarity index 100% rename from integration/examples/test-plugin/gcb/leeroy-app/app.go rename to integration/testdata/plugin/gcb/leeroy-app/app.go diff --git a/integration/examples/test-plugin/gcb/leeroy-app/kubernetes/deployment.yaml b/integration/testdata/plugin/gcb/leeroy-app/kubernetes/deployment.yaml similarity index 100% rename from integration/examples/test-plugin/gcb/leeroy-app/kubernetes/deployment.yaml rename to integration/testdata/plugin/gcb/leeroy-app/kubernetes/deployment.yaml diff --git a/integration/examples/test-plugin/gcb/leeroy-web/Dockerfile b/integration/testdata/plugin/gcb/leeroy-web/Dockerfile similarity index 100% rename from integration/examples/test-plugin/gcb/leeroy-web/Dockerfile rename to integration/testdata/plugin/gcb/leeroy-web/Dockerfile diff --git a/integration/examples/test-plugin/gcb/leeroy-web/kubernetes/deployment.yaml b/integration/testdata/plugin/gcb/leeroy-web/kubernetes/deployment.yaml similarity index 100% rename from integration/examples/test-plugin/gcb/leeroy-web/kubernetes/deployment.yaml rename to integration/testdata/plugin/gcb/leeroy-web/kubernetes/deployment.yaml diff --git a/integration/examples/test-plugin/gcb/leeroy-web/web.go b/integration/testdata/plugin/gcb/leeroy-web/web.go similarity index 100% rename from integration/examples/test-plugin/gcb/leeroy-web/web.go rename to integration/testdata/plugin/gcb/leeroy-web/web.go diff --git a/integration/examples/test-plugin/gcb/skaffold.yaml b/integration/testdata/plugin/gcb/skaffold.yaml similarity index 100% rename from integration/examples/test-plugin/gcb/skaffold.yaml rename to integration/testdata/plugin/gcb/skaffold.yaml diff --git a/integration/examples/test-plugin/local/bazel/BUILD b/integration/testdata/plugin/local/bazel/BUILD similarity index 100% rename from integration/examples/test-plugin/local/bazel/BUILD rename to integration/testdata/plugin/local/bazel/BUILD diff --git a/integration/examples/test-plugin/local/bazel/WORKSPACE b/integration/testdata/plugin/local/bazel/WORKSPACE similarity index 100% rename from integration/examples/test-plugin/local/bazel/WORKSPACE rename to integration/testdata/plugin/local/bazel/WORKSPACE diff --git a/integration/examples/test-plugin/local/bazel/k8s/k8s-pod.yaml b/integration/testdata/plugin/local/bazel/k8s/k8s-pod.yaml similarity index 100% rename from integration/examples/test-plugin/local/bazel/k8s/k8s-pod.yaml rename to integration/testdata/plugin/local/bazel/k8s/k8s-pod.yaml diff --git a/integration/examples/test-plugin/local/bazel/main.go b/integration/testdata/plugin/local/bazel/main.go similarity index 100% rename from integration/examples/test-plugin/local/bazel/main.go rename to integration/testdata/plugin/local/bazel/main.go diff --git a/integration/examples/test-plugin/local/bazel/skaffold.yaml b/integration/testdata/plugin/local/bazel/skaffold.yaml similarity index 100% rename from integration/examples/test-plugin/local/bazel/skaffold.yaml rename to integration/testdata/plugin/local/bazel/skaffold.yaml diff --git a/integration/examples/test-plugin/local/docker/leeroy-app/Dockerfile b/integration/testdata/plugin/local/docker/leeroy-app/Dockerfile similarity index 100% rename from integration/examples/test-plugin/local/docker/leeroy-app/Dockerfile rename to integration/testdata/plugin/local/docker/leeroy-app/Dockerfile diff --git a/integration/examples/test-plugin/local/docker/leeroy-app/app.go b/integration/testdata/plugin/local/docker/leeroy-app/app.go similarity index 100% rename from integration/examples/test-plugin/local/docker/leeroy-app/app.go rename to integration/testdata/plugin/local/docker/leeroy-app/app.go diff --git a/integration/examples/test-plugin/local/docker/leeroy-app/kubernetes/deployment.yaml b/integration/testdata/plugin/local/docker/leeroy-app/kubernetes/deployment.yaml similarity index 100% rename from integration/examples/test-plugin/local/docker/leeroy-app/kubernetes/deployment.yaml rename to integration/testdata/plugin/local/docker/leeroy-app/kubernetes/deployment.yaml diff --git a/integration/examples/test-plugin/local/docker/leeroy-web/Dockerfile b/integration/testdata/plugin/local/docker/leeroy-web/Dockerfile similarity index 100% rename from integration/examples/test-plugin/local/docker/leeroy-web/Dockerfile rename to integration/testdata/plugin/local/docker/leeroy-web/Dockerfile diff --git a/integration/examples/test-plugin/local/docker/leeroy-web/kubernetes/deployment.yaml b/integration/testdata/plugin/local/docker/leeroy-web/kubernetes/deployment.yaml similarity index 100% rename from integration/examples/test-plugin/local/docker/leeroy-web/kubernetes/deployment.yaml rename to integration/testdata/plugin/local/docker/leeroy-web/kubernetes/deployment.yaml diff --git a/integration/examples/test-plugin/local/docker/leeroy-web/web.go b/integration/testdata/plugin/local/docker/leeroy-web/web.go similarity index 100% rename from integration/examples/test-plugin/local/docker/leeroy-web/web.go rename to integration/testdata/plugin/local/docker/leeroy-web/web.go diff --git a/integration/examples/test-plugin/local/docker/skaffold.yaml b/integration/testdata/plugin/local/docker/skaffold.yaml similarity index 100% rename from integration/examples/test-plugin/local/docker/skaffold.yaml rename to integration/testdata/plugin/local/docker/skaffold.yaml diff --git a/integration/util.go b/integration/util.go index d47bd2b2c59..7bf94e7d60b 100644 --- a/integration/util.go +++ b/integration/util.go @@ -17,18 +17,19 @@ limitations under the License. package integration import ( + "fmt" "os" "os/exec" "testing" + kubernetesutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" + "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" ) -var Client kubernetes.Interface - func RunSkaffold(t *testing.T, command, dir, namespace, filename string, env []string, additionalArgs ...string) { if err := RunSkaffoldNoFail(make(chan bool), command, dir, namespace, filename, env, additionalArgs...); err != nil { t.Fatalf("skaffold delete: %v", err) @@ -72,8 +73,13 @@ func Run(t *testing.T, dir, command string, args ...string) { } } -func SetupNamespace(t *testing.T) (*v1.Namespace, func()) { - ns, err := Client.CoreV1().Namespaces().Create(&v1.Namespace{ +func SetupNamespace(t *testing.T) (*v1.Namespace, kubernetes.Interface, func()) { + client, err := kubernetesutil.GetClientset() + if err != nil { + logrus.Fatalf("Test setup error: getting kubernetes client: %s", err) + } + + ns, err := client.CoreV1().Namespaces().Create(&v1.Namespace{ ObjectMeta: meta_v1.ObjectMeta{ GenerateName: "skaffold", }, @@ -82,7 +88,9 @@ func SetupNamespace(t *testing.T) (*v1.Namespace, func()) { t.Fatalf("creating namespace: %s", err) } - return ns, func() { - Client.CoreV1().Namespaces().Delete(ns.Name, &meta_v1.DeleteOptions{}) + fmt.Println("Namespace:", ns.Name) + + return ns, client, func() { + client.CoreV1().Namespaces().Delete(ns.Name, &meta_v1.DeleteOptions{}) } } diff --git a/pkg/skaffold/kubernetes/wait.go b/pkg/skaffold/kubernetes/wait.go index ab05d1043c2..9db7c0588ff 100644 --- a/pkg/skaffold/kubernetes/wait.go +++ b/pkg/skaffold/kubernetes/wait.go @@ -167,17 +167,3 @@ func WaitForDeploymentToStabilize(ctx context.Context, c kubernetes.Interface, n }) return err } - -// WaitForJobToStabilize waits till the Job has at least one active pod -func WaitForJobToStabilize(ctx context.Context, c kubernetes.Interface, ns, name string, timeout time.Duration) error { - ctx, cancelTimeout := context.WithTimeout(ctx, timeout) - defer cancelTimeout() - - return wait.PollImmediateUntil(time.Millisecond*500, func() (bool, error) { - job, err := c.BatchV1().Jobs(ns).Get(name, meta_v1.GetOptions{}) - if err != nil { - return false, nil - } - return job.Status.Active > 0, nil - }, ctx.Done()) -} diff --git a/test.sh b/test.sh index e2506913465..e0ebb1c58de 100755 --- a/test.sh +++ b/test.sh @@ -21,7 +21,7 @@ GREEN='\033[0;32m' RESET='\033[0m' echo "Running go tests..." -go test -cover -v -timeout 60s `go list ./... | grep -v vendor` | sed ''/PASS/s//$(printf "${GREEN}PASS${RESET}")/'' | sed ''/FAIL/s//$(printf "${RED}FAIL${RESET}")/'' +go test -cover -short -v -timeout 60s ./... | sed ''/PASS/s//$(printf "${GREEN}PASS${RESET}")/'' | sed ''/FAIL/s//$(printf "${RED}FAIL${RESET}")/'' GO_TEST_EXIT_CODE=${PIPESTATUS[0]} if [[ $GO_TEST_EXIT_CODE -ne 0 ]]; then exit $GO_TEST_EXIT_CODE