Repository: knative/pkg
Pull request #2291 (2021-09-19 18:32:08)

[release-0.26] Source validation fixes
This is an automated cherry-pick of #2285

knative-prow-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/2291#" title="Author self-approved">knative-prow-robot</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **mattmoor** after the PR has been reviewed.
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](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

<details open>
Needs approval from an approver in each of these files:

- **[apis/duck/OWNERS](https://github.com/knative/pkg/blob/release-0.26/apis/duck/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["mattmoor"]} -->
google-cla[bot]: All (the pull request submitter and all commit authors) CLAs are signed, **but** one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project.  Please have them confirm that by leaving a comment that contains only `@googlebot I consent.` in this pull request.

*Note to project maintainer:* There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent.  In those cases, you can manually confirm consent of the commit author(s), and set the `cla` label to `yes` (if enabled on your project).

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Fknative%2Fpkg%2Fpull%2F2291) for more info**.

<!-- need_author_consent -->
mattmoor: /lgtm
/approve
knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/2291#" title="Author self-approved">knative-prow-robot</a>*, *<a href="https://github.com/knative/pkg/pull/2291#issuecomment-922517731" title="Approved">mattmoor</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[apis/duck/OWNERS](https://github.com/knative/pkg/blob/release-0.26/apis/duck/OWNERS)~~ [mattmoor]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
codecov[bot]: # [Codecov](https://codecov.io/gh/knative/pkg/pull/2291?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative) Report
> :exclamation: No coverage uploaded for pull request base (`release-0.26@a49a60e`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative#section-missing-base-commit).
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/knative/pkg/pull/2291/graphs/tree.svg?width=650&height=150&src=pr&token=rlqpDnfxbO&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative)](https://codecov.io/gh/knative/pkg/pull/2291?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative)

```diff
@@               Coverage Diff               @@
##             release-0.26    #2291   +/-   ##
===============================================
  Coverage                ?   64.46%           
===============================================
  Files                   ?      223           
  Lines                   ?     9599           
  Branches                ?        0           
===============================================
  Hits                    ?     6188           
  Misses                  ?     3139           
  Partials                ?      272           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/knative/pkg/pull/2291?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/knative/pkg/pull/2291?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative). Last update [a49a60e...9c8de9c](https://codecov.io/gh/knative/pkg/pull/2291?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative).

mattmoor: cc @knative/knative-release-leads 

We will need this for the release, it fixes a break updating eventing.  @ZhiminXiang in particular, we need a Googler to set the `cla: yes` label for Prow to merge this 😞 

It looks super red, but it's really just:
1. CLA (we need manual intervention)
2. Downstream test (doesn't know how to handle release branches before the downstream cuts are made, I filed: https://github.com/knative-sandbox/actions-downstream-test/issues/13)
3. codecov/project, which literally always fails 🙃 

The only blocking bit is `1.`


mattmoor: Also, @gabo1208 Can you consent per the above instructions?
gabo1208: @googlebot I consent

Patch:
diff --git a/apis/duck/v1/source_types.go b/apis/duck/v1/source_types.go
index 00e699156..5c5c030a1 100644
--- a/apis/duck/v1/source_types.go
+++ b/apis/duck/v1/source_types.go
@@ -180,6 +180,9 @@ func (s *Source) Validate(ctx context.Context) *apis.FieldError {
 }
 
 func (s *SourceSpec) Validate(ctx context.Context) *apis.FieldError {
+	if s.CloudEventOverrides == nil {
+		return nil
+	}
 	return s.CloudEventOverrides.Validate(ctx).ViaField("ceOverrides")
 }
 


Test patch:
diff --git a/apis/duck/v1/source_types_test.go b/apis/duck/v1/source_types_test.go
index 37dfb718c..8cbe38643 100644
--- a/apis/duck/v1/source_types_test.go
+++ b/apis/duck/v1/source_types_test.go
@@ -29,9 +29,17 @@ func TestSourceValidate(t *testing.T) {
 		src  *Source
 		want *apis.FieldError
 	}{{
-		name: "empty source validation",
+		name: "nil source validation",
 		src:  nil,
 		want: nil,
+	}, {
+		name: "nil source spec validation",
+		src:  &Source{},
+		want: nil,
+	}, {
+		name: "empty source spec validation",
+		src:  &Source{Spec: SourceSpec{}},
+		want: nil,
 	}, {
 		name: "empty source ceOverrides extensions validation",
 		src: &Source{Spec: SourceSpec{