From ae31c0423f08e514a6bccca19d88afbff07f8d65 Mon Sep 17 00:00:00 2001 From: R0CKSTAR Date: Fri, 1 Jul 2022 16:24:37 +0800 Subject: [PATCH 1/4] Print pod.Spec.RuntimeClassName in kubectl describe Signed-off-by: R0CKSTAR --- staging/src/k8s.io/kubectl/pkg/describe/describe.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/staging/src/k8s.io/kubectl/pkg/describe/describe.go b/staging/src/k8s.io/kubectl/pkg/describe/describe.go index e73fb16d846..48491833372 100644 --- a/staging/src/k8s.io/kubectl/pkg/describe/describe.go +++ b/staging/src/k8s.io/kubectl/pkg/describe/describe.go @@ -766,6 +766,9 @@ func describePod(pod *corev1.Pod, events *corev1.EventList) (string, error) { if len(pod.Spec.PriorityClassName) > 0 { w.Write(LEVEL_0, "Priority Class Name:\t%s\n", stringOrNone(pod.Spec.PriorityClassName)) } + if pod.Spec.RuntimeClassName != nil && len(*pod.Spec.RuntimeClassName) > 0 { + w.Write(LEVEL_0, "Runtime Class Name:\t%s\n", stringOrNone(*pod.Spec.RuntimeClassName)) + } if pod.Spec.NodeName == "" { w.Write(LEVEL_0, "Node:\t\n") } else { From fa9f2c409a7bea802048ea06e2266f13ff218e1d Mon Sep 17 00:00:00 2001 From: R0CKSTAR Date: Wed, 6 Jul 2022 11:11:53 +0800 Subject: [PATCH 2/4] Resolve review comments Signed-off-by: R0CKSTAR --- staging/src/k8s.io/kubectl/pkg/describe/describe.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/kubectl/pkg/describe/describe.go b/staging/src/k8s.io/kubectl/pkg/describe/describe.go index 48491833372..96b26045896 100644 --- a/staging/src/k8s.io/kubectl/pkg/describe/describe.go +++ b/staging/src/k8s.io/kubectl/pkg/describe/describe.go @@ -764,10 +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", stringOrNone(*pod.Spec.RuntimeClassName)) + w.Write(LEVEL_0, "Runtime Class Name:\t%s\n", *pod.Spec.RuntimeClassName) } if pod.Spec.NodeName == "" { w.Write(LEVEL_0, "Node:\t\n") From b8ecf6fbfeab3f59f5bf3942f713c699501e8b60 Mon Sep 17 00:00:00 2001 From: R0CKSTAR Date: Tue, 12 Jul 2022 09:34:04 +0800 Subject: [PATCH 3/4] Add unit test - TestDescribePodRuntimeClass Signed-off-by: R0CKSTAR --- .../kubectl/pkg/describe/describe_test.go | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go b/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go index f9988f53a81..095a0b96cf0 100644 --- a/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go +++ b/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go @@ -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", "test2", + }, + }, + { + name: "test3", + pod: &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "bar", + }, + Spec: corev1.PodSpec{}, + }, + expect: []string{ + "Name", "bar", + }, + unexpect: []string{ + "Runtime Class Name", "test3", + }, + }, + } + 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 From d9294dfff752636febcd9401696845c01a80c5f0 Mon Sep 17 00:00:00 2001 From: R0CKSTAR Date: Wed, 13 Jul 2022 08:44:07 +0800 Subject: [PATCH 4/4] Resolve review comments Signed-off-by: R0CKSTAR --- staging/src/k8s.io/kubectl/pkg/describe/describe_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go b/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go index 095a0b96cf0..2bdb731e700 100644 --- a/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go +++ b/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go @@ -416,7 +416,7 @@ func TestDescribePodRuntimeClass(t *testing.T) { "Name", "bar", }, unexpect: []string{ - "Runtime Class Name", "test2", + "Runtime Class Name", }, }, { @@ -431,7 +431,7 @@ func TestDescribePodRuntimeClass(t *testing.T) { "Name", "bar", }, unexpect: []string{ - "Runtime Class Name", "test3", + "Runtime Class Name", }, }, }