Print ServiceAccount attached to the Pod

This commit is contained in:
Aufar Gilbran 2022-07-16 16:57:38 +08:00
parent 35940b707c
commit b938cdabd0
No known key found for this signature in database
GPG Key ID: ADE4FF10782DF025
2 changed files with 27 additions and 0 deletions

View File

@ -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 len(pod.Spec.ServiceAccountName) > 0 {
w.Write(LEVEL_0, "Service Account:\t%s\n", pod.Spec.ServiceAccountName)
}
if pod.Spec.NodeName == "" {
w.Write(LEVEL_0, "Node:\t<none>\n")
} 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) {
fake := fake.NewSimpleClientset(&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{