uniform multiple writeSink into DescribeSink (#1075)

This commit is contained in:
Ying Chun Guo 2020-10-29 21:44:34 +08:00 committed by GitHub
parent 6d00de6f1d
commit 6ed76ae2c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 69 deletions

View File

@ -17,6 +17,10 @@
|=== |===
| | Description | PR | | 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 | Add function ResolvePodSpec and move the utilities to podspec_helper
| https://github.com/knative/client/pull/1024[#1024] | https://github.com/knative/client/pull/1024[#1024]

View File

@ -24,7 +24,7 @@ import (
) )
// DescribeSink prints the given 'sink' for the given prefix writer 'dw', // 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) { func DescribeSink(dw printers.PrefixWriter, attribute, namespace string, sink *duckv1.Destination) {
if sink == nil { if sink == nil {
return return

View File

@ -21,8 +21,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
v1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" 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/kn/commands"
"knative.dev/client/pkg/printers" "knative.dev/client/pkg/printers"
) )
@ -65,7 +65,7 @@ func NewAPIServerDescribeCommand(p *commands.KnParams) *cobra.Command {
return err return err
} }
writeSink(dw, apiSource.Spec.Sink) printing.DescribeSink(dw, "Sink", apiSource.Namespace, &apiSource.Spec.Sink)
dw.WriteLine() dw.WriteLine()
if err := dw.Flush(); err != nil { if err := dw.Flush(); err != nil {
return err 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) { func writeAPIServerSource(dw printers.PrefixWriter, source *v1alpha2.ApiServerSource, printDetails bool) {
commands.WriteMetadata(dw, &source.ObjectMeta, printDetails) commands.WriteMetadata(dw, &source.ObjectMeta, printDetails)
dw.WriteAttribute("ServiceAccountName", source.Spec.ServiceAccountName) dw.WriteAttribute("ServiceAccountName", source.Spec.ServiceAccountName)

View File

@ -21,9 +21,9 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
v1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" v1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/tracker" "knative.dev/pkg/tracker"
"knative.dev/client/lib/printing"
"knative.dev/client/pkg/kn/commands" "knative.dev/client/pkg/kn/commands"
"knative.dev/client/pkg/printers" "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) { func writeSinkBinding(dw printers.PrefixWriter, binding *v1alpha2.SinkBinding, printDetails bool) {
commands.WriteMetadata(dw, &binding.ObjectMeta, printDetails) commands.WriteMetadata(dw, &binding.ObjectMeta, printDetails)
writeSubject(dw, binding.Namespace, &binding.Spec.Subject) 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 { if binding.Spec.CloudEventOverrides != nil && binding.Spec.CloudEventOverrides.Extensions != nil {
writeCeOverrides(dw, binding.Spec.CloudEventOverrides.Extensions) 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) { func writeCeOverrides(dw printers.PrefixWriter, ceOverrides map[string]string) {
subDw := dw.WriteAttribute("CloudEvent Overrides", "") subDw := dw.WriteAttribute("CloudEvent Overrides", "")
keys := make([]string, 0, len(ceOverrides)) keys := make([]string, 0, len(ceOverrides))

View File

@ -16,13 +16,12 @@ package ping
import ( import (
"errors" "errors"
"fmt"
"sort" "sort"
"github.com/spf13/cobra" "github.com/spf13/cobra"
v1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" 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/kn/commands"
"knative.dev/client/pkg/printers" "knative.dev/client/pkg/printers"
) )
@ -67,7 +66,7 @@ func NewPingDescribeCommand(p *commands.KnParams) *cobra.Command {
} }
// Revisions summary info // Revisions summary info
writeSink(dw, &pingSource.Spec.Sink) printing.DescribeSink(dw, "Sink", pingSource.Namespace, &pingSource.Spec.Sink)
dw.WriteLine() dw.WriteLine()
if err := dw.Flush(); err != nil { if err := dw.Flush(); err != nil {
return err return err
@ -97,20 +96,6 @@ func NewPingDescribeCommand(p *commands.KnParams) *cobra.Command {
return pingDescribe 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) { func writePingSource(dw printers.PrefixWriter, source *v1alpha2.PingSource, printDetails bool) {
commands.WriteMetadata(dw, &source.ObjectMeta, printDetails) commands.WriteMetadata(dw, &source.ObjectMeta, printDetails)
dw.WriteAttribute("Schedule", source.Spec.Schedule) dw.WriteAttribute("Schedule", source.Spec.Schedule)

View File

@ -16,13 +16,12 @@ package trigger
import ( import (
"errors" "errors"
"fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
v1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" 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/kn/commands"
"knative.dev/client/pkg/printers" "knative.dev/client/pkg/printers"
) )
@ -74,7 +73,7 @@ func NewTriggerDescribeCommand(p *commands.KnParams) *cobra.Command {
} }
// Revisions summary info // Revisions summary info
writeSink(dw, &trigger.Spec.Subscriber) printing.DescribeSink(dw, "Sink", trigger.Namespace, &trigger.Spec.Subscriber)
dw.WriteLine() dw.WriteLine()
if err := dw.Flush(); err != nil { if err := dw.Flush(); err != nil {
return err return err
@ -96,20 +95,6 @@ func NewTriggerDescribeCommand(p *commands.KnParams) *cobra.Command {
return triggerDescribe 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) { func writeTrigger(dw printers.PrefixWriter, trigger *v1beta1.Trigger, printDetails bool) {
commands.WriteMetadata(dw, &trigger.ObjectMeta, printDetails) commands.WriteMetadata(dw, &trigger.ObjectMeta, printDetails)
dw.WriteAttribute("Broker", trigger.Spec.Broker) dw.WriteAttribute("Broker", trigger.Spec.Broker)