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

Ce overrides validation #5730

Merged
merged 10 commits into from
Sep 17, 2021

Conversation

gabo1208
Copy link
Member

@gabo1208 gabo1208 commented Sep 14, 2021

Fixes #5638

Release Note

Validate CloudEvent overrides as defined by the CloudEvent spec.

@google-cla google-cla bot added the cla: yes Indicates the PR's author has signed the CLA. label Sep 14, 2021
@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Sep 14, 2021
@gabo1208 gabo1208 force-pushed the ceOverrides-validation branch from aa3f1f2 to b3903cd Compare September 15, 2021 19:53
@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 15, 2021
@codecov
Copy link

codecov bot commented Sep 15, 2021

Codecov Report

Merging #5730 (c9e3156) into main (cf630ed) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5730      +/-   ##
==========================================
- Coverage   82.68%   82.65%   -0.03%     
==========================================
  Files         200      202       +2     
  Lines        6261     6326      +65     
==========================================
+ Hits         5177     5229      +52     
- Misses        750      758       +8     
- Partials      334      339       +5     
Impacted Files Coverage Δ
pkg/apis/sources/v1/apiserver_validation.go 100.00% <100.00%> (ø)
pkg/apis/sources/v1/container_validation.go 83.33% <100.00%> (+0.98%) ⬆️
pkg/apis/sources/v1/ping_validation.go 100.00% <100.00%> (ø)
pkg/apis/sources/v1/sinkbinding_validation.go 100.00% <100.00%> (ø)
pkg/apis/sources/v1beta2/ping_validation.go 100.00% <100.00%> (ø)
pkg/channel/attributes/knative_error.go 100.00% <0.00%> (ø)
pkg/resolver/addressable_resolver.go 100.00% <0.00%> (ø)
pkg/resolver/mapping_resolver.go 72.91% <0.00%> (ø)
pkg/channel/message_dispatcher.go 79.03% <0.00%> (+0.51%) ⬆️
pkg/reconciler/pingsource/controller.go 87.87% <0.00%> (+2.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf630ed...c9e3156. Read the comment docs.

@gabo1208

This comment has been minimized.

@@ -94,6 +94,7 @@ func (cs *PingSourceSpec) Validate(ctx context.Context) *apis.FieldError {
}
}
}
errs = errs.Also(cs.SourceSpec.Validate(ctx))
Copy link
Member

Choose a reason for hiding this comment

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

Can we do this for all other sources as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, but, I don't know exactly where that should be. If you can give me a hand with this :)

Copy link
Member

Choose a reason for hiding this comment

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

Sure, we need to go through every file in pkg/apis/sources/<version>/*_validation.go, and check if the embedded SourceSpec is validated, if not then we add the same check that you added for the PingSource (line 97).

For example, for ApiServerSource, we don't validate SourceSpec [1], so we need to add the check errs = errs.Also(cs.SourceSpec.Validate(ctx)) here

Also, if we can add simple unit tests for each source to prevent regression that would be great too.

Hope this helps, thanks!

[1]

func (cs *ApiServerSourceSpec) Validate(ctx context.Context) *apis.FieldError {
var errs *apis.FieldError
// Validate mode, if can be empty or set as certain value
switch cs.EventMode {
case ReferenceMode, ResourceMode:
// EventMode is valid.
default:
errs = errs.Also(apis.ErrInvalidValue(cs.EventMode, "mode"))
}
// Validate sink
errs = errs.Also(cs.Sink.Validate(ctx).ViaField("sink"))
if len(cs.Resources) == 0 {
errs = errs.Also(apis.ErrMissingField("resources"))
}
for i, res := range cs.Resources {
_, err := schema.ParseGroupVersion(res.APIVersion)
if err != nil {
errs = errs.Also(apis.ErrInvalidValue(res.APIVersion, "apiVersion").ViaFieldIndex("resources", i))
}
if strings.TrimSpace(res.Kind) == "" {
errs = errs.Also(apis.ErrMissingField("kind").ViaFieldIndex("resources", i))
}
}
if cs.ResourceOwner != nil {
_, err := schema.ParseGroupVersion(cs.ResourceOwner.APIVersion)
if err != nil {
errs = errs.Also(apis.ErrInvalidValue(cs.ResourceOwner.APIVersion, "apiVersion").ViaField("owner"))
}
if strings.TrimSpace(cs.ResourceOwner.Kind) == "" {
errs = errs.Also(apis.ErrMissingField("kind").ViaField("owner"))
}
}
return errs
}

logs-conf.log Outdated
@@ -0,0 +1,10295 @@
=== RUN TestChannelAddressableResolverClusterRoleTest
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this.

@knative-prow-robot knative-prow-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 16, 2021
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 17, 2021
@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-eventing-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/sources/v1/container_validation.go 88.2% 88.9% 0.7

@gabo1208
Copy link
Member Author

/retest

@gabo1208 gabo1208 requested a review from pierDipi September 17, 2021 01:42
Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

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

Thanks!

Can you add a release note in the PR body?
There is an example in the PR template in the .github folder.

/lgtm
/approve
/kind bug

@knative-prow-robot knative-prow-robot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 17, 2021
@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 17, 2021
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gabo1208, pierDipi

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 17, 2021
@knative-prow-robot knative-prow-robot merged commit 24d102d into knative:main Sep 17, 2021
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. kind/bug Categorizes issue or PR as related to a bug. 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.

ceOverrides extensions are not validated
4 participants