Merge pull request #108701 from denkensk/add-preemptionPolicy

support preemptionPolicy in describe PriorityClass

Kubernetes-commit: 2786b78b5a242452e6c7eda5a310609f77a482b9
This commit is contained in:
Kubernetes Publisher 2022-03-23 22:31:24 -07:00
commit d7a0de9a66
2 changed files with 70 additions and 0 deletions

View File

@ -4758,6 +4758,7 @@ func describePriorityClass(pc *schedulingv1.PriorityClass, events *corev1.EventL
w.Write(LEVEL_0, "Name:\t%s\n", pc.Name)
w.Write(LEVEL_0, "Value:\t%v\n", pc.Value)
w.Write(LEVEL_0, "GlobalDefault:\t%v\n", pc.GlobalDefault)
w.Write(LEVEL_0, "PreemptionPolicy:\t%s\n", *pc.PreemptionPolicy)
w.Write(LEVEL_0, "Description:\t%s\n", pc.Description)
w.Write(LEVEL_0, "Annotations:\t%s\n", labels.FormatLabels(pc.Annotations))

View File

@ -37,6 +37,7 @@ import (
networkingv1beta1 "k8s.io/api/networking/v1beta1"
policyv1 "k8s.io/api/policy/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1"
schedulingv1 "k8s.io/api/scheduling/v1"
storagev1 "k8s.io/api/storage/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/resource"
@ -343,6 +344,74 @@ func TestDescribePodPriority(t *testing.T) {
}
}
func TestDescribePriorityClass(t *testing.T) {
preemptLowerPriority := corev1.PreemptLowerPriority
preemptNever := corev1.PreemptNever
testCases := []struct {
name string
priorityClass *schedulingv1.PriorityClass
expect []string
}{
{
name: "test1",
priorityClass: &schedulingv1.PriorityClass{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
},
Value: 10,
GlobalDefault: false,
PreemptionPolicy: &preemptLowerPriority,
Description: "test1",
},
expect: []string{
"Name", "bar",
"Value", "10",
"GlobalDefault", "false",
"PreemptionPolicy", "PreemptLowerPriority",
"Description", "test1",
"Annotations", "",
},
},
{
name: "test2",
priorityClass: &schedulingv1.PriorityClass{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
},
Value: 100,
GlobalDefault: true,
PreemptionPolicy: &preemptNever,
Description: "test2",
},
expect: []string{
"Name", "bar",
"Value", "100",
"GlobalDefault", "true",
"PreemptionPolicy", "Never",
"Description", "test2",
"Annotations", "",
},
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
fake := fake.NewSimpleClientset(testCase.priorityClass)
c := &describeClient{T: t, Interface: fake}
d := PriorityClassDescriber{c}
out, err := d.Describe("", "bar", DescriberSettings{ShowEvents: true})
if err != nil {
t.Errorf("unexpected error: %v", err)
}
for _, expected := range testCase.expect {
if !strings.Contains(out, expected) {
t.Errorf("expected to find %q in output: %q", expected, out)
}
}
})
}
}
func TestDescribeConfigMap(t *testing.T) {
fake := fake.NewSimpleClientset(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{