Merge pull request #110914 from yeahdongcn/RuntimeClassName

Print pod.Spec.RuntimeClassName in kubectl describe
This commit is contained in:
Kubernetes Prow Robot 2022-07-20 14:13:43 -07:00 committed by GitHub
commit bbd2f8fa09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 84 additions and 1 deletions

View File

@ -764,7 +764,10 @@ func describePod(pod *corev1.Pod, events *corev1.EventList) (string, error) {
w.Write(LEVEL_0, "Priority:\t%d\n", *pod.Spec.Priority)
}
if len(pod.Spec.PriorityClassName) > 0 {
w.Write(LEVEL_0, "Priority Class Name:\t%s\n", stringOrNone(pod.Spec.PriorityClassName))
w.Write(LEVEL_0, "Priority Class Name:\t%s\n", pod.Spec.PriorityClassName)
}
if pod.Spec.RuntimeClassName != nil && len(*pod.Spec.RuntimeClassName) > 0 {
w.Write(LEVEL_0, "Runtime Class Name:\t%s\n", *pod.Spec.RuntimeClassName)
}
if pod.Spec.NodeName == "" {
w.Write(LEVEL_0, "Node:\t<none>\n")

View File

@ -378,6 +378,86 @@ func TestDescribePodPriority(t *testing.T) {
}
}
func TestDescribePodRuntimeClass(t *testing.T) {
runtimeClassNames := []string{"test1", ""}
testCases := []struct {
name string
pod *corev1.Pod
expect []string
unexpect []string
}{
{
name: "test1",
pod: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
},
Spec: corev1.PodSpec{
RuntimeClassName: &runtimeClassNames[0],
},
},
expect: []string{
"Name", "bar",
"Runtime Class Name", "test1",
},
unexpect: []string{},
},
{
name: "test2",
pod: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
},
Spec: corev1.PodSpec{
RuntimeClassName: &runtimeClassNames[1],
},
},
expect: []string{
"Name", "bar",
},
unexpect: []string{
"Runtime Class Name",
},
},
{
name: "test3",
pod: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
},
Spec: corev1.PodSpec{},
},
expect: []string{
"Name", "bar",
},
unexpect: []string{
"Runtime Class Name",
},
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
fake := fake.NewSimpleClientset(testCase.pod)
c := &describeClient{T: t, Interface: fake}
d := PodDescriber{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)
}
}
for _, unexpected := range testCase.unexpect {
if strings.Contains(out, unexpected) {
t.Errorf("unexpected to find %q in output: %q", unexpected, out)
}
}
})
}
}
func TestDescribePriorityClass(t *testing.T) {
preemptLowerPriority := corev1.PreemptLowerPriority
preemptNever := corev1.PreemptNever