Skip to content

Commit

Permalink
Merge pull request #79 from drone-runners/timeout-on-exit-code-2
Browse files Browse the repository at this point in the history
fail on error and exit code 2
  • Loading branch information
marko-gacesa committed Sep 21, 2021
2 parents 129f4b1 + 08e609e commit 278de41
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion engine/podwatcher/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ type containerWatchInfo struct {
exitCode int32
reason string

addedAt time.Time
addedAt time.Time
failedAt time.Time
}

type containerState int
Expand Down
36 changes: 35 additions & 1 deletion engine/podwatcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,41 @@ func (pw *PodWatcher) updateContainers(containers []containerInfo) {
// Often container the current image will revert back to the placeholder image.
// Kubernetes is probably downloading an image for the container in the background.
if cs.state == stateTerminated && cs.exitCode == 2 && cs.reason == "Error" {
if cs.restartCount == 0 {
continue
}

if c.failedAt.IsZero() {
logrus.
WithField("pod", pw.podName).
WithField("container", c.id).
WithFields(cs.stateToMap()).
Trace("PodWatcher: Container failed. Trying recovery...")
c.failedAt = time.Now()
} else if time.Since(c.failedAt) < time.Minute {
logrus.
WithField("pod", pw.podName).
WithField("container", c.id).
WithFields(cs.stateToMap()).
Trace("PodWatcher: Container failed. Waiting to recover...")
} else {
logrus.
WithField("pod", pw.podName).
WithField("container", c.id).
WithFields(cs.stateToMap()).
Debug("PodWatcher: Container failed.")

c.stepState = stepStateFailed
c.exitCode = cs.exitCode
c.reason = cs.reason

pw.notifyClients(c)
}

continue

} else {
c.failedAt = time.Time{}
}

switch cs.state {
Expand All @@ -200,7 +234,7 @@ func (pw *PodWatcher) updateContainers(containers []containerInfo) {
WithField("pod", pw.podName).
WithField("container", c.id).
WithFields(cs.stateToMap()).
Debug("PodWatcher: Container failed.")
Debug("PodWatcher: Container placeholder terminated.")
} else {
c.stepState = stepStateFinished

Expand Down

0 comments on commit 278de41

Please sign in to comment.