Merge pull request #108701 from denkensk/add-preemptionPolicy
support preemptionPolicy in describe PriorityClass
This commit is contained in:
		@@ -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))
 | 
			
		||||
 
 | 
			
		||||
@@ -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{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user