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

Uniform multiple writeSink(s) to DescribeSink #1075

Merged
merged 1 commit into from
Oct 29, 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 @@ -17,6 +17,10 @@
|===
| | Description | PR

| 🐣
| Uniform multiple writeSink to DescribeSink
| https://github.com/knative/client/pull/1075[#1075]

| 🐣
| Add function ResolvePodSpec and move the utilities to podspec_helper
| https://github.com/knative/client/pull/1024[#1024]
Expand Down
2 changes: 1 addition & 1 deletion lib/printing/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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,
func DescribeSink(dw printers.PrefixWriter, attribute, namespace string, sink *duckv1.Destination) {
if sink == nil {
return
Expand Down
18 changes: 2 additions & 16 deletions pkg/kn/commands/source/apiserver/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -65,7 +65,7 @@ func NewAPIServerDescribeCommand(p *commands.KnParams) *cobra.Command {
return err
}

writeSink(dw, apiSource.Spec.Sink)
printing.DescribeSink(dw, "Sink", apiSource.Namespace, &apiSource.Spec.Sink)
dw.WriteLine()
if err := dw.Flush(); err != nil {
return err
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 2 additions & 18 deletions pkg/kn/commands/source/binding/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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, "Sink", 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))
Expand Down
19 changes: 2 additions & 17 deletions pkg/kn/commands/source/ping/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -67,7 +66,7 @@ func NewPingDescribeCommand(p *commands.KnParams) *cobra.Command {
}

// Revisions summary info
writeSink(dw, &pingSource.Spec.Sink)
printing.DescribeSink(dw, "Sink", pingSource.Namespace, &pingSource.Spec.Sink)
dw.WriteLine()
if err := dw.Flush(); err != nil {
return err
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 2 additions & 17 deletions pkg/kn/commands/trigger/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -74,7 +73,7 @@ func NewTriggerDescribeCommand(p *commands.KnParams) *cobra.Command {
}

// Revisions summary info
writeSink(dw, &trigger.Spec.Subscriber)
printing.DescribeSink(dw, "Sink", trigger.Namespace, &trigger.Spec.Subscriber)
dw.WriteLine()
if err := dw.Flush(); err != nil {
return err
Expand All @@ -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)
Expand Down