diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index f4f10a7bb0..65ea62ea7d 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -17,6 +17,10 @@ |=== | | Description | PR +| 🐣 +| Uniform multiple writeSink(s) to DescribeSink +| https://github.com/knative/client/pull/1075[#1075] + | 🐛 | Fix various misspellings and linter items | https://github.com/knative/client/pull/1057[#1057] diff --git a/lib/printing/describe.go b/lib/printing/describe.go index a130ad6463..ab51de85c1 100644 --- a/lib/printing/describe.go +++ b/lib/printing/describe.go @@ -24,11 +24,15 @@ import ( ) // DescribeSink prints the given 'sink' for the given prefix writer 'dw', -// provide 'attribute' to print the section heading for this sink +// provide 'attribute' to print the section heading for this sink, +// 'Sink' is used if 'attribute' is an empty string. func DescribeSink(dw printers.PrefixWriter, attribute, namespace string, sink *duckv1.Destination) { if sink == nil { return } + if len(attribute) == 0 { + attribute = "Sink" + } subWriter := dw.WriteAttribute(attribute, "") ref := sink.Ref if ref != nil { diff --git a/pkg/kn/commands/source/apiserver/describe.go b/pkg/kn/commands/source/apiserver/describe.go index 150c31e9da..8b273df058 100644 --- a/pkg/kn/commands/source/apiserver/describe.go +++ b/pkg/kn/commands/source/apiserver/describe.go @@ -21,8 +21,8 @@ import ( "github.com/spf13/cobra" v1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" - duckv1 "knative.dev/pkg/apis/duck/v1" + "knative.dev/client/lib/printing" "knative.dev/client/pkg/kn/commands" "knative.dev/client/pkg/printers" ) @@ -65,7 +65,7 @@ func NewAPIServerDescribeCommand(p *commands.KnParams) *cobra.Command { return err } - writeSink(dw, apiSource.Spec.Sink) + printing.DescribeSink(dw, "", apiSource.Namespace, &apiSource.Spec.Sink) dw.WriteLine() if err := dw.Flush(); err != nil { return err @@ -107,20 +107,6 @@ func writeResources(dw printers.PrefixWriter, apiVersionKindSelectors []v1alpha2 } } -func writeSink(dw printers.PrefixWriter, sink duckv1.Destination) { - subWriter := dw.WriteAttribute("Sink", "") - ref := sink.Ref - if ref != nil { - subWriter.WriteAttribute("Name", sink.Ref.Name) - subWriter.WriteAttribute("Namespace", sink.Ref.Namespace) - subWriter.WriteAttribute("Kind", fmt.Sprintf("%s (%s)", sink.Ref.Kind, sink.Ref.APIVersion)) - } - uri := sink.URI - if uri != nil { - subWriter.WriteAttribute("URI", uri.String()) - } -} - func writeAPIServerSource(dw printers.PrefixWriter, source *v1alpha2.ApiServerSource, printDetails bool) { commands.WriteMetadata(dw, &source.ObjectMeta, printDetails) dw.WriteAttribute("ServiceAccountName", source.Spec.ServiceAccountName) diff --git a/pkg/kn/commands/source/binding/describe.go b/pkg/kn/commands/source/binding/describe.go index 41390c0ebb..927858994d 100644 --- a/pkg/kn/commands/source/binding/describe.go +++ b/pkg/kn/commands/source/binding/describe.go @@ -21,9 +21,9 @@ import ( "github.com/spf13/cobra" v1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" - duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/pkg/tracker" + "knative.dev/client/lib/printing" "knative.dev/client/pkg/kn/commands" "knative.dev/client/pkg/printers" ) @@ -85,28 +85,12 @@ func NewBindingDescribeCommand(p *commands.KnParams) *cobra.Command { func writeSinkBinding(dw printers.PrefixWriter, binding *v1alpha2.SinkBinding, printDetails bool) { commands.WriteMetadata(dw, &binding.ObjectMeta, printDetails) writeSubject(dw, binding.Namespace, &binding.Spec.Subject) - writeSink(dw, binding.Namespace, &binding.Spec.Sink) + printing.DescribeSink(dw, "", binding.Namespace, &binding.Spec.Sink) if binding.Spec.CloudEventOverrides != nil && binding.Spec.CloudEventOverrides.Extensions != nil { writeCeOverrides(dw, binding.Spec.CloudEventOverrides.Extensions) } } -func writeSink(dw printers.PrefixWriter, namespace string, sink *duckv1.Destination) { - subWriter := dw.WriteAttribute("Sink", "") - ref := sink.Ref - if ref != nil { - subWriter.WriteAttribute("Name", sink.Ref.Name) - if sink.Ref.Namespace != "" && sink.Ref.Namespace != namespace { - subWriter.WriteAttribute("Namespace", sink.Ref.Namespace) - } - subWriter.WriteAttribute("Resource", fmt.Sprintf("%s (%s)", sink.Ref.Kind, sink.Ref.APIVersion)) - } - uri := sink.URI - if uri != nil { - subWriter.WriteAttribute("URI", uri.String()) - } -} - func writeCeOverrides(dw printers.PrefixWriter, ceOverrides map[string]string) { subDw := dw.WriteAttribute("CloudEvent Overrides", "") keys := make([]string, 0, len(ceOverrides)) diff --git a/pkg/kn/commands/source/ping/describe.go b/pkg/kn/commands/source/ping/describe.go index 83c5749b4e..18bf9e196a 100644 --- a/pkg/kn/commands/source/ping/describe.go +++ b/pkg/kn/commands/source/ping/describe.go @@ -16,13 +16,12 @@ package ping import ( "errors" - "fmt" "sort" "github.com/spf13/cobra" v1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" - duckv1 "knative.dev/pkg/apis/duck/v1" + "knative.dev/client/lib/printing" "knative.dev/client/pkg/kn/commands" "knative.dev/client/pkg/printers" ) @@ -67,7 +66,7 @@ func NewPingDescribeCommand(p *commands.KnParams) *cobra.Command { } // Revisions summary info - writeSink(dw, &pingSource.Spec.Sink) + printing.DescribeSink(dw, "", pingSource.Namespace, &pingSource.Spec.Sink) dw.WriteLine() if err := dw.Flush(); err != nil { return err @@ -97,20 +96,6 @@ func NewPingDescribeCommand(p *commands.KnParams) *cobra.Command { return pingDescribe } -func writeSink(dw printers.PrefixWriter, sink *duckv1.Destination) { - subWriter := dw.WriteAttribute("Sink", "") - ref := sink.Ref - if ref != nil { - subWriter.WriteAttribute("Name", sink.Ref.Name) - subWriter.WriteAttribute("Namespace", sink.Ref.Namespace) - subWriter.WriteAttribute("Resource", fmt.Sprintf("%s (%s)", sink.Ref.Kind, sink.Ref.APIVersion)) - } - uri := sink.URI - if uri != nil { - subWriter.WriteAttribute("URI", uri.String()) - } -} - func writePingSource(dw printers.PrefixWriter, source *v1alpha2.PingSource, printDetails bool) { commands.WriteMetadata(dw, &source.ObjectMeta, printDetails) dw.WriteAttribute("Schedule", source.Spec.Schedule) diff --git a/pkg/kn/commands/trigger/describe.go b/pkg/kn/commands/trigger/describe.go index 4cae159f83..c732bbf409 100644 --- a/pkg/kn/commands/trigger/describe.go +++ b/pkg/kn/commands/trigger/describe.go @@ -16,13 +16,12 @@ package trigger import ( "errors" - "fmt" "github.com/spf13/cobra" v1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" - duckv1 "knative.dev/pkg/apis/duck/v1" + "knative.dev/client/lib/printing" "knative.dev/client/pkg/kn/commands" "knative.dev/client/pkg/printers" ) @@ -74,7 +73,7 @@ func NewTriggerDescribeCommand(p *commands.KnParams) *cobra.Command { } // Revisions summary info - writeSink(dw, &trigger.Spec.Subscriber) + printing.DescribeSink(dw, "", trigger.Namespace, &trigger.Spec.Subscriber) dw.WriteLine() if err := dw.Flush(); err != nil { return err @@ -96,20 +95,6 @@ func NewTriggerDescribeCommand(p *commands.KnParams) *cobra.Command { return triggerDescribe } -func writeSink(dw printers.PrefixWriter, sink *duckv1.Destination) { - subWriter := dw.WriteAttribute("Sink", "") - ref := sink.Ref - if ref != nil { - subWriter.WriteAttribute("Name", sink.Ref.Name) - subWriter.WriteAttribute("Namespace", sink.Ref.Namespace) - subWriter.WriteAttribute("Resource", fmt.Sprintf("%s (%s)", sink.Ref.Kind, sink.Ref.APIVersion)) - } - uri := sink.URI - if uri != nil { - subWriter.WriteAttribute("URI", uri.String()) - } -} - func writeTrigger(dw printers.PrefixWriter, trigger *v1beta1.Trigger, printDetails bool) { commands.WriteMetadata(dw, &trigger.ObjectMeta, printDetails) dw.WriteAttribute("Broker", trigger.Spec.Broker)