Skip to content

Commit 66dca45

Browse files
authored
Merge pull request kubernetes#126529 from googs1025/cli_priorityclass
kubectl: added preemptionPolicy field when using kubectl get PriorityClass
2 parents ae7e626 + d28ee82 commit 66dca45

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

pkg/printers/internalversion/printers.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ func AddHandlers(h printers.PrintHandler) {
494494
{Name: "Value", Type: "integer", Description: schedulingv1.PriorityClass{}.SwaggerDoc()["value"]},
495495
{Name: "Global-Default", Type: "boolean", Description: schedulingv1.PriorityClass{}.SwaggerDoc()["globalDefault"]},
496496
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
497+
{Name: "PreemptionPolicy", Type: "string", Description: schedulingv1.PriorityClass{}.SwaggerDoc()["preemptionPolicy"]},
497498
}
498499
_ = h.TableHandler(priorityClassColumnDefinitions, printPriorityClass)
499500
_ = h.TableHandler(priorityClassColumnDefinitions, printPriorityClassList)
@@ -2747,7 +2748,13 @@ func printPriorityClass(obj *scheduling.PriorityClass, options printers.Generate
27472748
value := obj.Value
27482749
globalDefault := obj.GlobalDefault
27492750
row.Cells = append(row.Cells, name, int64(value), globalDefault, translateTimestampSince(obj.CreationTimestamp))
2750-
2751+
if options.Wide {
2752+
var preemptionPolicy string
2753+
if obj.PreemptionPolicy != nil {
2754+
preemptionPolicy = string(*obj.PreemptionPolicy)
2755+
}
2756+
row.Cells = append(row.Cells, preemptionPolicy)
2757+
}
27512758
return []metav1.TableRow{row}, nil
27522759
}
27532760

pkg/printers/internalversion/printers_test.go

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5757,43 +5757,79 @@ func TestPrintLease(t *testing.T) {
57575757
}
57585758

57595759
func TestPrintPriorityClass(t *testing.T) {
5760+
preemptNever := api.PreemptNever
5761+
preemptLowerPriority := api.PreemptLowerPriority
57605762
tests := []struct {
5763+
name string
5764+
options printers.GenerateOptions
57615765
pc scheduling.PriorityClass
57625766
expected []metav1.TableRow
57635767
}{
57645768
{
5769+
name: "Test case with PreemptNever policy",
57655770
pc: scheduling.PriorityClass{
57665771
ObjectMeta: metav1.ObjectMeta{
57675772
Name: "pc1",
57685773
CreationTimestamp: metav1.Time{Time: time.Now().Add(1.9e9)},
57695774
},
5770-
Value: 1,
5775+
Value: 1,
5776+
PreemptionPolicy: &preemptNever,
57715777
},
57725778
expected: []metav1.TableRow{{Cells: []interface{}{"pc1", int64(1), bool(false), "0s"}}},
57735779
},
57745780
{
5781+
name: "Test case with PreemptLowerPriority policy",
57755782
pc: scheduling.PriorityClass{
57765783
ObjectMeta: metav1.ObjectMeta{
57775784
Name: "pc2",
57785785
CreationTimestamp: metav1.Time{Time: time.Now().Add(-3e11)},
57795786
},
5780-
Value: 1000000000,
5781-
GlobalDefault: true,
5787+
Value: 1000000000,
5788+
GlobalDefault: true,
5789+
PreemptionPolicy: &preemptLowerPriority,
57825790
},
57835791
expected: []metav1.TableRow{{Cells: []interface{}{"pc2", int64(1000000000), bool(true), "5m"}}},
57845792
},
5793+
{
5794+
name: "Test case with PreemptLowerPriority policy and wide output",
5795+
options: printers.GenerateOptions{Wide: true},
5796+
pc: scheduling.PriorityClass{
5797+
ObjectMeta: metav1.ObjectMeta{
5798+
Name: "pc2",
5799+
CreationTimestamp: metav1.Time{Time: time.Now().Add(-3e11)},
5800+
},
5801+
Value: 1000000000,
5802+
GlobalDefault: true,
5803+
PreemptionPolicy: &preemptLowerPriority,
5804+
},
5805+
expected: []metav1.TableRow{{Cells: []interface{}{"pc2", int64(1000000000), bool(true), "5m", string(api.PreemptLowerPriority)}}},
5806+
},
5807+
{
5808+
name: "Test case without set PreemptLowerPriority policy",
5809+
options: printers.GenerateOptions{Wide: true},
5810+
pc: scheduling.PriorityClass{
5811+
ObjectMeta: metav1.ObjectMeta{
5812+
Name: "pc2",
5813+
CreationTimestamp: metav1.Time{Time: time.Now().Add(-3e11)},
5814+
},
5815+
Value: 1000000000,
5816+
GlobalDefault: true,
5817+
PreemptionPolicy: nil,
5818+
},
5819+
expected: []metav1.TableRow{{Cells: []interface{}{"pc2", int64(1000000000), bool(true), "5m", string("")}}},
5820+
},
57855821
}
57865822

57875823
for i, test := range tests {
5788-
rows, err := printPriorityClass(&test.pc, printers.GenerateOptions{})
5824+
rows, err := printPriorityClass(&test.pc, test.options)
57895825
if err != nil {
57905826
t.Fatal(err)
57915827
}
57925828
for i := range rows {
57935829
rows[i].Object.Object = nil
57945830
}
57955831
if !reflect.DeepEqual(test.expected, rows) {
5796-
t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows))
5832+
t.Errorf("test case %s: %d mismatch: %s", test.name, i, cmp.Diff(test.expected, rows))
57975833
}
57985834
}
57995835
}

0 commit comments

Comments
 (0)