Skip to content

Add validation for bus parameter names#165

Merged
google-prow-robot merged 4 commits into
knative:masterfrom
ericbottard:issue_144
Jul 17, 2018
Merged

Add validation for bus parameter names#165
google-prow-robot merged 4 commits into
knative:masterfrom
ericbottard:issue_144

Conversation

@ericbottard
Copy link
Copy Markdown
Contributor

Fixes #144

@google-prow-robot google-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 10, 2018
Comment thread pkg/webhook/bus.go Outdated
@@ -0,0 +1,92 @@
/*
* Copyright 2017 the original author or authors.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use standard copyright header (x2)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Damn, finally figured out that Goland doesn't honor the "Copyright" setting but has them directly embedded in the new Go file template.... :(

Comment thread pkg/webhook/webhook.go
},
"ClusterBus": {
Factory: &v1alpha1.ClusterBus{},
Validator: ValidateBus(ctx),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ValidateBus looks like it will only work for Bus and not ClusterBus. There is a GenericBus interface that is implemented by both bus types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, correct.

BTW, why isn't ClusterBus a type alias of Bus?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

We should also have a test for a valid name that passes and tests with ClusterBus

Comment thread pkg/webhook/bus.go Outdated

import (
"context"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

formatting here seems wonky. Could you (or did you and this is what it gave you?) run gofmt on this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Comment thread pkg/webhook/bus.go
}
glog.Infof("%s: OLD Bus is\n%+v", fnName, oldBus)

newBus, ok := new.(v1alpha1.GenericBus)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can new ever be nil? If not, perhaps add a check for it and return an error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Seems not (kubectl delete bus <foo> doesn't trigger the webhook).
Added a (safe) check nevertheless

@ericbottard
Copy link
Copy Markdown
Contributor Author

Addressed review comments, rebased on master

Comment thread pkg/webhook/bus.go Outdated
glog.Infof("%s: OLD Bus is\n%+v", fnName, oldBus)

if new == nil {
return nil, nil, errInvalidBusInput
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we're that confident, we should panic :)

Changed for a dedicated error message

@evankanderson
Copy link
Copy Markdown
Member

/assign scothis
/assign @vaikas-google

@scothis
Copy link
Copy Markdown
Contributor

scothis commented Jul 17, 2018

/lgtm

@google-prow-robot google-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 17, 2018
@vaikas
Copy link
Copy Markdown
Contributor

vaikas commented Jul 17, 2018

/lgtm
/approve

@google-prow-robot
Copy link
Copy Markdown

[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

Details 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

@google-prow-robot google-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 17, 2018
@google-prow-robot google-prow-robot merged commit 38ed55d into knative:master Jul 17, 2018
scothis added a commit to scothis/eventing that referenced this pull request Sep 11, 2018
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
knative-prow-robot pushed a commit that referenced this pull request Sep 12, 2018
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
matzew pushed a commit to matzew/eventing that referenced this pull request Apr 11, 2019
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
matzew pushed a commit to matzew/eventing that referenced this pull request Jul 1, 2019
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. 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.

5 participants