Skip to content

Commit

Permalink
fix(conttroller): Always set finishedAt dote. Fixes #6135 (#6139)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Collins <alex_collins@intuit.com>
  • Loading branch information
alexec authored Jun 26, 2021
1 parent 92eb8b7 commit 19da541
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
24 changes: 6 additions & 18 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1174,14 +1174,7 @@ func (woc *wfOperationCtx) assessNodeStatus(pod *apiv1.Pod, node *wfv1.NodeStatu

if node.Fulfilled() && node.FinishedAt.IsZero() {
updated = true
if !node.IsDaemoned() {
node.FinishedAt = getLatestFinishedAt(pod)
}
if node.FinishedAt.IsZero() {
// If we get here, the container is daemoned so the
// finishedAt might not have been set.
node.FinishedAt = metav1.Time{Time: time.Now().UTC()}
}
node.FinishedAt = getLatestFinishedAt(pod)
node.ResourcesDuration = resource.DurationForPod(pod)
}
if updated {
Expand Down Expand Up @@ -1217,18 +1210,13 @@ func (woc *wfOperationCtx) cleanUpPod(pod *apiv1.Pod, tmpl wfv1.Template) {
}
}

// getLatestFinishedAt returns the latest finishAt timestamp from all the
// containers of this pod.
func getLatestFinishedAt(pod *apiv1.Pod) metav1.Time {
var latest metav1.Time
for _, ctr := range pod.Status.InitContainerStatuses {
if ctr.State.Terminated != nil && ctr.State.Terminated.FinishedAt.After(latest.Time) {
latest = ctr.State.Terminated.FinishedAt
}
}
for _, ctr := range pod.Status.ContainerStatuses {
if ctr.State.Terminated != nil && ctr.State.Terminated.FinishedAt.After(latest.Time) {
latest = ctr.State.Terminated.FinishedAt
for _, ctr := range append(pod.Status.InitContainerStatuses, pod.Status.ContainerStatuses...) {
if r := ctr.State.Running; r != nil { // if we are running, then the finished at time must be now or after
latest = metav1.Now()
} else if t := ctr.State.Terminated; t != nil && t.FinishedAt.After(latest.Time) {
latest = t.FinishedAt
}
}
return latest
Expand Down
4 changes: 2 additions & 2 deletions workflow/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ func AddParamToGlobalScope(wf *wfv1.Workflow, log *log.Entry, param wfv1.Paramet
wf.Status.Outputs.Parameters = append(wf.Status.Outputs.Parameters, gParam)
wfUpdated = true
} else {
prevVal := *wf.Status.Outputs.Parameters[index].Value
if prevVal != *param.Value {
prevVal := wf.Status.Outputs.Parameters[index].Value
if prevVal == nil || *prevVal != *param.Value {
log.Infof("overwriting %s: '%s' -> '%s'", paramName, wf.Status.Outputs.Parameters[index].Value, param.Value)
wf.Status.Outputs.Parameters[index].Value = param.Value
wfUpdated = true
Expand Down

0 comments on commit 19da541

Please sign in to comment.