Skip to content

Commit

Permalink
Find first error step based on "FinishAt" and "StartAt"
Browse files Browse the repository at this point in the history
Fix issue: #2415

Introduce `StartAt` for the sorting when `FinishedAt` are exactly the same.
Since the goal is to find the first failed step, the StartAt and FinishedAt are most simple and directly solution.
Moreover, adopt a higher resolution format for `StartAt` to make it more accurately.
  • Loading branch information
vincent-pli authored and tekton-robot committed May 21, 2020
1 parent cc2ca6a commit 332a5c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pkg/entrypoint/entrypointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import (
"go.uber.org/zap"
)

//RFC3339 with millisecond
const (
timeFormat = "2006-01-02T15:04:05.000Z07:00"
)

// Entrypointer holds fields for running commands with redirected
// entrypoints.
type Entrypointer struct {
Expand Down Expand Up @@ -98,7 +103,7 @@ func (e Entrypointer) Go() error {
e.WritePostFile(e.PostFile, err)
output = append(output, v1beta1.PipelineResourceResult{
Key: "StartedAt",
Value: time.Now().Format(time.RFC3339),
Value: time.Now().Format(timeFormat),
})

return err
Expand All @@ -110,7 +115,7 @@ func (e Entrypointer) Go() error {
}
output = append(output, v1beta1.PipelineResourceResult{
Key: "StartedAt",
Value: time.Now().Format(time.RFC3339),
Value: time.Now().Format(timeFormat),
})

err := e.Runner.Run(e.Args...)
Expand Down
13 changes: 11 additions & 2 deletions pkg/pod/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ const (

// ReasonFailed indicates that the reason for the failure status is unknown or that one of the steps failed
ReasonFailed = "Failed"

//timeFormat is RFC3339 with millisecond
timeFormat = "2006-01-02T15:04:05.000Z07:00"
)

const oomKilled = "OOMKilled"
Expand Down Expand Up @@ -168,7 +171,7 @@ func updateStatusStartTime(s *corev1.ContainerStatus) error {
}
for index, result := range r {
if result.Key == "StartedAt" {
t, err := time.Parse(time.RFC3339, result.Value)
t, err := time.Parse(timeFormat, result.Value)
if err != nil {
return fmt.Errorf("could not parse time value %q in StartedAt field: %w", result.Value, err)
}
Expand Down Expand Up @@ -268,12 +271,18 @@ func areStepsComplete(pod *corev1.Pod) bool {

func sortContainerStatuses(podInstance *corev1.Pod) {
sort.Slice(podInstance.Status.ContainerStatuses, func(i, j int) bool {
var ifinish, jfinish time.Time
var ifinish, istart, jfinish, jstart time.Time
if term := podInstance.Status.ContainerStatuses[i].State.Terminated; term != nil {
ifinish = term.FinishedAt.Time
istart = term.StartedAt.Time
}
if term := podInstance.Status.ContainerStatuses[j].State.Terminated; term != nil {
jfinish = term.FinishedAt.Time
jstart = term.StartedAt.Time
}

if ifinish.Equal(jfinish) {
return istart.Before(jstart)
}
return ifinish.Before(jfinish)
})
Expand Down

0 comments on commit 332a5c7

Please sign in to comment.