Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add service account info into service describe #472

Merged
merged 1 commit into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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