From 04559e6edae2ac0b79955063b5bbcb2d5a242947 Mon Sep 17 00:00:00 2001 From: Ivan Valdes Date: Fri, 9 Feb 2024 15:44:39 -0800 Subject: [PATCH] printers: add suspend to jobs table Add the suspend column before completions for the Jobs table. --- pkg/printers/internalversion/printers.go | 3 +- pkg/printers/internalversion/printers_test.go | 45 +++++++++++++------ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/pkg/printers/internalversion/printers.go b/pkg/printers/internalversion/printers.go index fd4377e143ba3..04cf754eeb6b3 100644 --- a/pkg/printers/internalversion/printers.go +++ b/pkg/printers/internalversion/printers.go @@ -167,6 +167,7 @@ func AddHandlers(h printers.PrintHandler) { jobColumnDefinitions := []metav1.TableColumnDefinition{ {Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]}, + {Name: "Suspend", Type: "boolean", Description: batchv1.JobSpec{}.SwaggerDoc()["suspend"]}, {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"]}, @@ -1156,7 +1157,7 @@ func printJob(obj *batch.Job, options printers.GenerateOptions) ([]metav1.TableR jobDuration = duration.HumanDuration(obj.Status.CompletionTime.Sub(obj.Status.StartTime.Time)) } - row.Cells = append(row.Cells, obj.Name, completions, jobDuration, translateTimestampSince(obj.CreationTimestamp)) + row.Cells = append(row.Cells, obj.Name, printBoolPtr(obj.Spec.Suspend), completions, jobDuration, translateTimestampSince(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)) diff --git a/pkg/printers/internalversion/printers_test.go b/pkg/printers/internalversion/printers_test.go index 3d1f5e8b4c280..97ba9d7dca696 100644 --- a/pkg/printers/internalversion/printers_test.go +++ b/pkg/printers/internalversion/printers_test.go @@ -2527,8 +2527,8 @@ func TestPrintJob(t *testing.T) { }, }, options: printers.GenerateOptions{}, - // Columns: Name, Completions, Duration, Age - expected: []metav1.TableRow{{Cells: []interface{}{"job1", "1/2", "", "0s"}}}, + // Columns: Name, Suspend, Completions, Duration, Age + expected: []metav1.TableRow{{Cells: []interface{}{"job1", "", "1/2", "", "0s"}}}, }, // Generate table rows for Job with generate options "Wide". { @@ -2560,10 +2560,10 @@ func TestPrintJob(t *testing.T) { }, }, options: printers.GenerateOptions{Wide: true}, - // Columns: Name, Completions, Duration, Age, Containers, Images, Selectors + // Columns: Name, Suspend, Completions, Duration, Age, Containers, Images, Selectors expected: []metav1.TableRow{ { - Cells: []interface{}{"job1", "1/2", "", "0s", "fake-job-container1,fake-job-container2", "fake-job-image1,fake-job-image2", "job-label=job-label-value"}, + Cells: []interface{}{"job1", "", "1/2", "", "0s", "fake-job-container1,fake-job-container2", "fake-job-image1,fake-job-image2", "job-label=job-label-value"}, }, }, }, @@ -2582,8 +2582,8 @@ func TestPrintJob(t *testing.T) { }, }, options: printers.GenerateOptions{}, - // Columns: Name, Completions, Duration, Age - expected: []metav1.TableRow{{Cells: []interface{}{"job2", "0/1", "", "10y"}}}, + // Columns: Name, Suspend, Completions, Duration, Age + expected: []metav1.TableRow{{Cells: []interface{}{"job2", "", "0/1", "", "10y"}}}, }, // Job with duration. { @@ -2602,8 +2602,8 @@ func TestPrintJob(t *testing.T) { }, }, options: printers.GenerateOptions{}, - // Columns: Name, Completions, Duration, Age - expected: []metav1.TableRow{{Cells: []interface{}{"job3", "0/1", "30m", "10y"}}}, + // Columns: Name, Suspend, Completions, Duration, Age + expected: []metav1.TableRow{{Cells: []interface{}{"job3", "", "0/1", "30m", "10y"}}}, }, { job: batch.Job{ @@ -2620,8 +2620,27 @@ func TestPrintJob(t *testing.T) { }, }, options: printers.GenerateOptions{}, - // Columns: Name, Completions, Duration, Age - expected: []metav1.TableRow{{Cells: []interface{}{"job4", "0/1", "20m", "10y"}}}, + // Columns: Name, Suspend, Completions, Duration, Age + expected: []metav1.TableRow{{Cells: []interface{}{"job4", "", "0/1", "20m", "10y"}}}, + }, + // Job with suspend set to true. + { + job: batch.Job{ + ObjectMeta: metav1.ObjectMeta{ + Name: "job5", + CreationTimestamp: metav1.Time{Time: time.Now().Add(1.9e9)}, + }, + Spec: batch.JobSpec{ + Suspend: utilpointer.Bool(true), + Completions: nil, + }, + Status: batch.JobStatus{ + Succeeded: 0, + }, + }, + options: printers.GenerateOptions{}, + // Columns: Name, Suspend, Completions, Duration, Age + expected: []metav1.TableRow{{Cells: []interface{}{"job5", "True", "0/1", "", "0s"}}}, }, } @@ -2701,10 +2720,10 @@ func TestPrintJobList(t *testing.T) { }, } - // Columns: Name, Completions, Duration, Age + // Columns: Name, Suspend, Completions, Duration, Age expectedRows := []metav1.TableRow{ - {Cells: []interface{}{"job1", "1/2", "", "0s"}}, - {Cells: []interface{}{"job2", "2/2", "20m", "0s"}}, + {Cells: []interface{}{"job1", "", "1/2", "", "0s"}}, + {Cells: []interface{}{"job2", "", "2/2", "20m", "0s"}}, } rows, err := printJobList(&jobList, printers.GenerateOptions{})