diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index e673fcd887..405902b78c 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -27,6 +27,11 @@ | https://github.com/knative/client/pull/1118[#1118] |=== +| 🎁 +| Add machine readable output (-o flag) to kn broker describe +| https://github.com/knative/client/pull/1118[#1124] +|=== + ### v0.19.0 (2020-11-11) [cols="1,10,3", options="header", width="100%"] |=== diff --git a/docs/cmd/kn_broker_describe.md b/docs/cmd/kn_broker_describe.md index ecdb8629cf..8e4abd9e1a 100644 --- a/docs/cmd/kn_broker_describe.md +++ b/docs/cmd/kn_broker_describe.md @@ -19,6 +19,9 @@ kn broker describe NAME # Describe broker 'mybroker' in the 'myproject' namespace kn broker describe mybroker --namespace myproject + + # Describe broker 'mybroker' in YAML format + kn broker describe mybroker -o yaml # Print only broker URL kn broker describe mybroker -o url diff --git a/pkg/eventing/v1beta1/client.go b/pkg/eventing/v1beta1/client.go index 92e056ffab..db5afb782f 100644 --- a/pkg/eventing/v1beta1/client.go +++ b/pkg/eventing/v1beta1/client.go @@ -225,11 +225,15 @@ func (c *knEventingClient) CreateBroker(broker *v1beta1.Broker) error { // GetBroker is used to get an instance of broker func (c *knEventingClient) GetBroker(name string) (*v1beta1.Broker, error) { - trigger, err := c.client.Brokers(c.namespace).Get(context.TODO(), name, apis_v1.GetOptions{}) + broker, err := c.client.Brokers(c.namespace).Get(context.TODO(), name, apis_v1.GetOptions{}) if err != nil { return nil, kn_errors.GetError(err) } - return trigger, nil + err = updateEventingGVK(broker) + if err != nil { + return nil, err + } + return broker, nil } // WatchBroker is used to create watcher object diff --git a/pkg/kn/commands/broker/describe.go b/pkg/kn/commands/broker/describe.go index 7851817376..ca4977ba7a 100644 --- a/pkg/kn/commands/broker/describe.go +++ b/pkg/kn/commands/broker/describe.go @@ -38,6 +38,9 @@ var describeExample = ` # Describe broker 'mybroker' in the 'myproject' namespace kn broker describe mybroker --namespace myproject + + # Describe broker 'mybroker' in YAML format + kn broker describe mybroker -o yaml # Print only broker URL kn broker describe mybroker -o url` diff --git a/pkg/kn/commands/broker/describe_test.go b/pkg/kn/commands/broker/describe_test.go index 5af2f44b27..3f9ddc5394 100644 --- a/pkg/kn/commands/broker/describe_test.go +++ b/pkg/kn/commands/broker/describe_test.go @@ -86,9 +86,25 @@ func TestBrokerDescribeURL(t *testing.T) { recorder.Validate() } +func TestTriggerDescribeMachineReadable(t *testing.T) { + client := clientv1beta1.NewMockKnEventingClient(t, "mynamespace") + + recorder := client.Recorder() + recorder.GetBroker("foo", getBroker(), nil) + + out, err := executeBrokerCommand(client, "describe", "foo", "-o", "yaml") + assert.NilError(t, err) + assert.Assert(t, util.ContainsAll(out, "kind: Broker", "spec:", "status:", "metadata:")) + + recorder.Validate() + +} func getBroker() *v1beta1.Broker { return &v1beta1.Broker{ - TypeMeta: v1.TypeMeta{}, + TypeMeta: v1.TypeMeta{ + Kind: "Broker", + APIVersion: "eventing.knative.dev/v1beta1", + }, ObjectMeta: metav1.ObjectMeta{ Name: "foo", Namespace: "default",