Skip to content

Commit

Permalink
Testing build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mik-dass committed Dec 9, 2019
1 parent 50762d8 commit 377ca01
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
5 changes: 1 addition & 4 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,8 @@ func Build(client *occlient.Client, componentName string, applicationName string
}

defer s.End(false)
if err := client.FollowBuildLog(buildName, stdout); err != nil {
return errors.Wrapf(err, "unable to follow logs for %s", buildName)
}

if err := client.WaitForBuildToFinish(buildName); err != nil {
if err := client.WaitForBuildToFinish(buildName, stdout); err != nil {
return errors.Wrapf(err, "unable to build %s, error: %s", buildName, b.String())
}
s.End(true)
Expand Down
43 changes: 29 additions & 14 deletions pkg/occlient/occlient.go
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,8 @@ func (c *Client) StartBuild(name string) (string, error) {
}

// WaitForBuildToFinish block and waits for build to finish. Returns error if build failed or was canceled.
func (c *Client) WaitForBuildToFinish(buildName string) error {
func (c *Client) WaitForBuildToFinish(buildName string, stdout io.Writer) error {
following := false
glog.V(4).Infof("Waiting for %s build to finish", buildName)

w, err := c.buildClient.Builds(c.Namespace).Watch(metav1.ListOptions{
Expand All @@ -1682,23 +1683,36 @@ func (c *Client) WaitForBuildToFinish(buildName string) error {
return errors.Wrapf(err, "unable to watch build")
}
defer w.Stop()
timeout := time.After(5 * time.Minute)
for {
val, ok := <-w.ResultChan()
if !ok {
break
}
if e, ok := val.Object.(*buildv1.Build); ok {
glog.V(4).Infof("Status of %s build is %s", e.Name, e.Status.Phase)
switch e.Status.Phase {
case buildv1.BuildPhaseComplete:
glog.V(4).Infof("Build %s completed.", e.Name)
return nil
case buildv1.BuildPhaseFailed, buildv1.BuildPhaseCancelled, buildv1.BuildPhaseError:
return errors.Errorf("build %s status %s", e.Name, e.Status.Phase)
select {
case val, ok := <-w.ResultChan():
if !ok {
break
}
if e, ok := val.Object.(*buildv1.Build); ok {
glog.V(4).Infof("Status of %s build is %s", e.Name, e.Status.Phase)
switch e.Status.Phase {
case buildv1.BuildPhaseComplete:
glog.V(4).Infof("Build %s completed.", e.Name)
return nil
case buildv1.BuildPhaseFailed, buildv1.BuildPhaseCancelled, buildv1.BuildPhaseError:
return errors.Errorf("build %s status %s", e.Name, e.Status.Phase)
case buildv1.BuildPhaseRunning:
// since the pod is ready and the build is now running, start following the logs
if !following {
following = true
err := c.FollowBuildLog(buildName, stdout)
if err != nil {
return err
}
}
}
}
case <-timeout:
return errors.Errorf("timeout waiting for build %s to start", buildName)
}
}
return nil
}

// WaitAndGetDC block and waits until the DeploymentConfig has updated it's annotation
Expand Down Expand Up @@ -1845,6 +1859,7 @@ func (c *Client) FollowBuildLog(buildName string, stdout io.Writer) error {
}

rd, err := c.buildClient.RESTClient().Get().
Timeout(5*time.Minute).
Namespace(c.Namespace).
Resource("builds").
Name(buildName).
Expand Down
2 changes: 1 addition & 1 deletion pkg/occlient/occlient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ func TestWaitForBuildToFinish(t *testing.T) {
return true, fkWatch, nil
})

err := fkclient.WaitForBuildToFinish(tt.buildName)
err := fkclient.WaitForBuildToFinish(tt.buildName, os.Stdout)
if !tt.wantErr == (err != nil) {
t.Errorf(" client.WaitForBuildToFinish(string) unexpected error %v, wantErr %v", err, tt.wantErr)
return
Expand Down

0 comments on commit 377ca01

Please sign in to comment.