mirror of https://github.com/knative/client.git
Refine route list output (#407)
- Only show NAME/URL/READY [issue 350](https://github.com/knative/client/issues/350)
This commit is contained in:
parent
df04573590
commit
f77c034c4a
|
|
@ -15,8 +15,6 @@
|
||||||
package route
|
package route
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
|
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"knative.dev/client/pkg/kn/commands"
|
"knative.dev/client/pkg/kn/commands"
|
||||||
|
|
@ -29,9 +27,7 @@ func RouteListHandlers(h hprinters.PrintHandler) {
|
||||||
kRouteColumnDefinitions := []metav1beta1.TableColumnDefinition{
|
kRouteColumnDefinitions := []metav1beta1.TableColumnDefinition{
|
||||||
{Name: "Name", Type: "string", Description: "Name of the Knative route.", Priority: 1},
|
{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: "URL", Type: "string", Description: "URL of the Knative route.", Priority: 1},
|
||||||
{Name: "Age", Type: "string", Description: "Age of the Knative route.", Priority: 1},
|
{Name: "READY", Type: "string", Description: "Ready condition status 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},
|
|
||||||
}
|
}
|
||||||
h.TableHandler(kRouteColumnDefinitions, printRoute)
|
h.TableHandler(kRouteColumnDefinitions, printRoute)
|
||||||
h.TableHandler(kRouteColumnDefinitions, printKRouteList)
|
h.TableHandler(kRouteColumnDefinitions, printKRouteList)
|
||||||
|
|
@ -54,29 +50,13 @@ func printKRouteList(kRouteList *servingv1alpha1.RouteList, options hprinters.Pr
|
||||||
func printRoute(route *servingv1alpha1.Route, options hprinters.PrintOptions) ([]metav1beta1.TableRow, error) {
|
func printRoute(route *servingv1alpha1.Route, options hprinters.PrintOptions) ([]metav1beta1.TableRow, error) {
|
||||||
name := route.Name
|
name := route.Name
|
||||||
url := route.Status.URL
|
url := route.Status.URL
|
||||||
age := commands.TranslateTimestampSince(route.CreationTimestamp)
|
ready := commands.ReadyCondition(route.Status.Conditions)
|
||||||
conditions := commands.ConditionsValue(route.Status.Conditions)
|
|
||||||
traffic := calculateTraffic(route.Status.Traffic)
|
|
||||||
row := metav1beta1.TableRow{
|
row := metav1beta1.TableRow{
|
||||||
Object: runtime.RawExtension{Object: route},
|
Object: runtime.RawExtension{Object: route},
|
||||||
}
|
}
|
||||||
row.Cells = append(row.Cells,
|
row.Cells = append(row.Cells,
|
||||||
name,
|
name,
|
||||||
url,
|
url,
|
||||||
age,
|
ready)
|
||||||
conditions,
|
|
||||||
traffic)
|
|
||||||
return []metav1beta1.TableRow{row}, nil
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,9 @@ func TestRouteListDefaultOutput(t *testing.T) {
|
||||||
} else if !action.Matches("list", "routes") {
|
} else if !action.Matches("list", "routes") {
|
||||||
t.Errorf("Bad action %v", action)
|
t.Errorf("Bad action %v", action)
|
||||||
}
|
}
|
||||||
assert.Check(t, util.ContainsAll(output[0], "NAME", "URL", "AGE", "CONDITIONS", "TRAFFIC"))
|
assert.Check(t, util.ContainsAll(output[0], "NAME", "URL", "READY"))
|
||||||
assert.Check(t, util.ContainsAll(output[1], "foo", "100% -> foo-01234"))
|
assert.Check(t, util.ContainsAll(output[1], "foo"))
|
||||||
assert.Check(t, util.ContainsAll(output[2], "bar", "100% -> bar-98765"))
|
assert.Check(t, util.ContainsAll(output[2], "bar"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRouteListDefaultOutputNoHeaders(t *testing.T) {
|
func TestRouteListDefaultOutputNoHeaders(t *testing.T) {
|
||||||
|
|
@ -84,9 +84,9 @@ func TestRouteListDefaultOutputNoHeaders(t *testing.T) {
|
||||||
t.Errorf("Bad action %v", action)
|
t.Errorf("Bad action %v", action)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Check(t, util.ContainsNone(output[0], "NAME", "URL", "GENERATION", "AGE", "CONDITIONS", "READY", "REASON"))
|
assert.Check(t, util.ContainsNone(output[0], "NAME", "URL", "READY"))
|
||||||
assert.Check(t, util.ContainsAll(output[0], "foo", "100% -> foo-01234"))
|
assert.Check(t, util.ContainsAll(output[0], "foo"))
|
||||||
assert.Check(t, util.ContainsAll(output[1], "bar", "100% -> bar-98765"))
|
assert.Check(t, util.ContainsAll(output[1], "bar"))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,8 +100,8 @@ func TestRouteListWithTwoTargetsOutput(t *testing.T) {
|
||||||
} else if !action.Matches("list", "routes") {
|
} else if !action.Matches("list", "routes") {
|
||||||
t.Errorf("Bad action %v", action)
|
t.Errorf("Bad action %v", action)
|
||||||
}
|
}
|
||||||
assert.Check(t, util.ContainsAll(output[0], "NAME", "URL", "AGE", "CONDITIONS", "TRAFFIC"))
|
assert.Check(t, util.ContainsAll(output[0], "NAME", "URL", "READY"))
|
||||||
assert.Check(t, util.ContainsAll(output[1], "foo", "20% -> foo-01234, 80% -> foo-98765"))
|
assert.Check(t, util.ContainsAll(output[1], "foo"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func createMockRouteMeta(name string) *v1alpha1.Route {
|
func createMockRouteMeta(name string) *v1alpha1.Route {
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ func (test *e2eTest) routeList(t *testing.T) {
|
||||||
out, err := test.kn.RunWithOpts([]string{"route", "list"}, runOpts{})
|
out, err := test.kn.RunWithOpts([]string{"route", "list"}, runOpts{})
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
expectedHeaders := []string{"NAME", "URL", "AGE", "CONDITIONS", "TRAFFIC"}
|
expectedHeaders := []string{"NAME", "URL", "READY"}
|
||||||
assert.Check(t, util.ContainsAll(out, expectedHeaders...))
|
assert.Check(t, util.ContainsAll(out, expectedHeaders...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,8 +72,7 @@ func (test *e2eTest) routeListWithArgument(t *testing.T, routeName string) {
|
||||||
out, err := test.kn.RunWithOpts([]string{"route", "list", routeName}, runOpts{})
|
out, err := test.kn.RunWithOpts([]string{"route", "list", routeName}, runOpts{})
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
expectedOutput := fmt.Sprintf("100%% -> %s", routeName)
|
assert.Check(t, util.ContainsAll(out, routeName))
|
||||||
assert.Check(t, util.ContainsAll(out, routeName, expectedOutput))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test *e2eTest) routeDescribe(t *testing.T, routeName string) {
|
func (test *e2eTest) routeDescribe(t *testing.T, routeName string) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue