Skip to content

Strengthen our resource name validation.#3019

Merged
knative-prow-robot merged 1 commit intoknative:masterfrom
mattmoor:dns-1035-names
Jan 29, 2019
Merged

Strengthen our resource name validation.#3019
knative-prow-robot merged 1 commit intoknative:masterfrom
mattmoor:dns-1035-names

Conversation

@mattmoor
Copy link
Copy Markdown
Member

This strengthen's our resource name validation to include DNS-1035 checks, which match the underlying Kubernetes resources that we create.

Fixes: #2942

@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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 Jan 29, 2019
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 29, 2019
Copy link
Copy Markdown
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@mattmoor: 0 warnings.

Details

In response to this:

This strengthen's our resource name validation to include DNS-1035 checks, which match the underlying Kubernetes resources that we create.

Fixes: #2942

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@mattmoor mattmoor added this to the Serving 0.4 milestone Jan 29, 2019
want: (&apis.FieldError{Message: "Invalid resource name: special character . must not be present", Paths: []string{"metadata.name"}}).
Also(apis.ErrMissingField("spec")),
want: (&apis.FieldError{
Message: "not a DNS 1035 label: [a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')]",
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.

Something like test/util.go:Error1035 = ...?
When k8s changes this string, it'll be a single place to change.

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 for the length.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That actually creates an import cycle, and I'm not sure of a good place to put it that could also be shared by autoscaling (we could share it across pkg/apis/serving/v1alpha1 via a private variable).

name := meta.GetName()

if strings.Contains(name, ".") {
msgs := validation.IsDNS1035Label(name)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What is the experience mutating an existing object that satisfied the old regex, but breaks the new one? Does it only error if the change touches the metadata, or will it error if anything on the object changes?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

you cannot change name

r: &Revision{},
r: &Revision{
ObjectMeta: metav1.ObjectMeta{
Name: "valid",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this now required for this test to work, or is this just filling in some forgotten boilerplate on the test table?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, the K8s function rejects empty names, so the validation before was overly weak.

Message: "not a DNS 1035 label: [must be no more than 63 characters]",
Paths: []string{"metadata.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.

do you want a test with both error conditions?
Also you can use validation.go:MaxLenError to generate check string.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not really :)

I don't think we need 100% path coverage of a (hopefully) well exercised library.

I can add it if you feel strongly (assuming you don't want ~5 versions of that same test).

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.

FWIW, you can collapse 2 tests into 1 :-)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done for Revision.

This strengthen's our resource name validation to include DNS-1035 checks, which match the underlying Kubernetes resources that we create.

Fixes: knative#2942
@mattmoor
Copy link
Copy Markdown
Member Author

/retest

Copy link
Copy Markdown
Contributor

@vagababov vagababov left a comment

Choose a reason for hiding this comment

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

/lgtm
/hold for dan to approve.

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 29, 2019
@markusthoemmes
Copy link
Copy Markdown
Contributor

/hold

to actually hold

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 29, 2019
@dgerd
Copy link
Copy Markdown

dgerd commented Jan 29, 2019

/lgtm
/hold cancel

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 29, 2019
@knative-prow-robot knative-prow-robot merged commit 580b5cc into knative:master Jan 29, 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