Skip to content

Commit

Permalink
add serviceaccount to service describe (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ying Chun Guo authored and knative-prow-robot committed Nov 5, 2019
1 parent 44dafbd commit c5b3f7a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/kn/commands/service/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ func writeService(dw printers.PrefixWriter, service *v1alpha1.Service) {
url := service.Status.Address.GetURL()
dw.WriteAttribute("Address", url.String())
}
if (service.Spec.Template != nil) && (service.Spec.Template.Spec.ServiceAccountName != "") {
dw.WriteAttribute("ServiceAccount", service.Spec.Template.Spec.ServiceAccountName)
}
}

// Write out revisions associated with this service. By default only active
Expand Down
23 changes: 22 additions & 1 deletion pkg/kn/commands/service/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestServiceDescribeBasic(t *testing.T) {
// Recording:
r := client.Recorder()
// Prepare service
expectedService := createTestService("foo", []string{"rev1"}, goodConditions())
expectedService := createTestServiceWithServiceAccount("foo", []string{"rev1"}, "default-sa", goodConditions())

// Get service & revision
r.GetService("foo", &expectedService, nil)
Expand All @@ -69,6 +69,7 @@ func TestServiceDescribeBasic(t *testing.T) {
assert.Assert(t, cmp.Regexp(`(?m)\s*Annotations:.*\.\.\.$`, output))
assert.Assert(t, util.ContainsAll(output, "Labels:", "label1=lval1, label2=lval2\n"))
assert.Assert(t, util.ContainsAll(output, "[1]"))
assert.Assert(t, cmp.Regexp("ServiceAccount: \\s+default-sa", output))

assert.Equal(t, strings.Count(output, "rev1"), 1)

Expand Down Expand Up @@ -546,6 +547,26 @@ func createTestService(name string, revisionNames []string, conditions duckv1.Co
}
service.Status.Traffic = trafficTargets
}

return service
}

func createTestServiceWithServiceAccount(name string, revisionNames []string, serviceAccountName string, conditions duckv1.Conditions) v1alpha1.Service {
service := createTestService(name, revisionNames, conditions)

if serviceAccountName != "" {
template := v1alpha1.RevisionTemplateSpec{
Spec: v1alpha1.RevisionSpec{
RevisionSpec: servingv1.RevisionSpec{
PodSpec: v1.PodSpec{
ServiceAccountName: serviceAccountName,
},
},
},
}
service.Spec.Template = &template
}

return service
}

Expand Down

0 comments on commit c5b3f7a

Please sign in to comment.