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 broker create, delete and list cmds #894

Merged
merged 24 commits into from
Jun 23, 2020

Conversation

dsimansk
Copy link
Contributor

@dsimansk dsimansk commented Jun 19, 2020

Description

Since the Eventing 0.15 multitenant broker is the new default. MT Broker is easier to manage from user's namespace because there're no more requirements for additional permission as majority of broker deployment is installed in knative-eventing namespace. This PR adds commands to manage broker CR.

Changes

  • Add broker create, broker delete, broker list commands

Note 1: E2E are missing right now, I'm currently working on them.

Note 2: I haven't added update operation since the current impl only creates Broker CR with a name without additional specs.

Reference

Fixes #

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jun 19, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@dsimansk: 8 warnings.

In response to this:

Description

Since the Eventing 0.15 multitenant broker is the new default. This PR adds commands to manage broker CR.

Changes

  • Add broker create, broker delete, broker list commands

Note 1: E2E are missing right now, I'm currently working on them.

Note 2: I haven't added update operation since the current impl only creates Broker CR with a name without additional specs.

Reference

Fixes #

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

pkg/kn/commands/broker/create.go Outdated Show resolved Hide resolved
pkg/kn/commands/broker/create.go Show resolved Hide resolved
pkg/kn/commands/broker/broker.go Show resolved Hide resolved
pkg/kn/commands/broker/list.go Outdated Show resolved Hide resolved
pkg/kn/commands/broker/list.go Show resolved Hide resolved
pkg/kn/commands/broker/list.go Outdated Show resolved Hide resolved
pkg/kn/commands/broker/delete.go Outdated Show resolved Hide resolved
pkg/kn/commands/broker/delete.go Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jun 19, 2020
Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

Thanks a lot, looks good so far.

The only bigger question is, whether we should allow a default value for the name. As mentioned in the comments, it is is very unlikely that the user is using multiple brokers ever, then allowing a kn broker create for creating the default broker makes much sense (much like kn trigger create --inject-broker also only creates the default broker).

What are your opinions on this ? // cc: @maximilien @daisy-ycguo @navidshaikh @duglin

Create a broker.

