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

Allow for http and broker sinks #574

Merged
merged 8 commits into from
Dec 27, 2019
Merged

Conversation

sixolet
Copy link
Contributor

@sixolet sixolet commented Dec 18, 2019

Refactors sink code to use a dynamic client to validate the sink, so we don't keep having to write the same parallel code. Paves the way for arbitrary user-configured sinks.

Fixes #570

Also fixes most of #563 : missing arbitrary ns for sinks, but now has the sink as being in the same ns as the object being created.

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Dec 18, 2019
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 18, 2019
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.

@sixolet: 2 warnings.

In response to this:

Refactors sink code to use a dynamic client to validate the sink, so we don't keep having to write the same parallel code. Paves the way for arbitrary user-configured sinks.

Fixes #570

Also fixes most of #563 : missing arbitrary ns for sinks, but now has the sink as being in the same ns as the object being created.

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/flags/sink.go Show resolved Hide resolved
pkg/dynamic/client.go Outdated Show resolved Hide resolved
@sixolet sixolet requested review from daisy-ycguo and removed request for rhuss December 18, 2019 23:37
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 ! Looks good to me, with the usual nits :). We can merge it as it, however, I would maybe model the fake client a bit differently (see comments) to make it more the same like the mock interfaces.

As you mentioned, one remaining problem is how to specify the sink's namespace. IMO this could be either a dedicated option (--sink-namespace) or part of the sink specification, like in svc:mysvc:anotherns. not sure what I like better ;-)

pkg/kn/commands/trigger/create.go Outdated Show resolved Hide resolved
}

// CreateFakeKnDynamicClient gives you a dynamic client for testing contianing the given objects.
func CreateFakeKnDynamicClient(testNamespace string, objects ...runtime.Object) KnDynamicClient {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think having the same mocking scheme that we use for the other clients. Maybe not now, but later.

So something in the lines of

client := NewMockDynamicClient(namespace)
recorder := client.Recorder()
recorder.RegisterGVK(SERVING_GVK)
recorder.RegisterGVK(EVENTING_GVK)
recorder.AddObject(rtObject)
....

and then the RawClient() implementation would return a fake client based on the configuration stored in the recorder. Maybe one could also omit the schema recording steps and hardcode them in the recorder.

Would be only a small change but would make it easier to follow the tests as it then would follow the same scheme.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also this would decouple test and business code better if we put that method in a different file at least

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 have put the Fake helper method in a different package, even, because you're right it's nice to have test code decoupled from mainline code. On the other hand, I really like the mocking scheme here. Using it was refreshing and much nicer — I would much rather specify the objects in my "fake server" than specify every call to it.. I'll keep this mocking scheme. Might even look to use it in more places.

pkg/kn/commands/source/cronjob/update.go Show resolved Hide resolved
pkg/kn/commands/flags/sink_test.go Show resolved Hide resolved
pkg/kn/commands/source/apiserver/create.go Outdated Show resolved Hide resolved
@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/dynamic/client.go 90.9% 83.3% -7.6
pkg/kn/commands/flags/sink.go 0.0% 78.3% 78.3
pkg/kn/commands/source/cronjob/create.go 92.0% 89.3% -2.7
pkg/kn/commands/source/cronjob/update.go 75.8% 75.0% -0.8

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.

/lgtm

@@ -99,3 +99,13 @@ func TestListSourceTypes(t *testing.T) {
assert.Equal(t, uList.Items[1].GetName(), "bar")
})
}

// createFakeKnDynamicClient gives you a dynamic client for testing contianing the given objects.
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
// createFakeKnDynamicClient gives you a dynamic client for testing contianing the given objects.
// createFakeKnDynamicClient gives you a dynamic client for testing containing the given objects.

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: navidshaikh, 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:
  • OWNERS [navidshaikh,sixolet]

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 f1bfafe into knative:master Dec 27, 2019
coryrc pushed a commit to coryrc/client that referenced this pull request May 14, 2020
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow source creation with brokers
6 participants