diff --git a/pkg/entrypoint/entrypointer.go b/pkg/entrypoint/entrypointer.go index e951a56aceb..188344a8fe7 100644 --- a/pkg/entrypoint/entrypointer.go +++ b/pkg/entrypoint/entrypointer.go @@ -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 { @@ -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 @@ -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...) diff --git a/pkg/pod/status.go b/pkg/pod/status.go index 208e9652df7..8a372129cf7 100644 --- a/pkg/pod/status.go +++ b/pkg/pod/status.go @@ -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" @@ -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) } @@ -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) })