Add validation for bus parameter names#165
Conversation
| @@ -0,0 +1,92 @@ | |||
| /* | |||
| * Copyright 2017 the original author or authors. | |||
There was a problem hiding this comment.
Use standard copyright header (x2)
There was a problem hiding this comment.
Damn, finally figured out that Goland doesn't honor the "Copyright" setting but has them directly embedded in the new Go file template.... :(
| }, | ||
| "ClusterBus": { | ||
| Factory: &v1alpha1.ClusterBus{}, | ||
| Validator: ValidateBus(ctx), |
There was a problem hiding this comment.
ValidateBus looks like it will only work for Bus and not ClusterBus. There is a GenericBus interface that is implemented by both bus types.
There was a problem hiding this comment.
Ah, correct.
BTW, why isn't ClusterBus a type alias of Bus?
There was a problem hiding this comment.
Bus and ClusterBus structs share a common spec, but are different types. The GenericBus interface has a method to get the spec, which you can then validate.
There was a problem hiding this comment.
I realize they're different (conceptual) types. But we leveraged type aliases for some of the parts that they share (Spec) but not the rest, hence my question
| expectFailsWith(t, ac.admit(testCtx, &req), "unhandled kind") | ||
| } | ||
|
|
||
| func TestInvalidBusParameterNameFails(t *testing.T) { |
There was a problem hiding this comment.
We should also have a test for a valid name that passes and tests with ClusterBus
|
|
||
| import ( | ||
| "context" | ||
|
|
There was a problem hiding this comment.
formatting here seems wonky. Could you (or did you and this is what it gave you?) run gofmt on this?
There was a problem hiding this comment.
I have gofmt set up to run automatically (and re-ran it manually to make sure). For some reason, new lines got added though (gofmt doesn't remove them). Fixing
| } | ||
| glog.Infof("%s: OLD Bus is\n%+v", fnName, oldBus) | ||
|
|
||
| newBus, ok := new.(v1alpha1.GenericBus) |
There was a problem hiding this comment.
Can new ever be nil? If not, perhaps add a check for it and return an error?
There was a problem hiding this comment.
Seems not (kubectl delete bus <foo> doesn't trigger the webhook).
Added a (safe) check nevertheless
|
Addressed review comments, rebased on master |
| glog.Infof("%s: OLD Bus is\n%+v", fnName, oldBus) | ||
|
|
||
| if new == nil { | ||
| return nil, nil, errInvalidBusInput |
There was a problem hiding this comment.
Since this should never happen, seems like this is an internal error of some sorts rather than a user input error? Thinking that perhaps a different error message is in order here?
There was a problem hiding this comment.
If we're that confident, we should panic :)
Changed for a dedicated error message
|
/assign scothis |
|
/lgtm |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ericbottard, vaikas-google The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
From [ROLES.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/ROLES.md#approver): > Reviewer of the codebase for at least 3 months or 50% of project lifetime, whichever is shorter - [First Issue](knative#80). Opened 6/11 - [First PR](knative#66). Opened 5/31 - [First Review](knative#79 (review)) 6/11 > Primary reviewer for at least 10 substantial PRs to the codebase - knative#422 (review) - knative#414 (review) - knative#325 (review) - knative#225 (review) - knative#189 (review) - knative#168 (review) - knative#165 (review) - knative#99 (review) - knative#79 (review) - knative#111 (review) > Reviewed or merged at least 30 PRs to the codebase - [Reviewed 23 PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+reviewed-by%3Ascothis) - [Authored 34 merged PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+author%3Ascothis+is%3Amerged) - [Authored 5 open PRs](https://github.com/knative/eventing/pulls/scothis) > Nominated by an area lead From [WORKING_GROUPS.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/WORKING-GROUPS.md#events) /assign @vaikas-google > With no objections from other leads 🤞 /cc @evankanderson @grantr @inlined @mattmoor
From [ROLES.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/ROLES.md#approver): > Reviewer of the codebase for at least 3 months or 50% of project lifetime, whichever is shorter - [First Issue](#80). Opened 6/11 - [First PR](#66). Opened 5/31 - [First Review](#79 (review)) 6/11 > Primary reviewer for at least 10 substantial PRs to the codebase - #422 (review) - #414 (review) - #325 (review) - #225 (review) - #189 (review) - #168 (review) - #165 (review) - #99 (review) - #79 (review) - #111 (review) > Reviewed or merged at least 30 PRs to the codebase - [Reviewed 23 PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+reviewed-by%3Ascothis) - [Authored 34 merged PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+author%3Ascothis+is%3Amerged) - [Authored 5 open PRs](https://github.com/knative/eventing/pulls/scothis) > Nominated by an area lead From [WORKING_GROUPS.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/WORKING-GROUPS.md#events) /assign @vaikas-google > With no objections from other leads 🤞 /cc @evankanderson @grantr @inlined @mattmoor
From [ROLES.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/ROLES.md#approver): > Reviewer of the codebase for at least 3 months or 50% of project lifetime, whichever is shorter - [First Issue](knative#80). Opened 6/11 - [First PR](knative#66). Opened 5/31 - [First Review](knative#79 (review)) 6/11 > Primary reviewer for at least 10 substantial PRs to the codebase - knative#422 (review) - knative#414 (review) - knative#325 (review) - knative#225 (review) - knative#189 (review) - knative#168 (review) - knative#165 (review) - knative#99 (review) - knative#79 (review) - knative#111 (review) > Reviewed or merged at least 30 PRs to the codebase - [Reviewed 23 PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+reviewed-by%3Ascothis) - [Authored 34 merged PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+author%3Ascothis+is%3Amerged) - [Authored 5 open PRs](https://github.com/knative/eventing/pulls/scothis) > Nominated by an area lead From [WORKING_GROUPS.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/WORKING-GROUPS.md#events) /assign @vaikas-google > With no objections from other leads 🤞 /cc @evankanderson @grantr @inlined @mattmoor
release creation prep work
Fixes #144