Skip to content

Adding validatable to bus types.#321

Merged
knative-prow-robot merged 7 commits into
knative:masterfrom
n3wscott:bus_validate
Aug 8, 2018
Merged

Adding validatable to bus types.#321
knative-prow-robot merged 7 commits into
knative:masterfrom
n3wscott:bus_validate

Conversation

@n3wscott
Copy link
Copy Markdown
Contributor

@n3wscott n3wscott commented Aug 3, 2018

This will be to support the webhook change.

@google-prow-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: n3wscott
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: mattmoor

If they are not already assigned, you can assign the PR to them by writing /assign @mattmoor in a comment when ready.

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

@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 3, 2018
@n3wscott
Copy link
Copy Markdown
Contributor Author

n3wscott commented Aug 3, 2018

Grant for LGTM:
/assign @grantr

Evan for Approval:
/assign @evankanderson

)

const (
longName = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
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.

You can use strings.Repeat to avoid having to type this out yourself, and so its self documenting as to its length.

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.

GREAT TIP!!

Copy link
Copy Markdown
Contributor

@scothis scothis left a comment

Choose a reason for hiding this comment

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

/lgtm

}

func (current *Bus) CheckImmutableFields(og apis.Immutable) *apis.FieldError {
// TODO(n3wscott): Anything to check?
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.

I'm not aware of any

}

func (current *ClusterBus) CheckImmutableFields(og apis.Immutable) *apis.FieldError {
// TODO(n3wscott): Anything to check?
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.

I'm not aware of any

@knative-prow-robot knative-prow-robot added lgtm Indicates that a PR is ready to be merged. and removed lgtm Indicates that a PR is ready to be merged. labels Aug 6, 2018
@scothis
Copy link
Copy Markdown
Contributor

scothis commented Aug 6, 2018

/lgtm

@knative-prow-robot knative-prow-robot added lgtm Indicates that a PR is ready to be merged. and removed lgtm Indicates that a PR is ready to be merged. labels Aug 6, 2018
@n3wscott
Copy link
Copy Markdown
Contributor Author

n3wscott commented Aug 7, 2018

bad merge of lock file... will fix when at real computer

@knative-prow-robot knative-prow-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 7, 2018

package v1alpha1

func (b *Bus) SetDefaults() {
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.

It's fine for these no-op methods to exist but I'd like to see a comment justifying their existence, otherwise someone will remove them unknowingly. Do we expect defaults to be added in the near future? Is this a demonstration of what's possible? A desire for consistency across all resource types? A need for all objects to implement the same interface?

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.

[n3wscott]: Note about #321 and other related Validatable stub PRs: This is staging work, the plan is another pass to bring up the test coverage, then remove unused after each type is stubbed.

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.

Makes sense. Can you add those words as a comment in this file? Just in case this work ends up taking longer than expected. 😸

return nil
}

func (current *Bus) CheckImmutableFields(og apis.Immutable) *apis.FieldError {
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.

Same as defaulters above. I'd like to see a comment justifying this method's no-op existence.

@scothis
Copy link
Copy Markdown
Contributor

scothis commented Aug 7, 2018

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 7, 2018
@n3wscott
Copy link
Copy Markdown
Contributor Author

n3wscott commented Aug 8, 2018

[n3wscott]: Note about #321 and other related Validatable stub PRs: This is staging work, the plan is another pass to bring up the test coverage, then remove unused after each type is stubbed.

@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 8, 2018
Copy link
Copy Markdown
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

/approve

BacksChannel(channel *Channel) bool
GetSpec() *BusSpec
apis.Validatable
apis.Immutable
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be apis.Defaultable as well (since you have an implementation)?

Alternately, since there appear to be no defaults, you might be able to get rid of the _defaults.go files.

},
},
},
want: nil,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You don't need to specify want here.

Subscription: &[]Parameter{
{
Name: "foo",
Description: "bar",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you want to check that empty description is valid
?

},
},
want: &apis.FieldError{
Message: fmt.Sprintf("invalid key name %q", longName),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice if you could supply a "matcher" object here.

},
Details: "must be no more than 253 characters",
},
}, {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you want to test any of:

  1. Multiple parameters to the same Bus.
  2. Two parameters with the same Name in the same list.
  3. Multiple errors in the same object.

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.

good thought, I added a todo to add those, this was just moving what tests existed.


for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := test.bs.Validate()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice if you could actually put these specs into both a Bus and a ClusterBus for testing (to ensure that both are hooked up correctly).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like the webhook tests actually do this right now, so I'm less concerned about this.

Comment thread pkg/webhook/bus.go
return err
}
if err := new.CheckImmutableFields(old); err != nil {
return err
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like we never call .SetDefaults() on new. Should we do that first, if it's going to be Defaultable? (Again, I question the value right now.)

@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: evankanderson, n3wscott

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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 8, 2018
@knative-metrics-robot
Copy link
Copy Markdown

The following is the coverage report on pkg/.
Say /test pull-knative-eventing-go-coverage to run the coverage report again

File Old Coverage New Coverage Delta
pkg/apis/channels/v1alpha1/bus_defaults.go Do not exist 0.0%
pkg/apis/channels/v1alpha1/bus_validation.go Do not exist 87.5%
pkg/apis/channels/v1alpha1/clusterbus_defaults.go Do not exist 0.0%
pkg/apis/channels/v1alpha1/bus_types.go Do not exist 0.0%
pkg/apis/channels/v1alpha1/clusterbus_validation.go Do not exist 0.0%
pkg/webhook/bus.go 77.4% 66.7% -10.8

@grantr
Copy link
Copy Markdown
Contributor

grantr commented Aug 8, 2018

/lgtm

Thanks @n3wscott!

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 8, 2018
@n3wscott
Copy link
Copy Markdown
Contributor Author

n3wscott commented Aug 8, 2018

/test pull-knative-eventing-integration-tests

/ISTIO

@knative-prow-robot knative-prow-robot merged commit 34ab480 into knative:master Aug 8, 2018
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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants