Merged by openshift-bot
OpenShift Bot authored on 2016/09/29 14:29:01... | ... |
@@ -13,7 +13,6 @@ import ( |
13 | 13 |
"os" |
14 | 14 |
"path/filepath" |
15 | 15 |
"strings" |
16 |
- "sync" |
|
17 | 16 |
|
18 | 17 |
"github.com/golang/glog" |
19 | 18 |
"github.com/spf13/cobra" |
... | ... |
@@ -316,58 +315,36 @@ func (o *StartBuildOptions) Run() error { |
316 | 316 |
|
317 | 317 |
kcmdutil.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, "build", newBuild.Name, "started") |
318 | 318 |
|
319 |
- var ( |
|
320 |
- wg sync.WaitGroup |
|
321 |
- exitErr error |
|
322 |
- ) |
|
323 |
- |
|
324 |
- // Wait for the build to complete |
|
325 |
- if o.WaitForComplete { |
|
326 |
- wg.Add(1) |
|
327 |
- go func() { |
|
328 |
- defer wg.Done() |
|
329 |
- exitErr = WaitForBuildComplete(o.Client.Builds(o.Namespace), newBuild.Name) |
|
330 |
- }() |
|
331 |
- } |
|
332 |
- |
|
333 | 319 |
// Stream the logs from the build |
334 | 320 |
if o.Follow { |
335 |
- wg.Add(1) |
|
336 |
- go func() { |
|
337 |
- // if --wait option is set, then don't wait for logs to finish streaming |
|
338 |
- // but wait for the build to reach its final state |
|
339 |
- if o.WaitForComplete { |
|
340 |
- wg.Done() |
|
341 |
- } else { |
|
342 |
- defer wg.Done() |
|
343 |
- } |
|
344 |
- opts := buildapi.BuildLogOptions{ |
|
345 |
- Follow: true, |
|
346 |
- NoWait: false, |
|
347 |
- } |
|
348 |
- for { |
|
349 |
- rd, err := o.Client.BuildLogs(o.Namespace).Get(newBuild.Name, opts).Stream() |
|
350 |
- if err != nil { |
|
351 |
- // if --wait options is set, then retry the connection to build logs |
|
352 |
- // when we hit the timeout. |
|
353 |
- if o.WaitForComplete && oerrors.IsTimeoutErr(err) { |
|
354 |
- continue |
|
355 |
- } |
|
356 |
- fmt.Fprintf(o.ErrOut, "error getting logs: %v\n", err) |
|
357 |
- return |
|
358 |
- } |
|
359 |
- defer rd.Close() |
|
360 |
- if _, err = io.Copy(o.Out, rd); err != nil { |
|
361 |
- fmt.Fprintf(o.ErrOut, "error streaming logs: %v\n", err) |
|
321 |
+ opts := buildapi.BuildLogOptions{ |
|
322 |
+ Follow: true, |
|
323 |
+ NoWait: false, |
|
324 |
+ } |
|
325 |
+ for { |
|
326 |
+ rd, err := o.Client.BuildLogs(o.Namespace).Get(newBuild.Name, opts).Stream() |
|
327 |
+ if err != nil { |
|
328 |
+ // retry the connection to build logs when we hit the timeout. |
|
329 |
+ if oerrors.IsTimeoutErr(err) { |
|
330 |
+ fmt.Fprintf(o.ErrOut, "timed out getting logs, retrying\n") |
|
331 |
+ continue |
|
362 | 332 |
} |
333 |
+ fmt.Fprintf(o.ErrOut, "error getting logs (%v), waiting for build to complete\n", err) |
|
363 | 334 |
break |
364 | 335 |
} |
365 |
- }() |
|
336 |
+ defer rd.Close() |
|
337 |
+ if _, err = io.Copy(o.Out, rd); err != nil { |
|
338 |
+ fmt.Fprintf(o.ErrOut, "error streaming logs (%v), waiting for build to complete\n", err) |
|
339 |
+ } |
|
340 |
+ break |
|
341 |
+ } |
|
366 | 342 |
} |
367 | 343 |
|
368 |
- wg.Wait() |
|
344 |
+ if o.Follow || o.WaitForComplete { |
|
345 |
+ return WaitForBuildComplete(o.Client.Builds(o.Namespace), newBuild.Name) |
|
346 |
+ } |
|
369 | 347 |
|
370 |
- return exitErr |
|
348 |
+ return nil |
|
371 | 349 |
} |
372 | 350 |
|
373 | 351 |
// RunListBuildWebHooks prints the webhooks for the provided build config. |