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

Show all revisions when run service describe -v #790

Merged
merged 1 commit into from
Apr 14, 2020
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
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
|===
| | Description | PR

| 🐛
| Service describe command shows repetitive revisions
| https://github.com/knative/client/pull/790[#790]

| 🎁
| Add concurrency-utilization option for `service create` and `service update` (`--concurrency-utilization`)
| https://github.com/knative/client/pull/788[#788]
Expand Down
10 changes: 5 additions & 5 deletions pkg/kn/commands/service/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func getRevisionDescriptions(client clientservingv1.KnServingClient, service *se
return nil, fmt.Errorf("cannot extract revision from service %s: %v", service.Name, err)
}
revisionsSeen.Insert(revision.Name)
desc, err := newRevisionDesc(revision, &target, service)
desc, err := newRevisionDesc(*revision, &target, service)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func completeWithLatestRevisions(client clientservingv1.KnServingClient, service
if err != nil {
return nil, err
}
newDesc, err := newRevisionDesc(rev, nil, service)
newDesc, err := newRevisionDesc(*rev, nil, service)
if err != nil {
return nil, err
}
Expand All @@ -321,7 +321,7 @@ func completeWithUntargetedRevisions(client clientservingv1.KnServingClient, ser
continue
}
revisionsSeen.Insert(revision.Name)
newDesc, err := newRevisionDesc(&revision, nil, service)
newDesc, err := newRevisionDesc(revision, nil, service)
if err != nil {
return nil, err
}
Expand All @@ -331,13 +331,13 @@ func completeWithUntargetedRevisions(client clientservingv1.KnServingClient, ser
return descs, nil
}

func newRevisionDesc(revision *servingv1.Revision, target *servingv1.TrafficTarget, service *servingv1.Service) (*revisionDesc, error) {
func newRevisionDesc(revision servingv1.Revision, target *servingv1.TrafficTarget, service *servingv1.Service) (*revisionDesc, error) {
generation, err := strconv.ParseInt(revision.Labels[serving.ConfigurationGenerationLabelKey], 0, 0)
if err != nil {
return nil, fmt.Errorf("cannot extract configuration generation for revision %s: %v", revision.Name, err)
}
revisionDesc := revisionDesc{
revision: revision,
revision: &revision,
configurationGeneration: int(generation),
latestCreated: revision.Name == service.Status.LatestCreatedRevisionName,
latestReady: revision.Name == service.Status.LatestReadyRevisionName,
Expand Down
17 changes: 12 additions & 5 deletions pkg/kn/commands/service/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,28 +432,31 @@ func TestServiceDescribeVerbose(t *testing.T) {
r := client.Recorder()

// Prepare service
expectedService := createTestService("foo", []string{"rev1", "rev2"}, goodConditions())
expectedService := createTestService("foo", []string{"rev1", "rev2", "rev3"}, goodConditions())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test for the base case with one revision? I think there is but worth double checking. Thx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the base case with one revision.

expectedService.Status.Traffic = expectedService.Status.Traffic[2:]
expectedService.Status.Traffic[0].LatestRevision = ptr.Bool(true)
expectedService.Status.Traffic[0].Percent = ptr.Int64(int64(100))
r.GetService("foo", &expectedService, nil)

rev1 := createTestRevision("rev1", 1)
rev2 := createTestRevision("rev2", 2)
rev3 := createTestRevision("rev3", 3)

revList := servingv1.RevisionList{
TypeMeta: metav1.TypeMeta{
Kind: "RevisionList",
APIVersion: "serving.knative.dev/v1",
},
Items: []servingv1.Revision{
rev1, rev2,
rev1, rev2, rev3,
},
}

// Return the list of all revisions
r.ListRevisions(knclient.HasLabelSelector(api_serving.ServiceLabelKey, "foo"), &revList, nil)

// Fetch the revisions
r.GetRevision("rev1", &rev1, nil)
r.GetRevision("rev2", &rev2, nil)
r.GetRevision("rev3", &rev3, nil)

// Testing:
output, err := executeServiceCommand(client, "describe", "foo", "--verbose")
Expand All @@ -462,12 +465,16 @@ func TestServiceDescribeVerbose(t *testing.T) {
validateServiceOutput(t, "foo", output)

assert.Assert(t, cmp.Regexp("Cluster:\\s+https://foo.default.svc.cluster.local", output))
assert.Assert(t, util.ContainsAll(output, "Image", "Name", "gcr.io/test/image (at 123456)", "50%", "(0s)"))
assert.Assert(t, util.ContainsAll(output, "Image", "Name", "gcr.io/test/image (at 123456)", "100%", "(0s)"))
assert.Assert(t, util.ContainsAll(output, "Env:", "env1=eval1\n", "env2=eval2\n"))
assert.Assert(t, util.ContainsAll(output, "EnvFrom:", "cm:test1\n", "cm:test2\n"))
assert.Assert(t, util.ContainsAll(output, "Annotations:", "anno1=aval1\n", "anno2=aval2\n"))
assert.Assert(t, util.ContainsAll(output, "Labels:", "label1=lval1\n", "label2=lval2\n"))
assert.Assert(t, util.ContainsAll(output, "[1]", "[2]"))
assert.Assert(t, util.ContainsAll(output, "rev1", "rev2", "rev3"))
assert.Equal(t, strings.Count(output, "rev3"), 1)
assert.Equal(t, strings.Count(output, "rev2"), 1)
assert.Equal(t, strings.Count(output, "rev1"), 1)

// Validate that all recorded API methods have been called
r.Validate()
Expand Down