-
Notifications
You must be signed in to change notification settings - Fork 244
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
Testing build fix #2406
Testing build fix #2406
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ type CreateArgs struct { | |
|
||
const ( | ||
OcUpdateTimeout = 5 * time.Minute | ||
OcBuildTimeout = 5 * time.Minute | ||
OpenShiftNameSpace = "openshift" | ||
|
||
// The length of the string to be generated for names of resources | ||
|
@@ -1672,33 +1673,55 @@ 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 indicates if we have already setup the following logic | ||
following := false | ||
glog.V(4).Infof("Waiting for %s build to finish", buildName) | ||
|
||
// start a watch on the build resources and look for the given build name | ||
w, err := c.buildClient.Builds(c.Namespace).Watch(metav1.ListOptions{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand this is not touched in the proposed PR but can we add a comment that describes what this all about? At least I didn't understand a thing here. 😞 |
||
FieldSelector: fields.Set{"metadata.name": buildName}.AsSelector().String(), | ||
}) | ||
if err != nil { | ||
return errors.Wrapf(err, "unable to watch build") | ||
} | ||
defer w.Stop() | ||
timeout := time.After(OcBuildTimeout) | ||
for { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't understand what's going on in this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can help here a bit. So here first thing to observe is the now the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as for the need for the |
||
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 { | ||
// when a event is received regarding the given buildName | ||
case val, ok := <-w.ResultChan(): | ||
if !ok { | ||
break | ||
} | ||
// cast the object returned to a build object and check the phase of the build | ||
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: | ||
// the build is completed thus return | ||
glog.V(4).Infof("Build %s completed.", e.Name) | ||
return nil | ||
case buildv1.BuildPhaseFailed, buildv1.BuildPhaseCancelled, buildv1.BuildPhaseError: | ||
// the build failed/got cancelled/error occurred thus return with error | ||
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 { | ||
// setting following to true as we need to set it up only once | ||
following = true | ||
err := c.FollowBuildLog(buildName, stdout) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of this above looks good! |
||
} | ||
} | ||
case <-timeout: | ||
// timeout has occurred while waiting for the build to start/complete, so error out | ||
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 | ||
|
@@ -1845,6 +1868,7 @@ func (c *Client) FollowBuildLog(buildName string, stdout io.Writer) error { | |
} | ||
|
||
rd, err := c.buildClient.RESTClient().Get(). | ||
Timeout(OcBuildTimeout). | ||
Namespace(c.Namespace). | ||
Resource("builds"). | ||
Name(buildName). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need more description on this, bit confused why we're setting following to false then true when going through the channel loop.