Skip to content

Commit 332a5c7

Browse files
vincent-plitekton-robot
authored andcommitted
Find first error step based on "FinishAt" and "StartAt"
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.
1 parent cc2ca6a commit 332a5c7

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, v1beta1.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, v1beta1.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
@@ -74,6 +74,9 @@ const (
7474

7575
// ReasonFailed indicates that the reason for the failure status is unknown or that one of the steps failed
7676
ReasonFailed = "Failed"
77+
78+
//timeFormat is RFC3339 with millisecond
79+
timeFormat = "2006-01-02T15:04:05.000Z07:00"
7780
)
7881

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

269272
func sortContainerStatuses(podInstance *corev1.Pod) {
270273
sort.Slice(podInstance.Status.ContainerStatuses, func(i, j int) bool {
271-
var ifinish, jfinish time.Time
274+
var ifinish, istart, jfinish, jstart time.Time
272275
if term := podInstance.Status.ContainerStatuses[i].State.Terminated; term != nil {
273276
ifinish = term.FinishedAt.Time
277+
istart = term.StartedAt.Time
274278
}
275279
if term := podInstance.Status.ContainerStatuses[j].State.Terminated; term != nil {
276280
jfinish = term.FinishedAt.Time
281+
jstart = term.StartedAt.Time
282+
}
283+
284+
if ifinish.Equal(jfinish) {
285+
return istart.Before(jstart)
277286
}
278287
return ifinish.Before(jfinish)
279288
})

0 commit comments

Comments
 (0)