Skip to content
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

Fix skaffold deploy --tail #3049

Merged
merged 1 commit into from
Oct 14, 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
39 changes: 39 additions & 0 deletions integration/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ limitations under the License.
package integration

import (
"bufio"
"strings"
"testing"
"time"

"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/flags"
"github.com/GoogleContainerTools/skaffold/integration/skaffold"
Expand Down Expand Up @@ -99,6 +101,43 @@ func TestDeploy(t *testing.T) {
skaffold.Delete().InDir("examples/kustomize").InNs(ns.Name).RunOrFail(t)
}

func TestDeployTail(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()

out, cancel := skaffold.Deploy("--tail", "--images", "busybox:latest").InDir("testdata/deploy-hello-tail").InNs(ns.Name).RunBackgroundOutput(t)
defer cancel()

// Wait for the logs to print "Hello world!"
lines := make(chan string)
go func() {
scanner := bufio.NewScanner(out)
for scanner.Scan() {
lines <- scanner.Text()
}
}()

timer := time.NewTimer(30 * time.Second)
defer timer.Stop()
for {
select {
case <-timer.C:
t.Fatal("timeout")
case line := <-lines:
if strings.Contains(line, "Hello world!") {
return
}
}
}
}

func TestDeployWithInCorrectConfig(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
Expand Down
15 changes: 13 additions & 2 deletions integration/skaffold/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,22 @@ func (b *RunBuilder) WithEnv(env []string) *RunBuilder {
}

// RunBackground runs the skaffold command in the background.
// This also returns a teardown function that stops skaffold.
// Returns a teardown function that stops skaffold.
func (b *RunBuilder) RunBackground(t *testing.T) context.CancelFunc {
_, cancel := b.RunBackgroundOutput(t)
return cancel
}

// RunBackgroundOutput runs the skaffold command in the background.
// Returns a teardown function that stops skaffold.
func (b *RunBuilder) RunBackgroundOutput(t *testing.T) (io.ReadCloser, context.CancelFunc) {
t.Helper()

pr, pw := io.Pipe()

ctx, cancel := context.WithCancel(context.Background())
cmd := b.cmd(ctx)
cmd.Stdout = pw
logrus.Infoln(cmd.Args)

start := time.Now()
Expand All @@ -145,9 +155,10 @@ func (b *RunBuilder) RunBackground(t *testing.T) context.CancelFunc {
logrus.Infoln("Ran in", time.Since(start))
}()

return func() {
return pr, func() {
cancel()
cmd.Wait()
pr.Close()
}
}

Expand Down
12 changes: 12 additions & 0 deletions integration/testdata/deploy-hello-tail/k8s/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox-hello
spec:
containers:
- name: busybox-hello
image: busybox
args:
- sh
- -c
- "while :; do echo 'Hello world!'; sleep 1; done"
2 changes: 2 additions & 0 deletions integration/testdata/deploy-hello-tail/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apiVersion: skaffold/v1beta16
kind: Config
1 change: 1 addition & 0 deletions pkg/skaffold/runner/build_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (r *SkaffoldRunner) DeployAndLog(ctx context.Context, out io.Writer, artifa
var imageNames []string
for _, artifact := range artifacts {
imageNames = append(imageNames, artifact.ImageName)
r.podSelector.Add(artifact.Tag)
}

logger := r.newLoggerForImages(out, imageNames)
Expand Down