-
Notifications
You must be signed in to change notification settings - Fork 263
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 command to create/delete a plain trigger #541
Conversation
887f4da
to
2ea32d6
Compare
/test pull-knative-client-integration-tests |
18880c5
to
5bd6789
Compare
/approve |
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I stopped at file 19. There are too many issues. Please address and I’ll take another look.
Also, use the /lint option to see many of these issues and address them before submitting PR
docs/cmd/kn_trigger.md
Outdated
### SEE ALSO | ||
|
||
* [kn](kn.md) - Knative client | ||
* [kn trigger create](kn_trigger_create.md) - Create a Trigger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is “trigger” spelled with capital T here? Be consistent with Delete and the rest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to lower case t in the whole PR (unless starting a sentence)
docs/cmd/kn_trigger_create.md
Outdated
@@ -0,0 +1,42 @@ | |||
## kn trigger create | |||
|
|||
Create a Trigger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistent spelling of Trigger or trigger (unless starting a sentence)... across all text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to lower case t
in the whole PR (unless starting a sentence)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to lower case t in the whole PR (unless starting a sentence)
@@ -0,0 +1,39 @@ | |||
## kn trigger delete | |||
|
|||
Delete a trigger. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to lower case t in the whole PR (unless starting a sentence)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to lower case t in the whole PR (unless starting a sentence)
// Temporarily help to add sources dependencies | ||
// May be changed when adding real sources features | ||
type knEventingClient struct { | ||
client client_v1alpha1.EventingV1alpha1Interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be consistent with creation in the order of the fields? It’s reverse here to the NewKnEventingClient
constructor...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the order of fields in NewKnEventingClient constructor to be consistent.
pkg/eventing/v1alpha1/client.go
Outdated
|
||
//CreateTrigger is used to create an instance of Trigger | ||
func (c *knEventingClient) CreateTrigger(trigger *v1alpha1.Trigger) (*v1alpha1.Trigger, error) { | ||
ins, err := c.client.Triggers(c.namespace).Create(trigger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: What does ins
mean? Why not call it trigger
or something descriptive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ins
means instance. :). I updated to use trigger
|
||
// BrokerInterface has methods to work with Broker resources. | ||
type BrokerInterface interface { | ||
Create(*v1alpha1.Broker) (*v1alpha1.Broker, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent use of comments. In previous interface you added comments for each method. Not here. IMO less comments is better since if name is well selected it’s clear. However, I also would agree to have comments for public interfaces and methods.
Either way be consistent and follow the rest of code. This is not being done here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's Eventing client dependency file, added by go mod
while building and testing.
restClient rest.Interface | ||
} | ||
|
||
func (c *EventingV1alpha1Client) Brokers(namespace string) BrokerInterface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public methods need comments or won’t pass the linter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's Eventing client dependency file, added by go mod
while building and testing.
// NewForConfig creates a new EventingV1alpha1Client for the given config. | ||
func NewForConfig(c *rest.Config) (*EventingV1alpha1Client, error) { | ||
config := *c | ||
if err := setConfigDefaults(&config); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don’t use this form. Extract the setCopnfigDefaults(&config)
outside of the if
since that’s consistent to the other line and most of this repo’s code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's Eventing client dependency file, added by go mod
while building and testing.
// RESTClient returns a RESTClient that is used to communicate | ||
// with API server by this client implementation. | ||
func (c *EventingV1alpha1Client) RESTClient() rest.Interface { | ||
if c == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would c == nil
be ever true?
If c
is nill
then an exception will be thrown before RESTClient()
be executed. So these three lines are dead code...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's Eventing client dependency file, added by go mod
while building and testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maximilien Of course can c
be nil. Try
EventingV1alphaClient(nil).RESTClient()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and as mentioned, its a dependeny added. It's also autogenerated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for this check is to allow chained called where an intermediate call returns nil like in
myServicHub.EventingClient().RESTClient()
and EventingClient()
return nil (but is of type *EventingV1alphaClient
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok but yuck... :)
|
||
// Get takes name of the eventType, and returns the corresponding eventType object, and an error if there is any. | ||
func (c *eventTypes) Get(name string, options v1.GetOptions) (result *v1alpha1.EventType, err error) { | ||
result = &v1alpha1.EventType{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again do not use named return args since it’s not consistent With rest of your code and this repo.
Future versions of Golang might remove this “feature” which is also another reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's Eventing client dependency file, added by go mod
while building and testing.
@maximilien Thank you for review. This pr has dependencies to
All files under "vendor" folder are automatically added by the build and test scripts. |
2173fa1
to
703def5
Compare
/lint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daisy-ycguo: 6 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.
) | ||
|
||
// TriggerUpdateFlags are flags for create and update a trigger | ||
type TriggerUpdateFlags struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type TriggerUpdateFlags struct { | |
type UpdateFlags struct { |
Golint naming: type name will be used as trigger.TriggerUpdateFlags by other packages, and that stutters; consider calling this UpdateFlags. More info.
duckv1 "knative.dev/pkg/apis/duck/v1" | ||
) | ||
|
||
func NewTriggerCreateCommand(p *commands.KnParams) *cobra.Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint comments: exported function NewTriggerCreateCommand should have comment or be unexported. More info.
"knative.dev/client/pkg/kn/commands" | ||
) | ||
|
||
func NewTriggerCommand(p *commands.KnParams) *cobra.Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint comments: exported function NewTriggerCommand should have comment or be unexported. More info.
"knative.dev/eventing/pkg/apis/eventing/v1alpha1" | ||
) | ||
|
||
type MockKnEventingClient struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint comments: exported type MockKnEventingClient should have comment or be unexported. More info.
pkg/eventing/v1alpha1/client_mock.go
Outdated
// Ensure that the interface is implemented | ||
var _ KnEventingClient = &MockKnEventingClient{} | ||
|
||
// recorder for service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint comments: comment on exported type EventingRecorder should be of the form "EventingRecorder ..." (with optional leading article). More info.
pkg/eventing/v1alpha1/client_mock.go
Outdated
return mock.ErrorOrNil(call.Result[0]) | ||
} | ||
|
||
// Validates validates whether every recorded action has been called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint comments: comment on exported method EventingRecorder.Validate should be of the form "Validate ...". More info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot, some comments see below.
In general we should use only Mock tests for the command tests. Also it woudl be awesome if you could reduce duplicated code in the tests to minimize the references to v1alpha1
structs, so that a later upgrade becomes easier.
docs/cmd/kn_trigger_create.md
Outdated
### Options | ||
|
||
``` | ||
--broker string Name of the Broker which the trigger associates with. Defaults to 'default' if not specified. (default "default") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could skip the explanation for 'default' as it is automatically added by cobra
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
docs/cmd/kn_trigger_create.md
Outdated
|
||
``` | ||
--broker string Name of the Broker which the trigger associates with. Defaults to 'default' if not specified. (default "default") | ||
--filter strings Comma seperate key-value pair for exact CloudEvent attribute matching against incoming events, e.g type=dev.knative.foo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I would prefer to allow multiple flter arguments instead of puttng everything tog gether into a single filter. E.g. what's about escaping for value that contain comma ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed to use multiple --filter
--filter strings Comma seperate key-value pair for exact CloudEvent attribute matching against incoming events, e.g type=dev.knative.foo | ||
-h, --help help for create | ||
-n, --namespace string Specify the namespace to operate in. | ||
-s, --sink string Addressable sink for events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should contain examples, like for sources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Examples are contained in line #13.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, describing the possible format (e.g. prefix :
name) and a reference to the list of possible prefixes. Lets keep it like now, going to make an overall check of all sources later.
) | ||
|
||
// MockKnEventingClient is a combine of test object and recorder | ||
type MockKnEventingClient struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
pkg/eventing/v1alpha1/client.go
Outdated
|
||
//GetTrigger is used to get an instance of trigger | ||
func (c *knEventingClient) GetTrigger(name string) (*v1alpha1.Trigger, error) { | ||
return c.client.Triggers(c.namespace).Get(name, apis_v1.GetOptions{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no error conversion here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added.
} | ||
|
||
//construct a wanted instance | ||
wanted := &v1alpha1.Trigger{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should put the duplicated code imo a method, parameterized with the stuff that changes. The more often you use v1alpha
objects directly the harder it will be to upgrade to a v1
version. Even in tests, we should avoid duplicated code as much as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
cmd, fakeEventing, buf := commands.CreateEventingTestKnCommand(NewTriggerCommand(knParams), knParams) | ||
fakeEventing.AddReactor("delete", "triggers", | ||
func(a client_testing.Action) (bool, runtime.Object, error) { | ||
deleteAction, _ := a.(client_testing.DeleteAction) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the test will panic anyway if its wrong.
//Add is to set parameters | ||
func (f *TriggerUpdateFlags) Add(cmd *cobra.Command) { | ||
cmd.Flags().StringVar(&f.Broker, "broker", "default", "Name of the Broker which the trigger associates with. Defaults to 'default' if not specified.") | ||
cmd.Flags().StringSliceVar(&f.Filter, "filter", nil, "Comma seperate key-value pair for exact CloudEvent attribute matching against incoming events, e.g type=dev.knative.foo") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we allow multiple --filter
options, with every option being a single filter. So singular is correct. However its inocrrect that you can use comma separated filters in one option, if I understand the code above correctly.
@@ -69,6 +72,10 @@ func (params *KnParams) Initialize() { | |||
params.NewSourcesClient = params.newSourcesClient | |||
} | |||
|
|||
if params.NewEventingClient == nil { | |||
params.NewEventingClient = params.newEventingClient | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This technique allows test code to hook in by setting the NewEventingClient
in advance before reaching this method with a fake implementation.
I'm also not happy with this construct (for other reasons, mostly because of coupling layers unnecessarily), but I'm happy to take this over as is (as its follows the same scheme like for the other clients).
In a subsequent PR we should refactor the client handling to be more delocalized maybe.
// RESTClient returns a RESTClient that is used to communicate | ||
// with API server by this client implementation. | ||
func (c *EventingV1alpha1Client) RESTClient() rest.Interface { | ||
if c == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for this check is to allow chained called where an intermediate call returns nil like in
myServicHub.EventingClient().RESTClient()
and EventingClient()
return nil (but is of type *EventingV1alphaClient
)
The following is the coverage report on the affected files.
|
@maximilien @rhuss @sixolet This PR is ready for a second review.
|
} | ||
|
||
//CreateTrigger is used to create an instance of trigger | ||
func (c *knEventingClient) CreateTrigger(trigger *v1alpha1.Trigger) (*v1alpha1.Trigger, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be in accordance with our other APIs, we should not return the created trigger here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Thanks !
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: daisy-ycguo, rhuss, sixolet 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 |
… flaky tests (knative#541) * initialize commit for Slack notification * slack notification * update based on PR comments * Update tools/flaky-test-reporter/slack_notification.go Co-Authored-By: chaodaiG <[email protected]> * Update tools/flaky-test-reporter/slack_notification.go Co-Authored-By: chaodaiG <[email protected]> * Update tools/flaky-test-reporter/slack_notification.go Co-Authored-By: chaodaiG <[email protected]> * updates for PR comments * updates for PR comments
Fixes #479
Proposed Changes