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

[kueuectl] Add EXEC TIME column on list workload command. #2977

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
12 changes: 6 additions & 6 deletions cmd/kueuectl/app/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ cq2 cohort2 0 0 false 120m
Creation(testStartTime.Add(-2 * time.Hour).Truncate(time.Second)).
Obj(),
},
wantOut: `NAMESPACE NAME JOB TYPE JOB NAME LOCALQUEUE CLUSTERQUEUE STATUS POSITION IN QUEUE AGE
ns1 wl1 j1 lq1 cq1 PENDING 60m
ns2 wl2 j2 lq2 cq2 PENDING 120m
wantOut: `NAMESPACE NAME JOB TYPE JOB NAME LOCALQUEUE CLUSTERQUEUE STATUS POSITION IN QUEUE EXEC TIME AGE
ns1 wl1 j1 lq1 cq1 PENDING 60m
ns2 wl2 j2 lq2 cq2 PENDING 120m
`,
},
"should print workload list with all namespaces (short command and flag)": {
Expand All @@ -148,9 +148,9 @@ ns2 wl2 j2 lq2 cq2 PENDING
Creation(testStartTime.Add(-2 * time.Hour).Truncate(time.Second)).
Obj(),
},
wantOut: `NAMESPACE NAME JOB TYPE JOB NAME LOCALQUEUE CLUSTERQUEUE STATUS POSITION IN QUEUE AGE
ns1 wl1 j1 lq1 cq1 PENDING 60m
ns2 wl2 j2 lq2 cq2 PENDING 120m
wantOut: `NAMESPACE NAME JOB TYPE JOB NAME LOCALQUEUE CLUSTERQUEUE STATUS POSITION IN QUEUE EXEC TIME AGE
ns1 wl1 j1 lq1 cq1 PENDING 60m
ns2 wl2 j2 lq2 cq2 PENDING 120m
`,
},
}
Expand Down
16 changes: 16 additions & 0 deletions cmd/kueuectl/app/list/list_workload_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"strings"

apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/duration"
Expand Down Expand Up @@ -75,6 +76,7 @@ func (p *listWorkloadPrinter) PrintObj(obj runtime.Object, out io.Writer) error
{Name: "ClusterQueue", Type: "string"},
{Name: "Status", Type: "string"},
{Name: "Position in Queue", Type: "string"},
{Name: "Exec Time", Type: "string"},
{Name: "Age", Type: "string"},
},
Rows: p.printWorkloadList(list),
Expand Down Expand Up @@ -138,6 +140,19 @@ func (p *listWorkloadPrinter) printWorkload(wl *v1beta1.Workload) metav1.TableRo
positionInQueue = fmt.Sprintf("%d", pendingWorkload.PositionInLocalQueue)
}

var execTime string
if admittedCond := apimeta.FindStatusCondition(wl.Status.Conditions, v1beta1.WorkloadAdmitted); admittedCond != nil &&
admittedCond.Status == metav1.ConditionTrue {
finishedTime := p.clock.Now()

if finishedCond := apimeta.FindStatusCondition(wl.Status.Conditions, v1beta1.WorkloadFinished); finishedCond != nil &&
finishedCond.Status == metav1.ConditionTrue {
finishedTime = finishedCond.LastTransitionTime.Time
}

execTime = duration.HumanDuration(finishedTime.Sub(admittedCond.LastTransitionTime.Time))
}

row.Cells = []any{
wl.Name,
strings.Join(p.crdTypes(wl), ", "),
Expand All @@ -146,6 +161,7 @@ func (p *listWorkloadPrinter) printWorkload(wl *v1beta1.Workload) metav1.TableRo
clusterQueueName,
strings.ToUpper(workload.Status(wl)),
positionInQueue,
execTime,
duration.HumanDuration(p.clock.Since(wl.CreationTimestamp.Time)),
}

Expand Down
Loading