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 command to create/delete a plain trigger #541

Merged
merged 1 commit into from
Dec 16, 2019

Conversation

daisy-ycguo
Copy link
Member

@daisy-ycguo daisy-ycguo commented Dec 9, 2019

Fixes #479

Proposed Changes

  • Add command for creation of a plain trigger
  • Add command for deletion of a trigger
  • Add command for description of a trigger

@knative-prow-robot knative-prow-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Dec 9, 2019
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Dec 9, 2019
@daisy-ycguo daisy-ycguo changed the title Add command for creation of a plain trigger [WIP] Add command for creation of a plain trigger Dec 9, 2019
@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 9, 2019
@daisy-ycguo daisy-ycguo changed the title [WIP] Add command for creation of a plain trigger [Add command for creation of a plain trigger Dec 11, 2019
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 11, 2019
@daisy-ycguo daisy-ycguo changed the title [Add command for creation of a plain trigger Add command for creation of a plain trigger Dec 11, 2019
@daisy-ycguo daisy-ycguo force-pushed the trigger branch 4 times, most recently from 887f4da to 2ea32d6 Compare December 11, 2019 15:38
@daisy-ycguo
Copy link
Member Author

/test pull-knative-client-integration-tests

@daisy-ycguo daisy-ycguo force-pushed the trigger branch 2 times, most recently from 18880c5 to 5bd6789 Compare December 12, 2019 09:28
@daisy-ycguo daisy-ycguo changed the title Add command for creation of a plain trigger Add command to create/delete a plain trigger Dec 12, 2019
@sixolet
Copy link
Contributor

sixolet commented Dec 12, 2019

/approve
/lgtm

@knative-prow-robot knative-prow-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 12, 2019
@sixolet
Copy link
Contributor

sixolet commented Dec 12, 2019

/retest

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.

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

### SEE ALSO

* [kn](kn.md) - Knative client
* [kn trigger create](kn_trigger_create.md) - Create a Trigger
Copy link
Contributor

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.

Copy link
Member Author

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,42 @@
## kn trigger create

Create a Trigger
Copy link
Contributor

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.

Copy link
Member Author

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)

Copy link
Member Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Spelling...

Copy link
Member Author

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)

Copy link
Member Author

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
Copy link
Contributor

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...

Copy link
Member Author

@daisy-ycguo daisy-ycguo Dec 13, 2019

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.


//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)
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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.

Copy link
Member Author

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 {
Copy link
Contributor

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

Copy link
Member Author

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 {
Copy link
Contributor

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

Copy link
Member Author

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 {
Copy link
Contributor

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...

Copy link
Member Author

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.

Copy link
Contributor

@rhuss rhuss Dec 13, 2019

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()

Copy link
Contributor

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.

Copy link
Contributor

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)

Copy link
Contributor

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{}
Copy link
Contributor

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.

Copy link
Member Author

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.

@daisy-ycguo
Copy link
Member Author

daisy-ycguo commented Dec 13, 2019

@maximilien Thank you for review. This pr has dependencies to

knative.dev/eventing/pkg/client/clientset/versioned/typed/eventing/v1alpha1
knative.dev/eventing/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake

All files under "vendor" folder are automatically added by the build and test scripts.
The files under "pkg" are added by me.

@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Dec 13, 2019
@daisy-ycguo daisy-ycguo force-pushed the trigger branch 3 times, most recently from 2173fa1 to 703def5 Compare December 13, 2019 11:17
@daisy-ycguo
Copy link
Member 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.

@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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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 {
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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.

// Ensure that the interface is implemented
var _ KnEventingClient = &MockKnEventingClient{}

// recorder for service
Copy link
Contributor

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.

return mock.ErrorOrNil(call.Result[0])
}

// Validates validates whether every recorded action has been called
Copy link
Contributor

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.

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, 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.

### Options

```
--broker string Name of the Broker which the trigger associates with. Defaults to 'default' if not specified. (default "default")
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

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

resolved.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed.


```
--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
Copy link
Contributor

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 ?

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


//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{})
Copy link
Contributor

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 ?

Copy link
Member Author

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{
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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")
Copy link
Contributor

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
}
Copy link
Contributor

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 {
Copy link
Contributor

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)

@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/v1alpha1/client.go Do not exist 92.9%
pkg/eventing/v1alpha1/client_mock.go Do not exist 87.5%
pkg/kn/commands/testing_helper.go 64.4% 54.3% -10.1
pkg/kn/commands/trigger/create.go Do not exist 86.1%
pkg/kn/commands/trigger/delete.go Do not exist 82.4%
pkg/kn/commands/trigger/describe.go Do not exist 83.3%
pkg/kn/commands/trigger/flag.go Do not exist 93.8%
pkg/kn/commands/trigger/trigger.go Do not exist 100.0%
pkg/kn/commands/types.go 62.2% 53.8% -8.4
pkg/kn/core/root.go 60.8% 61.2% 0.4

@daisy-ycguo
Copy link
Member Author

@maximilien @rhuss @sixolet This PR is ready for a second review.
Besides the minor changes, I

  • used multiple --filter to manage filter options
  • rewrote unit tests to use mock client

}

//CreateTrigger is used to create an instance of trigger
func (c *knEventingClient) CreateTrigger(trigger *v1alpha1.Trigger) (*v1alpha1.Trigger, error) {
Copy link
Contributor

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.

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.

/lgtm

Thanks !

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 16, 2019
@knative-prow-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot merged commit 7def9f4 into knative:master Dec 16, 2019
coryrc pushed a commit to coryrc/client that referenced this pull request May 14, 2020
… 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
dsimansk added a commit to dsimansk/client that referenced this pull request Nov 29, 2024
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.

kn trigger create
7 participants