Merge pull request #111192 from aufarg/add-serviceaccount-to-describe

Print ServiceAccount attached to the Pod
This commit is contained in:
Kubernetes Prow Robot 2022-07-22 09:43:38 -07:00 committed by GitHub
commit 9a8b4ab240
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -769,6 +769,9 @@ func describePod(pod *corev1.Pod, events *corev1.EventList) (string, error) {
if pod.Spec.RuntimeClassName != nil && len(*pod.Spec.RuntimeClassName) > 0 { if pod.Spec.RuntimeClassName != nil && len(*pod.Spec.RuntimeClassName) > 0 {
w.Write(LEVEL_0, "Runtime Class Name:\t%s\n", *pod.Spec.RuntimeClassName) w.Write(LEVEL_0, "Runtime Class Name:\t%s\n", *pod.Spec.RuntimeClassName)
} }
if len(pod.Spec.ServiceAccountName) > 0 {
w.Write(LEVEL_0, "Service Account:\t%s\n", pod.Spec.ServiceAccountName)
}
if pod.Spec.NodeName == "" { if pod.Spec.NodeName == "" {
w.Write(LEVEL_0, "Node:\t<none>\n") w.Write(LEVEL_0, "Node:\t<none>\n")
} else { } else {

View File

@ -102,6 +102,30 @@ func TestDescribePod(t *testing.T) {
} }
} }
func TestDescribePodServiceAccount(t *testing.T) {
fake := fake.NewSimpleClientset(&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "foo",
},
Spec: corev1.PodSpec{
ServiceAccountName: "fooaccount",
},
})
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
d := PodDescriber{c}
out, err := d.Describe("foo", "bar", DescriberSettings{ShowEvents: true})
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if !strings.Contains(out, "Service Account:") {
t.Errorf("unexpected out: %s", out)
}
if !strings.Contains(out, "fooaccount") {
t.Errorf("unexpected out: %s", out)
}
}
func TestDescribePodEphemeralContainers(t *testing.T) { func TestDescribePodEphemeralContainers(t *testing.T) {
fake := fake.NewSimpleClientset(&corev1.Pod{ fake := fake.NewSimpleClientset(&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{