Harmonize list headers for trigger and sources (#658)

This commit is contained in:
Ying Chun Guo 2020-02-13 15:40:36 +08:00 committed by GitHub
parent 3019f6813b
commit f9d907d401
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 49 additions and 38 deletions

View File

@ -105,3 +105,18 @@ func parseSink(sink string) (string, string) {
return parts[0], parts[1] return parts[0], parts[1]
} }
} }
// SinkToString prepares a sink for list output
func SinkToString(sink duckv1.Destination) string {
if sink.Ref != nil {
if sink.Ref.Kind == "Service" {
return fmt.Sprintf("svc:%s", sink.Ref.Name)
} else {
return fmt.Sprintf("%s:%s", strings.ToLower(sink.Ref.Kind), sink.Ref.Name)
}
}
if sink.URI != nil {
return sink.URI.String()
}
return ""
}

View File

@ -165,6 +165,7 @@ func APIServerSourceListHandlers(h hprinters.PrintHandler) {
{Name: "Name", Type: "string", Description: "Name of the ApiServer source", Priority: 1}, {Name: "Name", Type: "string", Description: "Name of the ApiServer source", Priority: 1},
{Name: "Resources", Type: "string", Description: "Event resources configured for the ApiServer source", Priority: 1}, {Name: "Resources", Type: "string", Description: "Event resources configured for the ApiServer source", Priority: 1},
{Name: "Sink", Type: "string", Description: "Sink of the ApiServer source", Priority: 1}, {Name: "Sink", Type: "string", Description: "Sink of the ApiServer source", Priority: 1},
{Name: "Age", Type: "string", Description: "Age of the ApiServer source", Priority: 1},
{Name: "Conditions", Type: "string", Description: "Ready state conditions", Priority: 1}, {Name: "Conditions", Type: "string", Description: "Ready state conditions", Priority: 1},
{Name: "Ready", Type: "string", Description: "Ready state of the ApiServer source", Priority: 1}, {Name: "Ready", Type: "string", Description: "Ready state of the ApiServer source", Priority: 1},
{Name: "Reason", Type: "string", Description: "Reason if state is not Ready", Priority: 1}, {Name: "Reason", Type: "string", Description: "Reason if state is not Ready", Priority: 1},
@ -180,6 +181,7 @@ func printSource(source *v1alpha1.ApiServerSource, options hprinters.PrintOption
} }
name := source.Name name := source.Name
age := commands.TranslateTimestampSince(source.CreationTimestamp)
conditions := commands.ConditionsValue(source.Status.Conditions) conditions := commands.ConditionsValue(source.Status.Conditions)
ready := commands.ReadyCondition(source.Status.Conditions) ready := commands.ReadyCondition(source.Status.Conditions)
reason := strings.TrimSpace(commands.NonReadyConditionReason(source.Status.Conditions)) reason := strings.TrimSpace(commands.NonReadyConditionReason(source.Status.Conditions))
@ -206,7 +208,7 @@ func printSource(source *v1alpha1.ApiServerSource, options hprinters.PrintOption
row.Cells = append(row.Cells, source.Namespace) row.Cells = append(row.Cells, source.Namespace)
} }
row.Cells = append(row.Cells, name, strings.Join(resources[:], ","), sink, conditions, ready, reason) row.Cells = append(row.Cells, name, strings.Join(resources[:], ","), sink, age, conditions, ready, reason)
return []metav1beta1.TableRow{row}, nil return []metav1beta1.TableRow{row}, nil
} }

View File

