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

Refine route list output #407

Merged
merged 1 commit into from
Oct 23, 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
26 changes: 3 additions & 23 deletions pkg/kn/commands/route/human_readable_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package route

import (
"fmt"

metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"knative.dev/client/pkg/kn/commands"
Expand All @@ -29,9 +27,7 @@ func RouteListHandlers(h hprinters.PrintHandler) {
kRouteColumnDefinitions := []metav1beta1.TableColumnDefinition{
{Name: "Name", Type: "string", Description: "Name of the Knative route.", Priority: 1},
{Name: "URL", Type: "string", Description: "URL of the Knative route.", Priority: 1},
{Name: "Age", Type: "string", Description: "Age of the Knative route.", Priority: 1},
{Name: "Conditions", Type: "string", Description: "Conditions describing statuses of route components.", Priority: 1},
{Name: "Traffic", Type: "integer", Description: "Traffic configured for route.", Priority: 1},
{Name: "READY", Type: "string", Description: "Ready condition status of the Knative route.", Priority: 1},
}
h.TableHandler(kRouteColumnDefinitions, printRoute)
h.TableHandler(kRouteColumnDefinitions, printKRouteList)
Expand All @@ -54,29 +50,13 @@ func printKRouteList(kRouteList *servingv1alpha1.RouteList, options hprinters.Pr
func printRoute(route *servingv1alpha1.Route, options hprinters.PrintOptions) ([]metav1beta1.TableRow, error) {
name := route.Name
url := route.Status.URL
age := commands.TranslateTimestampSince(route.CreationTimestamp)
conditions := commands.ConditionsValue(route.Status.Conditions)
traffic := calculateTraffic(route.Status.Traffic)
ready := commands.ReadyCondition(route.Status.Conditions)
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: route},
}
row.Cells = append(row.Cells,
name,
url,
age,
conditions,
traffic)
ready)
return []metav1beta1.TableRow{row}, nil
}

func calculateTraffic(targets []servingv1alpha1.TrafficTarget) string {
var traffic string
for _, target := range targets {
if len(traffic) > 0 {
traffic = fmt.Sprintf("%s, %d%% -> %s", traffic, target.Percent, target.RevisionName)
} else {
traffic = fmt.Sprintf("%d%% -> %s", target.Percent, target.RevisionName)
}
}
return traffic
}
16 changes: 8 additions & 8 deletions pkg/kn/commands/route/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func TestRouteListDefaultOutput(t *testing.T) {
} else if !action.Matches("list", "routes") {
t.Errorf("Bad action %v", action)
}
assert.Check(t, util.ContainsAll(output[0], "NAME", "URL", "AGE", "CONDITIONS", "TRAFFIC"))
assert.Check(t, util.ContainsAll(output[1], "foo", "100% -> foo-01234"))
assert.Check(t, util.ContainsAll(output[2], "bar", "100% -> bar-98765"))
assert.Check(t, util.ContainsAll(output[0], "NAME", "URL", "READY"))
assert.Check(t, util.ContainsAll(output[1], "foo"))
assert.Check(t, util.ContainsAll(output[2], "bar"))
}

func TestRouteListDefaultOutputNoHeaders(t *testing.T) {
Expand All @@ -84,9 +84,9 @@ func TestRouteListDefaultOutputNoHeaders(t *testing.T) {
t.Errorf("Bad action %v", action)
}

assert.Check(t, util.ContainsNone(output[0], "NAME", "URL", "GENERATION", "AGE", "CONDITIONS", "READY", "REASON"))
assert.Check(t, util.ContainsAll(output[0], "foo", "100% -> foo-01234"))
assert.Check(t, util.ContainsAll(output[1], "bar", "100% -> bar-98765"))
assert.Check(t, util.ContainsNone(output[0], "NAME", "URL", "READY"))
assert.Check(t, util.ContainsAll(output[0], "foo"))
assert.Check(t, util.ContainsAll(output[1], "bar"))

}

Expand All @@ -100,8 +100,8 @@ func TestRouteListWithTwoTargetsOutput(t *testing.T) {
} else if !action.Matches("list", "routes") {
t.Errorf("Bad action %v", action)
}
assert.Check(t, util.ContainsAll(output[0], "NAME", "URL", "AGE", "CONDITIONS", "TRAFFIC"))
assert.Check(t, util.ContainsAll(output[1], "foo", "20% -> foo-01234, 80% -> foo-98765"))
assert.Check(t, util.ContainsAll(output[0], "NAME", "URL", "READY"))
assert.Check(t, util.ContainsAll(output[1], "foo"))
}

func createMockRouteMeta(name string) *v1alpha1.Route {
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,15 @@ func (test *e2eTest) routeList(t *testing.T) {
out, err := test.kn.RunWithOpts([]string{"route", "list"}, runOpts{})
assert.NilError(t, err)

expectedHeaders := []string{"NAME", "URL", "AGE", "CONDITIONS", "TRAFFIC"}
expectedHeaders := []string{"NAME", "URL", "READY"}
assert.Check(t, util.ContainsAll(out, expectedHeaders...))
}

func (test *e2eTest) routeListWithArgument(t *testing.T, routeName string) {
out, err := test.kn.RunWithOpts([]string{"route", "list", routeName}, runOpts{})
assert.NilError(t, err)

expectedOutput := fmt.Sprintf("100%% -> %s", routeName)
assert.Check(t, util.ContainsAll(out, routeName, expectedOutput))
assert.Check(t, util.ContainsAll(out, routeName))
}

func (test *e2eTest) routeDescribe(t *testing.T, routeName string) {
Expand Down