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

Add machine-readable output for broker #1124

Merged
merged 1 commit into from
Nov 18, 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
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()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arghya88 : lets fix this in the next update to of #1121 ?

}
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