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

[kaniko] Stop printing the logs on ctrl-c #3069

Merged
merged 1 commit into from
Oct 16, 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
2 changes: 1 addition & 1 deletion pkg/skaffold/build/cluster/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (b *Builder) runKanikoBuild(ctx context.Context, out io.Writer, artifact *l
return "", errors.Wrap(err, "modifying kaniko pod")
}

waitForLogs := streamLogs(out, pod.Name, pods)
waitForLogs := streamLogs(ctx, out, pod.Name, pods)

err = kubernetes.WaitForPodSucceeded(ctx, pods, pod.Name, b.timeout)
waitForLogs()
Expand Down
22 changes: 18 additions & 4 deletions pkg/skaffold/build/cluster/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ limitations under the License.
package cluster

import (
"bufio"
"context"
"fmt"
"io"
"sync"
"sync/atomic"
Expand All @@ -40,7 +43,7 @@ func logLevel() logrus.Level {
return level
}

func streamLogs(out io.Writer, name string, pods corev1.PodInterface) func() {
func streamLogs(ctx context.Context, out io.Writer, name string, pods corev1.PodInterface) func() {
var wg sync.WaitGroup
wg.Add(1)

Expand All @@ -60,9 +63,20 @@ func streamLogs(out io.Writer, name string, pods corev1.PodInterface) func() {
continue
}

w, _ := io.Copy(out, r)
atomic.AddInt64(&written, w)
return
scanner := bufio.NewScanner(r)
for {
select {
case <-ctx.Done():
return // The build was cancelled
default:
if !scanner.Scan() {
return // No more logs
}

fmt.Fprintln(out, scanner.Text())
atomic.AddInt64(&written, 1)
}
}
}
}()

Expand Down