Skip to content

Commit

Permalink
machine-readable output for broker
Browse files Browse the repository at this point in the history
Signed-off-by: Arghya Sadhu <[email protected]>
  • Loading branch information
arghya88 committed Nov 18, 2020
1 parent 4539ee8 commit 341d7bd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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/1124[#1124]
|===

### v0.19.0 (2020-11-11)
[cols="1,10,3", options="header", width="100%"]
|===
Expand Down
3 changes: 3 additions & 0 deletions docs/cmd/kn_broker_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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
```
Expand Down
8 changes: 6 additions & 2 deletions pkg/eventing/v1beta1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/kn/commands/broker/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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`

Expand Down
18 changes: 17 additions & 1 deletion pkg/kn/commands/broker/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 341d7bd

Please sign in to comment.