```
kn broker create NAME
Copy link
Contributor

Choose a reason for hiding this comment

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

As there is a good default for a broker (named 'default') I wonder whether we can make the name optional for all broker commands.

That would help in creating a default broker like the injection would do

kn broker create
Broker 'default' is created

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd go for requiring the name explicitly as arg for create. Keeping create formula consistent with other resources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've decided to keep create consistent with the rest of resource creation flow, but I've had those thoughts myself that "default" might be worth. However, we can consider "default" to be exclusive for annotation created broker, therefore keeping name argument required here.

pkg/eventing/v1beta1/client.go Show resolved Hide resolved
pkg/kn/commands/broker/broker.go Show resolved Hide resolved
pkg/kn/commands/broker/broker_test.go Show resolved Hide resolved
pkg/kn/commands/broker/create.go Outdated Show resolved Hide resolved
if len(args) != 1 {
return errors.New("'broker create' requires the broker name given as single argument")
}
name := args[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

we might defaullt to "default" here, but I leave this open for discussion.

pkg/kn/commands/broker/delete.go Outdated Show resolved Hide resolved
if len(args) != 1 {
return errors.New("'broker delete' requires the broker name given as single argument")
}
name := args[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Here I'm less sure whether we should default to "default", as this could lead to an accidental deletion of a broker.

It really depends how likely the use case to have multiple brokers in a namespace is. If 95% of all usescases only use the default broker, then having a default value is helpful as this supports the user (who might not even now that he can have more than one broker).

pkg/kn/commands/broker/list.go Outdated Show resolved Hide resolved
pkg/kn/root/root.go Outdated Show resolved Hide resolved
dsimansk and others added 3 commits June 19, 2020 12:05
Co-authored-by: Roland Huß <rhuss@redhat.com>
Co-authored-by: Roland Huß <rhuss@redhat.com>
Co-authored-by: Roland Huß <rhuss@redhat.com>
@navidshaikh navidshaikh added this to the v0.16.0 milestone Jun 19, 2020
@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 19, 2020
@dsimansk
Copy link
Contributor Author

/lint

Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@dsimansk: 1 unresolved warnings and 1 new warnings.

In response to this:

/lint

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

pkg/kn/commands/broker/list.go Show resolved Hide resolved
Copy link
Contributor

@maximilien maximilien left a comment

Choose a reason for hiding this comment

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

Some small issues but one "bigger" one in lack of testing in describe command.

Overall, nice work. Thanks for contribution.

pkg/eventing/v1beta1/client.go Show resolved Hide resolved
}

// GetBroker records a call for GetBroker with the expected object or error. Either trigger or err should be nil
func (sr *EventingRecorder) GetBroker(name interface{}, broker *v1beta1.Broker, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why name the interface{} parameter name here but broker in line 118?

Copy link
Contributor

Choose a reason for hiding this comment

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

In 118 it is supposed to be a Broker object normally (but is in an interface{} due to the way the mocking works with expectactions), but here its the name of a Broke (a string normally, again an interface to allow setting expectatiions like Any() ...)

I think its totally fine to mimic the names of the interface here.

}

// DeleteBroker records a call for DeleteBroker with the expected error (nil if none)
func (sr *EventingRecorder) DeleteBroker(name interface{}, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as before?

Copy link
Contributor

Choose a reason for hiding this comment

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

see response above, the wording should reflect the wording of the interface.

"knative.dev/client/pkg/util"
)

func TestBrokerDescribe(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Test is not complete... I can comment out following and still pass the test:

// describeBroker print broker details to the provided output writer
func describeBroker(out io.Writer, broker *v1beta1.Broker, printDetails bool) error {
	dw := printers.NewPrefixWriter(out)
	commands.WriteMetadata(dw, &broker.ObjectMeta, printDetails)
	// dw.WriteLine()
	dw.WriteAttribute("Address", "").WriteAttribute("URL", broker.Status.Address.URL.String())
	// dw.WriteLine()
	// commands.WriteConditions(dw, broker.Status.Conditions, printDetails)
	if err := dw.Flush(); err != nil {
		return err
	}
	return nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 25ec5bd, let me know if the test's acceptable now.

@dsimansk
Copy link
Contributor Author

/retest

brokerCreate(r, "foo2")
verifyBrokerList(r, "foo2")
brokerDelete(r, "foo2")
verifyBrokerNotfound(r, "foo2")
Copy link
Collaborator

Choose a reason for hiding this comment

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

@dsimansk : seems like the e2e failure

    TestBroker: result_collector.go:84: ERROR: Error expected but no error happened

log

is the scenario where the resource being deleted is described before delete completes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per our chat discussion, there seems to be race condition between actual completion of broker delete operation out verifyBrokerNotfound. I've addes sync delete in commit e7b5261. Lets see if it helps.

@navidshaikh
Copy link
Collaborator

/retest

Copy link
Collaborator

@navidshaikh navidshaikh left a comment

Choose a reason for hiding this comment

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

suggested a few nits

pkg/kn/commands/broker/describe.go Outdated Show resolved Hide resolved
pkg/eventing/v1beta1/client.go Outdated Show resolved Hide resolved
pkg/kn/commands/broker/describe.go Outdated Show resolved Hide resolved
pkg/kn/commands/broker/list.go Outdated Show resolved Hide resolved
dsimansk and others added 5 commits June 22, 2020 13:22
Co-authored-by: Navid Shaikh <nshaikh@redhat.com>
Co-authored-by: Navid Shaikh <nshaikh@redhat.com>
Co-authored-by: Navid Shaikh <nshaikh@redhat.com>
Co-authored-by: Navid Shaikh <nshaikh@redhat.com>
@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/eventing/v1beta1/client.go 83.1% 87.4% 4.3
pkg/eventing/v1beta1/client_mock.go 90.9% 94.1% 3.2
pkg/kn/commands/broker/broker.go Do not exist 100.0%
pkg/kn/commands/broker/create.go Do not exist 83.3%
pkg/kn/commands/broker/delete.go Do not exist 81.8%
pkg/kn/commands/broker/describe.go Do not exist 84.0%
pkg/kn/commands/broker/list.go Do not exist 88.6%

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

I agree now that we should require an explicit name and no implicit "default". If we ever change our minds we can change to a default "default" broker in a backwards-compatible way later. But not vice versa.

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dsimansk, rhuss

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 23, 2020
kn broker create mybroker --namespace myproject
`
# Delete a broker 'mybroker' in the 'myproject' namespace
kn broker create mybroker --namespace myproject`
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@rhuss
Copy link
Contributor

rhuss commented Jun 23, 2020

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 23, 2020
@knative-prow-robot knative-prow-robot merged commit 1f59f53 into knative:master Jun 23, 2020
@dsimansk dsimansk deleted the broker-crud branch June 23, 2020 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants