Skip to content

Add more defaulting and validation for DomainMapping - #9915

Merged
knative-prow-robot merged 8 commits into
knative:masterfrom
julz:domainmappingmoardefaults
Oct 22, 2020
Merged

knative-prow-robot merged 8 commits into
knative:masterfrom
julz:domainmappingmoardefaults

Conversation

@julz

@julz julz commented Oct 22, 2020

Copy link
Copy Markdown
Contributor

Part 700ish of #9713.

Adds more validation and defaulting. Now:

  • uses pkg for kreference validation/defaulting
  • sets and validates lastModifier/creator annotations
  • adds some defensive validation that kind and apiVersion are set to the only currently-allowed values, for now.
  • checks ref name/namespace are valid since we rely on them when constructing the rewriteHost host etc.

This is probably a bit big, but it's mostly test boilerplate. I'd very happily split out some smaller PRs if anyone feels it's too painful to review, though.

/assign @mattmoor @dprotaso

@google-cla google-cla Bot added the cla: yes Indicates the PR's author has signed the CLA. label Oct 22, 2020
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/API API objects and controllers area/test-and-release It flags unit/e2e/conformance/perf test issues for product features labels Oct 22, 2020
@codecov

codecov Bot commented Oct 22, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #9915 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9915      +/-   ##
==========================================
+ Coverage   87.79%   87.82%   +0.02%     
==========================================
  Files         183      183              
  Lines        8613     8630      +17     
==========================================
+ Hits         7562     7579      +17     
  Misses        802      802              
  Partials      249      249              
Impacted Files Coverage Δ
...kg/apis/serving/v1alpha1/domainmapping_defaults.go 100.00% <100.00%> (ø)
.../apis/serving/v1alpha1/domainmapping_validation.go 100.00% <100.00%> (ø)
pkg/autoscaler/metrics/collector.go 98.55% <100.00%> (+0.04%) ⬆️
pkg/reconciler/configuration/configuration.go 86.71% <0.00%> (-1.57%) ⬇️
pkg/reconciler/autoscaling/kpa/scaler.go 90.00% <0.00%> (+1.42%) ⬆️

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 dbbf6fe...3f70c79. Read the comment docs.

if ref.Name == "" {
// validateMetadata validates the metadata section of a DomainMapping.
func (dm *DomainMapping) validateMetadata(ctx context.Context) (errs *apis.FieldError) {
if dm.Name == "" {

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 this even in theory be empty?

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.

yeah, it can be empty if GenerateName is passed, but actually it'd be way clearer to check that instead of checking name isn't empty: fixed.


// For now, ref must be a serving.knative.dev/v1 Service.
if spec.Ref.Kind != "Service" {
errs = errs.Also(apis.ErrGeneric(`must be "Service"`, "ref.kind"))

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.

Via("kind") of sorts?

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.

think the final argument does this already

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.

Well ref is already part of the parent error. I'd just do errs.Also(errs.ViaField()...) or along those lines :)

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 think this is fine as-is. 🤷

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.

you mean like errs = errs.Also(apis.ErrGeneric('must be "Service"', "kind").ViaField("ref"))? Can do, seems to be a bit wordier without much benefit - or are you thinking of something else?

@vagababov vagababov Oct 22, 2020 •

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.

Yeah, it's just that "ref.kind" is internal knowledge to how field error constructs field paths.
Tomorrow when it's "/" separated this will be a bug. Otherwise, it's fine.

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 worried about a switch to XPath 😉

@julz julz mentioned this pull request Oct 22, 2020
13 of 14 tasks
@mattmoor

Copy link
Copy Markdown
Contributor

just the one thing, otherwise LGTM. thanks for the validation improvements.

@mattmoor mattmoor left a comment

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.

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 22, 2020
@knative-prow-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: julz, mattmoor

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 Oct 22, 2020
@knative-prow-robot
knative-prow-robot merged commit e5987bd into knative:master Oct 22, 2020
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. area/API API objects and controllers area/test-and-release It flags unit/e2e/conformance/perf test issues for product features cla: yes Indicates the PR's author has signed the CLA. 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