mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-13 13:14:05 +00:00
Improve job describe and get output
For get, condense completions and success into a single column, and print the job duration. Use a new variant of ShortHumanDuration that shows more significant digits, since duration matters more for jobs. ``` NAME COMPLETIONS DURATION AGE image-mirror-origin-v3.10-1529985600 1/1 47s 42m image-mirror-origin-v3.11-1529985600 1/1 74s 42m image-pruner-1529971200 1/1 60m 4h ``` The completions column can be: ``` COMPLETIONS 0/1 # completions nil or 1, succeeded 0 1/1 # completions nil or 1, succeeded 1 0/3 # completions 3, succeeded 1 1/3 # completions 3, succeeded 1 0/1 of 30 # parallelism of 30, completions is nil ``` Update describe to show the completion time and the duration.
This commit is contained in:
@@ -149,8 +149,8 @@ func AddHandlers(h printers.PrintHandler) {
|
||||
|
||||
jobColumnDefinitions := []metav1beta1.TableColumnDefinition{
|
||||
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
|
||||
{Name: "Desired", Type: "integer", Description: batchv1.JobSpec{}.SwaggerDoc()["completions"]},
|
||||
{Name: "Successful", Type: "integer", Description: batchv1.JobStatus{}.SwaggerDoc()["succeeded"]},
|
||||
{Name: "Completions", Type: "string", Description: batchv1.JobStatus{}.SwaggerDoc()["succeeded"]},
|
||||
{Name: "Duration", Type: "string", Description: "Time required to complete the job."},
|
||||
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
|
||||
{Name: "Containers", Type: "string", Priority: 1, Description: "Names of each container in the template."},
|
||||
{Name: "Images", Type: "string", Priority: 1, Description: "Images referenced by each container in the template."},
|
||||
@@ -750,12 +750,28 @@ func printJob(obj *batch.Job, options printers.PrintOptions) ([]metav1beta1.Tabl
|
||||
|
||||
var completions string
|
||||
if obj.Spec.Completions != nil {
|
||||
completions = strconv.Itoa(int(*obj.Spec.Completions))
|
||||
completions = fmt.Sprintf("%d/%d", obj.Status.Succeeded, *obj.Spec.Completions)
|
||||
} else {
|
||||
completions = "<none>"
|
||||
parallelism := int32(0)
|
||||
if obj.Spec.Parallelism != nil {
|
||||
parallelism = *obj.Spec.Parallelism
|
||||
}
|
||||
if parallelism > 1 {
|
||||
completions = fmt.Sprintf("%d/1 of %d", obj.Status.Succeeded, parallelism)
|
||||
} else {
|
||||
completions = fmt.Sprintf("%d/1", obj.Status.Succeeded)
|
||||
}
|
||||
}
|
||||
var jobDuration string
|
||||
switch {
|
||||
case obj.Status.StartTime == nil:
|
||||
case obj.Status.CompletionTime == nil:
|
||||
jobDuration = duration.HumanDuration(time.Now().Sub(obj.Status.StartTime.Time))
|
||||
default:
|
||||
jobDuration = duration.HumanDuration(obj.Status.CompletionTime.Sub(obj.Status.StartTime.Time))
|
||||
}
|
||||
|
||||
row.Cells = append(row.Cells, obj.Name, completions, int64(obj.Status.Succeeded), translateTimestamp(obj.CreationTimestamp))
|
||||
row.Cells = append(row.Cells, obj.Name, completions, jobDuration, translateTimestamp(obj.CreationTimestamp))
|
||||
if options.Wide {
|
||||
names, images := layoutContainerCells(obj.Spec.Template.Spec.Containers)
|
||||
row.Cells = append(row.Cells, names, images, metav1.FormatLabelSelector(obj.Spec.Selector))
|
||||
|
Reference in New Issue
Block a user