Merge pull request #52245 from zjj2wry/describe-sa

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

fix issue(#52244)kubectl describe serviceaccount have redundance null…

… line, we should keep accordance for kubectl describe command



**What this PR does / why we need it**:
close issue #52244

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
pull/6/head
Kubernetes Submit Queue 2017-10-24 20:37:24 -07:00 committed by GitHub
commit 88ac8c0227
2 changed files with 37 additions and 2 deletions

View File

@ -2246,7 +2246,6 @@ func describeServiceAccount(serviceAccount *api.ServiceAccount, tokens []api.Sec
w.Write(LEVEL_0, "Namespace:\t%s\n", serviceAccount.Namespace)
printLabelsMultiline(w, "Labels", serviceAccount.Labels)
printAnnotationsMultiline(w, "Annotations", serviceAccount.Annotations)
w.WriteLine()
var (
emptyHeader = " "
@ -2288,7 +2287,6 @@ func describeServiceAccount(serviceAccount *api.ServiceAccount, tokens []api.Sec
prefix = emptyHeader
}
}
w.WriteLine()
}
if events != nil {

View File

@ -1659,6 +1659,43 @@ func TestDescribeResourceQuota(t *testing.T) {
}
}
func TestDescribeServiceAccount(t *testing.T) {
fake := fake.NewSimpleClientset(&api.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "foo",
},
Secrets: []api.ObjectReference{
{
Name: "test-objectref",
},
},
ImagePullSecrets: []api.LocalObjectReference{
{
Name: "test-local-ref",
},
},
})
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
d := ServiceAccountDescriber{c}
out, err := d.Describe("foo", "bar", printers.DescriberSettings{ShowEvents: true})
if err != nil {
t.Errorf("unexpected error: %v", err)
}
expectedOut := `Name: bar
Namespace: foo
Labels: <none>
Annotations: <none>
Image pull secrets: test-local-ref (not found)
Mountable secrets: test-objectref (not found)
Tokens: <none>
Events: <none>` + "\n"
if out != expectedOut {
t.Errorf("expected : %q\n but got output:\n %q", expectedOut, out)
}
}
// boolPtr returns a pointer to a bool
func boolPtr(b bool) *bool {
o := b