diff --git a/pkg/printers/internalversion/printers.go b/pkg/printers/internalversion/printers.go index f2fe011c3d7..b9cb7cef868 100644 --- a/pkg/printers/internalversion/printers.go +++ b/pkg/printers/internalversion/printers.go @@ -180,6 +180,7 @@ func AddHandlers(h printers.PrintHandler) { cronJobColumnDefinitions := []metav1.TableColumnDefinition{ {Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]}, {Name: "Schedule", Type: "string", Description: batchv1beta1.CronJobSpec{}.SwaggerDoc()["schedule"]}, + {Name: "Timezone", Type: "string", Description: batchv1beta1.CronJobSpec{}.SwaggerDoc()["timeZone"]}, {Name: "Suspend", Type: "boolean", Description: batchv1beta1.CronJobSpec{}.SwaggerDoc()["suspend"]}, {Name: "Active", Type: "integer", Description: batchv1beta1.CronJobStatus{}.SwaggerDoc()["active"]}, {Name: "Last Schedule", Type: "string", Description: batchv1beta1.CronJobStatus{}.SwaggerDoc()["lastScheduleTime"]}, @@ -1185,7 +1186,12 @@ func printCronJob(obj *batch.CronJob, options printers.GenerateOptions) ([]metav lastScheduleTime = translateTimestampSince(*obj.Status.LastScheduleTime) } - row.Cells = append(row.Cells, obj.Name, obj.Spec.Schedule, printBoolPtr(obj.Spec.Suspend), int64(len(obj.Status.Active)), lastScheduleTime, translateTimestampSince(obj.CreationTimestamp)) + timeZone := "" + if obj.Spec.TimeZone != nil { + timeZone = *obj.Spec.TimeZone + } + + row.Cells = append(row.Cells, obj.Name, obj.Spec.Schedule, timeZone, printBoolPtr(obj.Spec.Suspend), int64(len(obj.Status.Active)), lastScheduleTime, translateTimestampSince(obj.CreationTimestamp)) if options.Wide { names, images := layoutContainerCells(obj.Spec.JobTemplate.Spec.Template.Spec.Containers) row.Cells = append(row.Cells, names, images, metav1.FormatLabelSelector(obj.Spec.JobTemplate.Spec.Selector)) diff --git a/pkg/printers/internalversion/printers_test.go b/pkg/printers/internalversion/printers_test.go index ead3e5386ed..e7e0ea5ea9e 100644 --- a/pkg/printers/internalversion/printers_test.go +++ b/pkg/printers/internalversion/printers_test.go @@ -5089,6 +5089,7 @@ func TestPrintComponentStatus(t *testing.T) { } func TestPrintCronJob(t *testing.T) { + timeZone := "LOCAL" completions := int32(2) suspend := false tests := []struct { @@ -5133,7 +5134,47 @@ func TestPrintCronJob(t *testing.T) { }, options: printers.GenerateOptions{}, // Columns: Name, Schedule, Suspend, Active, Last Schedule, Age - expected: []metav1.TableRow{{Cells: []interface{}{"cronjob1", "0/5 * * * ?", "False", int64(0), "0s", "0s"}}}, + expected: []metav1.TableRow{{Cells: []interface{}{"cronjob1", "0/5 * * * ?", "", "False", int64(0), "0s", "0s"}}}, + }, + // Basic cron job; does not print containers, images, or labels. + { + cronjob: batch.CronJob{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cronjob1", + CreationTimestamp: metav1.Time{Time: time.Now().Add(1.9e9)}, + }, + Spec: batch.CronJobSpec{ + Schedule: "0/5 * * * ?", + TimeZone: &timeZone, + Suspend: &suspend, + JobTemplate: batch.JobTemplateSpec{ + Spec: batch.JobSpec{ + Completions: &completions, + Template: api.PodTemplateSpec{ + Spec: api.PodSpec{ + Containers: []api.Container{ + { + Name: "fake-job-container1", + Image: "fake-job-image1", + }, + { + Name: "fake-job-container2", + Image: "fake-job-image2", + }, + }, + }, + }, + Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"a": "b"}}, + }, + }, + }, + Status: batch.CronJobStatus{ + LastScheduleTime: &metav1.Time{Time: time.Now().Add(1.9e9)}, + }, + }, + options: printers.GenerateOptions{}, + // Columns: Name, Schedule, Suspend, Active, Last Schedule, Age + expected: []metav1.TableRow{{Cells: []interface{}{"cronjob1", "0/5 * * * ?", "LOCAL", "False", int64(0), "0s", "0s"}}}, }, // Generate options: Wide; prints containers, images, and labels. { @@ -5172,7 +5213,7 @@ func TestPrintCronJob(t *testing.T) { }, options: printers.GenerateOptions{Wide: true}, // Columns: Name, Schedule, Suspend, Active, Last Schedule, Age - expected: []metav1.TableRow{{Cells: []interface{}{"cronjob1", "0/5 * * * ?", "False", int64(0), "0s", "0s", "fake-job-container1,fake-job-container2", "fake-job-image1,fake-job-image2", "a=b"}}}, + expected: []metav1.TableRow{{Cells: []interface{}{"cronjob1", "0/5 * * * ?", "", "False", int64(0), "0s", "0s", "fake-job-container1,fake-job-container2", "fake-job-image1,fake-job-image2", "a=b"}}}, }, // CronJob with Last Schedule and Age { @@ -5191,7 +5232,7 @@ func TestPrintCronJob(t *testing.T) { }, options: printers.GenerateOptions{}, // Columns: Name, Schedule, Suspend, Active, Last Schedule, Age - expected: []metav1.TableRow{{Cells: []interface{}{"cronjob2", "0/5 * * * ?", "False", int64(0), "30s", "5m"}}}, + expected: []metav1.TableRow{{Cells: []interface{}{"cronjob2", "0/5 * * * ?", "", "False", int64(0), "30s", "5m"}}}, }, // CronJob without Last Schedule { @@ -5208,7 +5249,7 @@ func TestPrintCronJob(t *testing.T) { }, options: printers.GenerateOptions{}, // Columns: Name, Schedule, Suspend, Active, Last Schedule, Age - expected: []metav1.TableRow{{Cells: []interface{}{"cronjob3", "0/5 * * * ?", "False", int64(0), "", "5m"}}}, + expected: []metav1.TableRow{{Cells: []interface{}{"cronjob3", "0/5 * * * ?", "", "False", int64(0), "", "5m"}}}, }, } @@ -5227,6 +5268,7 @@ func TestPrintCronJob(t *testing.T) { } func TestPrintCronJobList(t *testing.T) { + timeZone := "LOCAL" completions := int32(2) suspend := false @@ -5239,6 +5281,7 @@ func TestPrintCronJobList(t *testing.T) { }, Spec: batch.CronJobSpec{ Schedule: "0/5 * * * ?", + TimeZone: &timeZone, Suspend: &suspend, JobTemplate: batch.JobTemplateSpec{ Spec: batch.JobSpec{ @@ -5275,8 +5318,8 @@ func TestPrintCronJobList(t *testing.T) { // Columns: Name, Schedule, Suspend, Active, Last Schedule, Age expectedRows := []metav1.TableRow{ - {Cells: []interface{}{"cronjob1", "0/5 * * * ?", "False", int64(0), "0s", "0s"}}, - {Cells: []interface{}{"cronjob2", "4/5 1 1 1 ?", "False", int64(0), "20m", "0s"}}, + {Cells: []interface{}{"cronjob1", "0/5 * * * ?", "LOCAL", "False", int64(0), "0s", "0s"}}, + {Cells: []interface{}{"cronjob2", "4/5 1 1 1 ?", "", "False", int64(0), "20m", "0s"}}, } rows, err := printCronJobList(&cronJobList, printers.GenerateOptions{})