Skip to content

Commit

Permalink
fix: job duration stops changing
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Lesikov <[email protected]>
  • Loading branch information
ilya-lesikov committed Jul 18, 2022
1 parent b46a5b2 commit 4aa62c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
11 changes: 0 additions & 11 deletions pkg/tracker/job/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package job

import (
"fmt"
"time"

batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/duration"

"github.com/werf/kubedog/pkg/tracker/indicators"
"github.com/werf/kubedog/pkg/tracker/pod"
Expand All @@ -19,7 +17,6 @@ type JobStatus struct {
StatusGeneration uint64

SucceededIndicator *indicators.Int32EqualConditionIndicator
Duration string
Age string

WaitingForMessages []string
Expand All @@ -46,14 +43,6 @@ func NewJobStatus(object *batchv1.Job, statusGeneration uint64, isTrackerFailed
}
}

switch {
case res.StartTime == nil:
case res.CompletionTime == nil:
res.Duration = duration.HumanDuration(time.Since(res.StartTime.Time))
default:
res.Duration = duration.HumanDuration(res.CompletionTime.Sub(res.StartTime.Time))
}

doCheckJobConditions := true
for _, trackedPodName := range trackedPodsNames {
podStatus := podsStatuses[trackedPodName]
Expand Down
16 changes: 14 additions & 2 deletions pkg/trackers/rollout/multitrack/multitrack_display.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"regexp"
"sort"
"strings"
"time"

dur "k8s.io/apimachinery/pkg/util/duration"

"github.com/werf/kubedog/pkg/tracker/indicators"
"github.com/werf/kubedog/pkg/tracker/pod"
Expand Down Expand Up @@ -315,10 +318,19 @@ func (mt *multitracker) displayJobsProgress() {
})
}

var duration string
switch {
case status.JobStatus.StartTime == nil:
case status.JobStatus.CompletionTime == nil:
duration = dur.HumanDuration(time.Since(status.JobStatus.StartTime.Time))
default:
duration = dur.HumanDuration(status.JobStatus.CompletionTime.Sub(status.JobStatus.StartTime.Time))
}

if status.IsFailed {
t.Row(resource, status.Active, status.Duration, strings.Join([]string{succeeded, fmt.Sprintf("%d", status.Failed)}, "/"), formatResourceError(disableWarningColors, status.FailedReason))
t.Row(resource, status.Active, duration, strings.Join([]string{succeeded, fmt.Sprintf("%d", status.Failed)}, "/"), formatResourceError(disableWarningColors, status.FailedReason))
} else {
t.Row(resource, status.Active, status.Duration, strings.Join([]string{succeeded, fmt.Sprintf("%d", status.Failed)}, "/"))
t.Row(resource, status.Active, duration, strings.Join([]string{succeeded, fmt.Sprintf("%d", status.Failed)}, "/"))
}

if len(status.Pods) > 0 {
Expand Down

0 comments on commit 4aa62c3

Please sign in to comment.