From 2d9b44611cc578dd7f38d36af711eacc0ae40f40 Mon Sep 17 00:00:00 2001 From: Priya Modali Date: Thu, 24 Dec 2020 20:39:32 -0800 Subject: [PATCH 1/4] Adding test to the dev loop. --- pkg/skaffold/runner/build_deploy.go | 10 +++++----- pkg/skaffold/runner/build_deploy_test.go | 5 ++++- pkg/skaffold/runner/dev.go | 20 +++++++++++++++++--- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/pkg/skaffold/runner/build_deploy.go b/pkg/skaffold/runner/build_deploy.go index c66db8ae5c6..c32abe7557e 100644 --- a/pkg/skaffold/runner/build_deploy.go +++ b/pkg/skaffold/runner/build_deploy.go @@ -79,11 +79,11 @@ func (r *SkaffoldRunner) Build(ctx context.Context, out io.Writer, artifacts []* return nil, err } - if !r.runCtx.SkipTests() { - if err = r.tester.Test(ctx, out, bRes); err != nil { - return nil, err - } - } + // if !r.runCtx.SkipTests() { + // if err = r.tester.Test(ctx, out, bRes); err != nil { + // return nil, err + // } + // } // Update which images are logged. r.addTagsToPodSelector(bRes) diff --git a/pkg/skaffold/runner/build_deploy_test.go b/pkg/skaffold/runner/build_deploy_test.go index 1a541e0a0a6..242cc2ee1c2 100644 --- a/pkg/skaffold/runner/build_deploy_test.go +++ b/pkg/skaffold/runner/build_deploy_test.go @@ -139,7 +139,10 @@ func TestBuildTestDeploy(t *testing.T) { runner := createRunner(t, test.testBench, nil, artifacts) bRes, err := runner.Build(ctx, ioutil.Discard, artifacts) if err == nil { - err = runner.DeployAndLog(ctx, ioutil.Discard, bRes) + err = runner.Test(ctx, ioutil.Discard, bRes) + if err == nil { + err = runner.DeployAndLog(ctx, ioutil.Discard, bRes) + } } t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expectedActions, test.testBench.Actions()) diff --git a/pkg/skaffold/runner/dev.go b/pkg/skaffold/runner/dev.go index c50bccbec9d..3bad1df8e1d 100644 --- a/pkg/skaffold/runner/dev.go +++ b/pkg/skaffold/runner/dev.go @@ -102,11 +102,19 @@ func (r *SkaffoldRunner) doDev(ctx context.Context, out io.Writer, logger *kuber instrumentation.AddDevIteration("build") meterUpdated = true } - if _, err := r.Build(ctx, out, r.changeSet.needsRebuild); err != nil { - logrus.Warnln("Skipping deploy due to error:", err) + bRes, err := r.Build(ctx, out, r.changeSet.needsRebuild) + if err != nil { + logrus.Warnln("Skipping test and deploy due to build error:", err) event.DevLoopFailedInPhase(r.devIteration, sErrors.Build, err) return nil } + if !r.runCtx.SkipTests() { + if err = r.Test(ctx, out, bRes); err != nil { + logrus.Warnln("Skipping deploy due to test error:", err) + event.DevLoopFailedInPhase(r.devIteration, sErrors.Build, err) + return nil + } + } } if needsDeploy { @@ -134,7 +142,7 @@ func (r *SkaffoldRunner) doDev(ctx context.Context, out io.Writer, logger *kuber return nil } -// Dev watches for changes and runs the skaffold build and deploy +// Dev watches for changes and runs the skaffold build, test and deploy // config until interrupted by the user. func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*latest.Artifact) error { event.DevLoopInProgress(r.devIteration) @@ -219,6 +227,12 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*la event.DevLoopFailedInPhase(r.devIteration, sErrors.Build, err) return fmt.Errorf("exiting dev mode because first build failed: %w", err) } + if !r.runCtx.SkipTests() { + if err = r.Test(ctx, out, bRes); err != nil { + event.DevLoopFailedInPhase(r.devIteration, sErrors.Build, err) + return fmt.Errorf("exiting dev mode because test failed after first build: %w", err) + } + } logger := r.createLogger(out, bRes) defer logger.Stop() From 106a6984047037786d0f06550fefb656b06c609d Mon Sep 17 00:00:00 2001 From: Priya Modali Date: Thu, 24 Dec 2020 21:50:32 -0800 Subject: [PATCH 2/4] Increasing timeouts. --- integration/debug_test.go | 2 +- integration/dev_test.go | 2 +- integration/util.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration/debug_test.go b/integration/debug_test.go index 527c0854d15..8ba83945233 100644 --- a/integration/debug_test.go +++ b/integration/debug_test.go @@ -167,7 +167,7 @@ func waitForDebugEvent(t *testing.T, client *NSKubernetesClient, rpcAddr string) _, entries := apiEvents(t, rpcAddr) - timeout := time.After(1 * time.Minute) + timeout := time.After(5 * time.Minute) for { select { case <-timeout: diff --git a/integration/dev_test.go b/integration/dev_test.go index 9a22d02cb6d..d543cc099ae 100644 --- a/integration/dev_test.go +++ b/integration/dev_test.go @@ -244,7 +244,7 @@ func TestDevPortForwardGKELoadBalancer(t *testing.T) { } func getLocalPortFromPortForwardEvent(t *testing.T, entries chan *proto.LogEntry, resourceName, resourceType, namespace string) (string, int) { - timeout := time.After(1 * time.Minute) + timeout := time.After(5 * time.Minute) for { select { case <-timeout: diff --git a/integration/util.go b/integration/util.go index 51fdd586c70..a21556e6b9e 100644 --- a/integration/util.go +++ b/integration/util.go @@ -180,7 +180,7 @@ func (k *NSKubernetesClient) WaitForPodsInPhase(expectedPhase v1.PodPhase, podNa logrus.Infoln("Waiting for pods", podNames, "to be ready") - ctx, cancelTimeout := context.WithTimeout(context.Background(), 5*time.Minute) + ctx, cancelTimeout := context.WithTimeout(context.Background(), 8*time.Minute) defer cancelTimeout() pods := k.Pods() From 6f3e2b244e639b7048d12db8d21f468db4bbe00c Mon Sep 17 00:00:00 2001 From: Priya Modali Date: Mon, 28 Dec 2020 11:34:39 -0800 Subject: [PATCH 3/4] Revert "Increasing timeouts." This reverts commit 106a6984047037786d0f06550fefb656b06c609d. --- integration/debug_test.go | 2 +- integration/dev_test.go | 2 +- integration/util.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration/debug_test.go b/integration/debug_test.go index 8ba83945233..527c0854d15 100644 --- a/integration/debug_test.go +++ b/integration/debug_test.go @@ -167,7 +167,7 @@ func waitForDebugEvent(t *testing.T, client *NSKubernetesClient, rpcAddr string) _, entries := apiEvents(t, rpcAddr) - timeout := time.After(5 * time.Minute) + timeout := time.After(1 * time.Minute) for { select { case <-timeout: diff --git a/integration/dev_test.go b/integration/dev_test.go index d543cc099ae..9a22d02cb6d 100644 --- a/integration/dev_test.go +++ b/integration/dev_test.go @@ -244,7 +244,7 @@ func TestDevPortForwardGKELoadBalancer(t *testing.T) { } func getLocalPortFromPortForwardEvent(t *testing.T, entries chan *proto.LogEntry, resourceName, resourceType, namespace string) (string, int) { - timeout := time.After(5 * time.Minute) + timeout := time.After(1 * time.Minute) for { select { case <-timeout: diff --git a/integration/util.go b/integration/util.go index a21556e6b9e..51fdd586c70 100644 --- a/integration/util.go +++ b/integration/util.go @@ -180,7 +180,7 @@ func (k *NSKubernetesClient) WaitForPodsInPhase(expectedPhase v1.PodPhase, podNa logrus.Infoln("Waiting for pods", podNames, "to be ready") - ctx, cancelTimeout := context.WithTimeout(context.Background(), 8*time.Minute) + ctx, cancelTimeout := context.WithTimeout(context.Background(), 5*time.Minute) defer cancelTimeout() pods := k.Pods() From 3a7bf312e5cb8b4213843d29c83c05adf9a24547 Mon Sep 17 00:00:00 2001 From: Priya Modali Date: Tue, 5 Jan 2021 17:39:06 -0800 Subject: [PATCH 4/4] Removed commented code. --- pkg/skaffold/runner/build_deploy.go | 6 ------ pkg/skaffold/runner/dev.go | 1 + 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/pkg/skaffold/runner/build_deploy.go b/pkg/skaffold/runner/build_deploy.go index c32abe7557e..3b04131af8f 100644 --- a/pkg/skaffold/runner/build_deploy.go +++ b/pkg/skaffold/runner/build_deploy.go @@ -79,12 +79,6 @@ func (r *SkaffoldRunner) Build(ctx context.Context, out io.Writer, artifacts []* return nil, err } - // if !r.runCtx.SkipTests() { - // if err = r.tester.Test(ctx, out, bRes); err != nil { - // return nil, err - // } - // } - // Update which images are logged. r.addTagsToPodSelector(bRes) diff --git a/pkg/skaffold/runner/dev.go b/pkg/skaffold/runner/dev.go index 3bad1df8e1d..a4f6c199e7c 100644 --- a/pkg/skaffold/runner/dev.go +++ b/pkg/skaffold/runner/dev.go @@ -108,6 +108,7 @@ func (r *SkaffoldRunner) doDev(ctx context.Context, out io.Writer, logger *kuber event.DevLoopFailedInPhase(r.devIteration, sErrors.Build, err) return nil } + // TODO(modali): Add skipTest boolean to Tester itself to avoid this check. if !r.runCtx.SkipTests() { if err = r.Test(ctx, out, bRes); err != nil { logrus.Warnln("Skipping deploy due to test error:", err)