Skip to content

Commit

Permalink
Merge pull request #2721 from dgageot/fix-2669
Browse files Browse the repository at this point in the history
Don’t store log lines as mutable slices of bytes
  • Loading branch information
tejal29 authored Aug 26, 2019
2 parents 06a867f + d45cce3 commit 83bf3fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
15 changes: 7 additions & 8 deletions pkg/skaffold/build/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ func InParallel(ctx context.Context, out io.Writer, tags tag.ImageTags, artifact
defer cancel()

results := new(sync.Map)
outputs := make([]chan []byte, len(artifacts))
outputs := make([]chan string, len(artifacts))

// Run builds in //
wg.Add(len(artifacts))
for i := range artifacts {
outputs[i] = make(chan []byte, buffSize)
outputs[i] = make(chan string, buffSize)
r, w := io.Pipe()
cw := setUpColorWriter(w, out)

Expand Down Expand Up @@ -95,10 +95,10 @@ func runBuild(ctx context.Context, cw io.WriteCloser, tags tag.ImageTags, artifa
cw.Close()
}

func readOutputAndWriteToChannel(r io.Reader, lines chan []byte) {
func readOutputAndWriteToChannel(r io.Reader, lines chan string) {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
lines <- scanner.Bytes()
lines <- scanner.Text()
}
close(lines)
}
Expand All @@ -119,7 +119,7 @@ func getBuildResult(ctx context.Context, cw io.Writer, tags tag.ImageTags, artif
return build(ctx, cw, artifact, tag)
}

func collectResults(out io.Writer, artifacts []*latest.Artifact, results *sync.Map, outputs []chan []byte) ([]Artifact, error) {
func collectResults(out io.Writer, artifacts []*latest.Artifact, results *sync.Map, outputs []chan string) ([]Artifact, error) {
var built []Artifact
for i, artifact := range artifacts {
// Wait for build to complete.
Expand All @@ -140,9 +140,8 @@ func collectResults(out io.Writer, artifacts []*latest.Artifact, results *sync.M
return built, nil
}

func printResult(out io.Writer, output chan []byte) {
func printResult(out io.Writer, output chan string) {
for line := range output {
out.Write(line)
fmt.Fprintln(out)
fmt.Fprintln(out, line)
}
}
6 changes: 3 additions & 3 deletions pkg/skaffold/build/parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ func TestColoredOutput(t *testing.T) {
}
}

func setUpChannels(n int) []chan []byte {
outputs := make([]chan []byte, n)
func setUpChannels(n int) []chan string {
outputs := make([]chan string, n)
for i := 0; i < n; i++ {
outputs[i] = make(chan []byte, 10)
outputs[i] = make(chan string, 10)
close(outputs[i])
}
return outputs
Expand Down

0 comments on commit 83bf3fd

Please sign in to comment.