Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find first error step based on "FinishAt" and "StartAt" #2455

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, v1alpha1.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, v1alpha1.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 @@ -70,6 +70,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 @@ -164,7 +167,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 @@ -264,12 +267,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