mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #110914 from yeahdongcn/RuntimeClassName
Print pod.Spec.RuntimeClassName in kubectl describe
This commit is contained in:
commit
bbd2f8fa09
@ -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")
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user