@ -36,7 +36,7 @@ func TestListAPIServerSource(t *testing.T) {
out, err := executeAPIServerSourceCommand(apiServerClient, nil, "list") out, err := executeAPIServerSourceCommand(apiServerClient, nil, "list")
assert.NilError(t, err, "sources should be listed") assert.NilError(t, err, "sources should be listed")
util.ContainsAll(out, "NAME", "RESOURCES", "SINK", "CONDITIONS", "READY", "REASON") util.ContainsAll(out, "NAME", "RESOURCES", "SINK", "AGE", "CONDITIONS", "READY", "REASON")
util.ContainsAll(out, "testsource", "Eventing:v1:false", "mysvc") util.ContainsAll(out, "testsource", "Eventing:v1:false", "mysvc")
apiServerRecorder.Validate() apiServerRecorder.Validate()
@ -52,7 +52,7 @@ func TestListAPIServerSourceEmpty(t *testing.T) {
out, err := executeAPIServerSourceCommand(apiServerClient, nil, "list") out, err := executeAPIServerSourceCommand(apiServerClient, nil, "list")
assert.NilError(t, err, "Sources should be listed") assert.NilError(t, err, "Sources should be listed")
util.ContainsNone(out, "NAME", "RESOURCES", "SINK", "CONDITIONS", "READY", "REASON") util.ContainsNone(out, "NAME", "RESOURCES", "SINK", "AGE", "CONDITIONS", "READY", "REASON")
util.ContainsAll(out, "No", "ApiServer", "source", "found") util.ContainsAll(out, "No", "ApiServer", "source", "found")
apiServerRecorder.Validate() apiServerRecorder.Validate()

View File

@ -23,7 +23,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
"knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1alpha1" "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1alpha1"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/tracker" "knative.dev/pkg/tracker"
"knative.dev/client/pkg/kn/commands" "knative.dev/client/pkg/kn/commands"
@ -133,23 +132,6 @@ func subjectToString(ref tracker.Reference) string {
return ret return ret
} }
// sinkToString prepares a sink for list output
// This is kept here until we have moved everything to duckv1 (currently the other sources
// are still on duckv1beta1)
func sinkToString(sink duckv1.Destination) string {
if sink.Ref != nil {
if sink.Ref.Kind == "Service" {
return fmt.Sprintf("svc:%s", sink.Ref.Name)
} else {
return fmt.Sprintf("%s:%s", sink.Ref.Kind, sink.Ref.Name)
}
}
if sink.URI != nil {
return sink.URI.String()
}
return ""
}
// updateCeOverrides updates the values of the --ce-override flags if given // updateCeOverrides updates the values of the --ce-override flags if given
func updateCeOverrides(bindingFlags bindingUpdateFlags, bindingBuilder *clientsourcesv1alpha1.SinkBindingBuilder) error { func updateCeOverrides(bindingFlags bindingUpdateFlags, bindingBuilder *clientsourcesv1alpha1.SinkBindingBuilder) error {
if bindingFlags.ceOverrides != nil { if bindingFlags.ceOverrides != nil {

View File

@ -20,6 +20,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"knative.dev/client/pkg/kn/commands" "knative.dev/client/pkg/kn/commands"
"knative.dev/client/pkg/kn/commands/flags"
hprinters "knative.dev/client/pkg/printers" hprinters "knative.dev/client/pkg/printers"
"knative.dev/eventing/pkg/apis/sources/v1alpha1" "knative.dev/eventing/pkg/apis/sources/v1alpha1"
@ -41,6 +42,7 @@ func BindingListHandlers(h hprinters.PrintHandler) {
{Name: "Name", Type: "string", Description: "Name of sink binding", Priority: 1}, {Name: "Name", Type: "string", Description: "Name of sink binding", Priority: 1},
{Name: "Subject", Type: "string", Description: "Subject part of binding", Priority: 1}, {Name: "Subject", Type: "string", Description: "Subject part of binding", Priority: 1},
{Name: "Sink", Type: "string", Description: "Sink part of binding", Priority: 1}, {Name: "Sink", Type: "string", Description: "Sink part of binding", Priority: 1},
{Name: "Age", Type: "string", Description: "Age of binding", Priority: 1},
{Name: "Conditions", Type: "string", Description: "Ready state conditions", Priority: 1}, {Name: "Conditions", Type: "string", Description: "Ready state conditions", Priority: 1},
{Name: "Ready", Type: "string", Description: "Ready state of the sink binding", Priority: 1}, {Name: "Ready", Type: "string", Description: "Ready state of the sink binding", Priority: 1},
{Name: "Reason", Type: "string", Description: "Reason if state is not Ready", Priority: 1}, {Name: "Reason", Type: "string", Description: "Reason if state is not Ready", Priority: 1},
@ -57,7 +59,8 @@ func printSinkBinding(binding *v1alpha1.SinkBinding, options hprinters.PrintOpti
name := binding.Name name := binding.Name
subject := subjectToString(binding.Spec.Subject) subject := subjectToString(binding.Spec.Subject)
sink := sinkToString(binding.Spec.Sink) sink := flags.SinkToString(binding.Spec.Sink)
age := commands.TranslateTimestampSince(binding.CreationTimestamp)
conditions := commands.ConditionsValue(binding.Status.Conditions) conditions := commands.ConditionsValue(binding.Status.Conditions)
ready := commands.ReadyCondition(binding.Status.Conditions) ready := commands.ReadyCondition(binding.Status.Conditions)
reason := commands.NonReadyConditionReason(binding.Status.Conditions) reason := commands.NonReadyConditionReason(binding.Status.Conditions)
@ -66,7 +69,7 @@ func printSinkBinding(binding *v1alpha1.SinkBinding, options hprinters.PrintOpti
row.Cells = append(row.Cells, binding.Namespace) row.Cells = append(row.Cells, binding.Namespace)
} }
row.Cells = append(row.Cells, name, subject, sink, conditions, ready, reason) row.Cells = append(row.Cells, name, subject, sink, age, conditions, ready, reason)
return []metav1beta1.TableRow{row}, nil return []metav1beta1.TableRow{row}, nil
} }

View File

@ -38,7 +38,7 @@ func TestListSimple(t *testing.T) {
out, err := executeSinkBindingCommand(bindingClient, nil, "list") out, err := executeSinkBindingCommand(bindingClient, nil, "list")
assert.NilError(t, err, "Sources should be listed") assert.NilError(t, err, "Sources should be listed")
util.ContainsAll(out, "NAME", "SUBJECT", "SINK", "CONDITIONS", "READY", "REASON") util.ContainsAll(out, "NAME", "SUBJECT", "SINK", "AGE", "CONDITIONS", "READY", "REASON")
util.ContainsAll(out, "testbinding", "deployment:apps/v1:mydeploy", "mysvc") util.ContainsAll(out, "testbinding", "deployment:apps/v1:mydeploy", "mysvc")
bindingRecorder.Validate() bindingRecorder.Validate()
@ -53,7 +53,7 @@ func TestListEmpty(t *testing.T) {
out, err := executeSinkBindingCommand(bindingClient, nil, "list") out, err := executeSinkBindingCommand(bindingClient, nil, "list")
assert.NilError(t, err, "Sources should be listed") assert.NilError(t, err, "Sources should be listed")
util.ContainsNone(out, "NAME", "SUBJECT", "SINK", "CONDITIONS", "READY", "REASON") util.ContainsNone(out, "NAME", "SUBJECT", "SINK", "AGE", "CONDITIONS", "READY", "REASON")
util.ContainsAll(out, "No", "sink binding", "found") util.ContainsAll(out, "No", "sink binding", "found")
bindingRecorder.Validate() bindingRecorder.Validate()

View File

@ -45,6 +45,7 @@ func CronJobSourceListHandlers(h hprinters.PrintHandler) {
{Name: "Name", Type: "string", Description: "Name of the CronJob source", Priority: 1}, {Name: "Name", Type: "string", Description: "Name of the CronJob source", Priority: 1},
{Name: "Schedule", Type: "string", Description: "Schedule of the CronJob source", Priority: 1}, {Name: "Schedule", Type: "string", Description: "Schedule of the CronJob source", Priority: 1},
{Name: "Sink", Type: "string", Description: "Sink of the CronJob source", Priority: 1}, {Name: "Sink", Type: "string", Description: "Sink of the CronJob source", Priority: 1},
{Name: "Age", Type: "string", Description: "Age of the CronJob source", Priority: 1},
{Name: "Conditions", Type: "string", Description: "Ready state conditions", Priority: 1}, {Name: "Conditions", Type: "string", Description: "Ready state conditions", Priority: 1},
{Name: "Ready", Type: "string", Description: "Ready state of the CronJob source", Priority: 1}, {Name: "Ready", Type: "string", Description: "Ready state of the CronJob source", Priority: 1},
{Name: "Reason", Type: "string", Description: "Reason if state is not Ready", Priority: 1}, {Name: "Reason", Type: "string", Description: "Reason if state is not Ready", Priority: 1},
@ -61,6 +62,7 @@ func printSource(source *v1alpha1.CronJobSource, options hprinters.PrintOptions)
name := source.Name name := source.Name
schedule := source.Spec.Schedule schedule := source.Spec.Schedule
age := commands.TranslateTimestampSince(source.CreationTimestamp)
conditions := commands.ConditionsValue(source.Status.Conditions) conditions := commands.ConditionsValue(source.Status.Conditions)
ready := commands.ReadyCondition(source.Status.Conditions) ready := commands.ReadyCondition(source.Status.Conditions)
reason := commands.NonReadyConditionReason(source.Status.Conditions) reason := commands.NonReadyConditionReason(source.Status.Conditions)
@ -83,7 +85,7 @@ func printSource(source *v1alpha1.CronJobSource, options hprinters.PrintOptions)
row.Cells = append(row.Cells, source.Namespace) row.Cells = append(row.Cells, source.Namespace)
} }
row.Cells = append(row.Cells, name, schedule, sink, conditions, ready, reason) row.Cells = append(row.Cells, name, schedule, sink, age, conditions, ready, reason)
return []metav1beta1.TableRow{row}, nil return []metav1beta1.TableRow{row}, nil
} }

View File

@ -36,7 +36,7 @@ func TestListCronJobSource(t *testing.T) {
out, err := executeCronJobSourceCommand(cronjobClient, nil, "list") out, err := executeCronJobSourceCommand(cronjobClient, nil, "list")
assert.NilError(t, err, "Sources should be listed") assert.NilError(t, err, "Sources should be listed")
util.ContainsAll(out, "NAME", "SCHEDULE", "SINK", "CONDITIONS", "READY", "REASON") util.ContainsAll(out, "NAME", "SCHEDULE", "SINK", "AGE", "CONDITIONS", "READY", "REASON")
util.ContainsAll(out, "testsource", "* * * * */2", "mysvc") util.ContainsAll(out, "testsource", "* * * * */2", "mysvc")
cronJobRecorder.Validate() cronJobRecorder.Validate()
@ -52,7 +52,7 @@ func TestListCronJobSourceEmpty(t *testing.T) {
out, err := executeCronJobSourceCommand(cronjobClient, nil, "list") out, err := executeCronJobSourceCommand(cronjobClient, nil, "list")
assert.NilError(t, err, "Sources should be listed") assert.NilError(t, err, "Sources should be listed")
util.ContainsNone(out, "NAME", "SCHEDULE", "SINK", "CONDITIONS", "READY", "REASON") util.ContainsNone(out, "NAME", "SCHEDULE", "SINK", "AGE", "CONDITIONS", "READY", "REASON")
util.ContainsAll(out, "No", "CronJob", "source", "found") util.ContainsAll(out, "No", "CronJob", "source", "found")
cronJobRecorder.Validate() cronJobRecorder.Validate()

View File

@ -20,6 +20,7 @@ import (
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"
"knative.dev/client/pkg/kn/commands/flags"
hprinters "knative.dev/client/pkg/printers" hprinters "knative.dev/client/pkg/printers"
eventing "knative.dev/eventing/pkg/apis/eventing/v1alpha1" eventing "knative.dev/eventing/pkg/apis/eventing/v1alpha1"
) )
@ -27,12 +28,14 @@ import (
// TriggerListHandlers handles printing human readable table for `kn source list-types` command's output // TriggerListHandlers handles printing human readable table for `kn source list-types` command's output
func TriggerListHandlers(h hprinters.PrintHandler) { func TriggerListHandlers(h hprinters.PrintHandler) {
sourceTypesColumnDefinitions := []metav1beta1.TableColumnDefinition{ sourceTypesColumnDefinitions := []metav1beta1.TableColumnDefinition{
{Name: "Namespace", Type: "string", Description: "Namespace of the trigger", Priority: 0}, {Name: "Namespace", Type: "string", Description: "Namespace of the trigger.", Priority: 0},
{Name: "Name", Type: "string", Description: "Name of the trigger", Priority: 1}, {Name: "Name", Type: "string", Description: "Name of the trigger.", Priority: 1},
{Name: "Broker", Type: "string", Description: "Name of the broker", Priority: 1}, {Name: "Broker", Type: "string", Description: "Name of the broker.", Priority: 1},
{Name: "Subscriber_URI", Type: "string", Description: "URI of the subscriber", Priority: 1}, {Name: "Sink", Type: "string", Description: "Sink for events, i.e. the subscriber.", Priority: 1},
{Name: "Ready", Type: "string", Description: "Ready condition status of the trigger", Priority: 1}, {Name: "Age", Type: "string", Description: "Age of the trigger.", Priority: 1},
{Name: "Reason", Type: "string", Description: "Reason for non-ready condition of the trigger", Priority: 1}, {Name: "Conditions", Type: "string", Description: "Ready state conditions.", Priority: 1},
{Name: "Ready", Type: "string", Description: "Ready condition status of the trigger.", Priority: 1},
{Name: "Reason", Type: "string", Description: "Reason for non-ready condition of the trigger.", Priority: 1},
} }
h.TableHandler(sourceTypesColumnDefinitions, printTrigger) h.TableHandler(sourceTypesColumnDefinitions, printTrigger)
h.TableHandler(sourceTypesColumnDefinitions, printTriggerList) h.TableHandler(sourceTypesColumnDefinitions, printTriggerList)
@ -42,7 +45,9 @@ func TriggerListHandlers(h hprinters.PrintHandler) {
func printTrigger(trigger *eventing.Trigger, options hprinters.PrintOptions) ([]metav1beta1.TableRow, error) { func printTrigger(trigger *eventing.Trigger, options hprinters.PrintOptions) ([]metav1beta1.TableRow, error) {
name := trigger.Name name := trigger.Name
broker := trigger.Spec.Broker broker := trigger.Spec.Broker
uri := trigger.Status.SubscriberURI sink := flags.SinkToString(trigger.Spec.Subscriber)
age := commands.TranslateTimestampSince(trigger.CreationTimestamp)
conditions := commands.ConditionsValue(trigger.Status.Conditions)
ready := commands.ReadyCondition(trigger.Status.Conditions) ready := commands.ReadyCondition(trigger.Status.Conditions)
reason := commands.NonReadyConditionReason(trigger.Status.Conditions) reason := commands.NonReadyConditionReason(trigger.Status.Conditions)
@ -57,7 +62,9 @@ func printTrigger(trigger *eventing.Trigger, options hprinters.PrintOptions) ([]
row.Cells = append(row.Cells, row.Cells = append(row.Cells,
name, name,
broker, broker,
uri, sink,
age,
conditions,
ready, ready,
reason) reason)
return []metav1beta1.TableRow{row}, nil return []metav1beta1.TableRow{row}, nil

View File

@ -49,7 +49,7 @@ func TestTriggerList(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
outputLines := strings.Split(output, "\n") outputLines := strings.Split(output, "\n")
assert.Check(t, util.ContainsAll(outputLines[0], "NAME", "BROKER", "SUBSCRIBER_URI", "READY", "REASON")) assert.Check(t, util.ContainsAll(outputLines[0], "NAME", "BROKER", "SINK", "AGE", "CONDITIONS", "READY", "REASON"))
assert.Check(t, util.ContainsAll(outputLines[1], "trigger1", "mybroker1", "mysink")) assert.Check(t, util.ContainsAll(outputLines[1], "trigger1", "mybroker1", "mysink"))
assert.Check(t, util.ContainsAll(outputLines[2], "trigger2", "mybroker2", "mysink")) assert.Check(t, util.ContainsAll(outputLines[2], "trigger2", "mybroker2", "mysink"))
assert.Check(t, util.ContainsAll(outputLines[3], "trigger3", "mybroker3", "mysink")) assert.Check(t, util.ContainsAll(outputLines[3], "trigger3", "mybroker3", "mysink"))
@ -90,7 +90,7 @@ func TestTriggerListAllNamespace(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
outputLines := strings.Split(output, "\n") outputLines := strings.Split(output, "\n")
assert.Check(t, util.ContainsAll(outputLines[0], "NAMESPACE", "NAME", "BROKER", "SUBSCRIBER_URI", "READY", "REASON")) assert.Check(t, util.ContainsAll(outputLines[0], "NAMESPACE", "NAME", "BROKER", "SINK", "AGE", "CONDITIONS", "READY", "REASON"))
assert.Check(t, util.ContainsAll(outputLines[1], "default1", "trigger1", "mybroker1", "mysink")) assert.Check(t, util.ContainsAll(outputLines[1], "default1", "trigger1", "mybroker1", "mysink"))
assert.Check(t, util.ContainsAll(outputLines[2], "default2", "trigger2", "mybroker2", "mysink")) assert.Check(t, util.ContainsAll(outputLines[2], "default2", "trigger2", "mybroker2", "mysink"))
assert.Check(t, util.ContainsAll(outputLines[3], "default3", "trigger3", "mybroker3", "mysink")) assert.Check(t, util.ContainsAll(outputLines[3], "default3", "trigger3", "mybroker3", "mysink"))