Skip to content

Commit e3a8c5f

Browse files
committed
Find first error step based on "FinishAt" and "StartAt"
Fix issue: tektoncd#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.
1 parent 1346656 commit e3a8c5f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

pkg/entrypoint/entrypointer.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ import (
2929
"go.uber.org/zap"
3030
)
3131

32+
//RFC3339 with millisecond
33+
const (
34+
timeFormat = "2006-01-02T15:04:05.000Z07:00"
35+
)
36+
3237
// Entrypointer holds fields for running commands with redirected
3338
// entrypoints.
3439
type Entrypointer struct {
@@ -98,7 +103,7 @@ func (e Entrypointer) Go() error {
98103
e.WritePostFile(e.PostFile, err)
99104
output = append(output, v1alpha1.PipelineResourceResult{
100105
Key: "StartedAt",
101-
Value: time.Now().Format(time.RFC3339),
106+
Value: time.Now().Format(TimeFormat),
102107
})
103108

104109
return err
@@ -110,7 +115,7 @@ func (e Entrypointer) Go() error {
110115
}
111116
output = append(output, v1alpha1.PipelineResourceResult{
112117
Key: "StartedAt",
113-
Value: time.Now().Format(time.RFC3339),
118+
Value: time.Now().Format(TimeFormat),
114119
})
115120

116121
err := e.Runner.Run(e.Args...)

pkg/pod/status.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ const (
7070

7171
// ReasonFailed indicates that the reason for the failure status is unknown or that one of the steps failed
7272
ReasonFailed = "Failed"
73+
74+
//TimeFormat is RFC3339 with millisecond
75+
timeFormat = "2006-01-02T15:04:05.000Z07:00"
7376
)
7477

7578
const oomKilled = "OOMKilled"
@@ -164,7 +167,7 @@ func updateStatusStartTime(s *corev1.ContainerStatus) error {
164167
}
165168
for index, result := range r {
166169
if result.Key == "StartedAt" {
167-
t, err := time.Parse(time.RFC3339, result.Value)
170+
t, err := time.Parse(TimeFormat, result.Value)
168171
if err != nil {
169172
return fmt.Errorf("could not parse time value %q in StartedAt field: %w", result.Value, err)
170173
}
@@ -264,12 +267,18 @@ func areStepsComplete(pod *corev1.Pod) bool {
264267

265268
func sortContainerStatuses(podInstance *corev1.Pod) {
266269
sort.Slice(podInstance.Status.ContainerStatuses, func(i, j int) bool {
267-
var ifinish, jfinish time.Time
270+
var ifinish, istart, jfinish, jstart time.Time
268271
if term := podInstance.Status.ContainerStatuses[i].State.Terminated; term != nil {
269272
ifinish = term.FinishedAt.Time
273+
istart = term.StartedAt.Time
270274
}
271275
if term := podInstance.Status.ContainerStatuses[j].State.Terminated; term != nil {
272276
jfinish = term.FinishedAt.Time
277+
jstart = term.StartedAt.Time
278+
}
279+
280+
if ifinish.Equal(jfinish) {
281+
return istart.Before(jstart)
273282
}
274283
return ifinish.Before(jfinish)
275284
})

0 commit comments

Comments
 (0)