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

Allow dot character in resource names #3893

Merged
merged 1 commit into from
Apr 23, 2021
Merged

Conversation

psschwei
Copy link
Contributor

@psschwei psschwei commented Apr 19, 2021

Changes

Fixes #3891 to allow dot (.) characters in resource names.

The basic approach here was to update pkg/apis/validate/metadata.go so that it checks if Tekton resource names meet the criteria of DNS Subdomain names (. is a valid character in a DNS subdomain). It does this by using the IsDNS1123Subdomain() function from k8s.io/apimachinery/pkg/util/validation.

There had previously been a 63 character limit on resource names that, to my understanding, was put in place due to the fact that Tekton pod names are composed based on pipelineRun + pipeline + pipelineTask. For reference, a DNS subdomain can be up to 253 characters in length.

Some updates were made to the tests as well:

  • tests that checked for failure if a . was found in the resource name were updated to instead check for a comma
  • several tests used camelCase in the metadata.name field -- capital letters are not valid for metadata.name, and the new validation method will throw errors on any resource name in camelCase. I've updated the tests to use all lowercase letters for resource names. As this PR has been steadily increasing in size, I'll add new tests for camelCase in a separate PR
  • examples/v1beta1/pipelineruns/pipelinerun.yaml was updated to include resource names with a . in it, in order to catch any future issues that may arise with resource names containing a .

/kind feature

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

Release Notes

Allow resource names to contain the dot character (".") 
Resource names now validated using the common `validation.IsDNS1123Subdomain()` function

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. labels Apr 19, 2021
@tekton-robot tekton-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 19, 2021
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/validate/metadata.go 83.3% 75.0% -8.3

@tekton-robot tekton-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 19, 2021
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/condition_validation.go 90.0% 80.0% -10.0
pkg/apis/validate/metadata.go 83.3% 75.0% -8.3

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/condition_validation.go 90.0% 80.0% -10.0
pkg/apis/validate/metadata.go 83.3% 75.0% -8.3

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/condition_validation.go 90.0% 80.0% -10.0
pkg/apis/validate/metadata.go 83.3% 75.0% -8.3

@tekton-robot tekton-robot added 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 Apr 19, 2021
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/condition_validation.go 90.0% 80.0% -10.0
pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go 95.5% 90.9% -4.5
pkg/apis/pipeline/v1alpha1/run_validation.go 93.8% 87.5% -6.2
pkg/apis/pipeline/v1alpha1/taskrun_validation.go 89.8% 88.1% -1.7
pkg/apis/validate/metadata.go 83.3% 75.0% -8.3

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/condition_validation.go 90.0% 80.0% -10.0
pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go 95.5% 90.9% -4.5
pkg/apis/pipeline/v1alpha1/run_validation.go 93.8% 87.5% -6.2
pkg/apis/pipeline/v1alpha1/taskrun_validation.go 89.8% 88.1% -1.7
pkg/apis/validate/metadata.go 83.3% 75.0% -8.3

@pritidesai
Copy link
Member

@imjasonh after dropping the restriction for a dot character, the metadata_validation.go would have a single check validating the length of the resource name. Is there any more validation needed here or should the length validation be part of metadata_validation.go?

@imjasonh
Copy link
Member

@imjasonh after dropping the restriction for a dot character, the metadata_validation.go would have a single check validating the length of the resource name. Is there any more validation needed here or should the length validation be part of metadata_validation.go?

Keeping it in a shared function seems useful, just to document what validation means right now. I don't feel that strongly though.

@ghost
Copy link

ghost commented Apr 20, 2021

Could I request we also add an example yaml in examples/v1beta1/pipelineruns that includes a task with the new name format and a pipeline with the new name format, referenced by taskRef and pipelineRef? This way we're exercising the new naming format end-to-end and if we accidentally break taskRef pointing to names with "." in future we'd catch it early.

@afrittoli
Copy link
Member

Could I request we also add an example yaml in examples/v1beta1/pipelineruns that includes a task with the new name format and a pipeline with the new name format, referenced by taskRef and pipelineRef? This way we're exercising the new naming format end-to-end and if we accidentally break taskRef pointing to names with "." in future we'd catch it early.

Good idea!
Would it be acceptable to use the dot in the name of some existing example, to avoid adding an entire new E2E tests for testing this alone?

@psschwei
Copy link
Contributor Author

I can do either option (add a new example or edit an existing one)... if we go with the latter, would the main pipelinerun.yaml one be a suitable candidate? Thinking I would update to use unit.tests task and demo.pipeline pipeline...

@ghost
Copy link

ghost commented Apr 20, 2021

Absolutely, updating an existing one to use the format sounds good to me too.

Edit: the main pipelinerun.yaml would work great for this.

@psschwei
Copy link
Contributor Author

/test pull-tekton-pipeline-integration-tests

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/condition_validation.go 90.0% 80.0% -10.0
pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go 95.5% 90.9% -4.5
pkg/apis/pipeline/v1alpha1/run_validation.go 93.8% 87.5% -6.2
pkg/apis/pipeline/v1alpha1/taskrun_validation.go 89.8% 88.1% -1.7
pkg/apis/validate/metadata.go 83.3% 75.0% -8.3

@ghost
Copy link

ghost commented Apr 20, 2021

The integration tests are failing due to a version change in the cluster that gets spun up for the tests to run in. Folks in slack are exploring the problem atm.

@psschwei
Copy link
Contributor Author

/retest

@psschwei
Copy link
Contributor Author

So the integration tests are failing with the following error:

   Error from server (BadRequest): error when creating "STDIN": admission webhook "validation.webhook.pipeline.tekton.dev" denied the request: validation failed: invalid resource name "unit.tests": must be a valid DNS label: metadata.name
        Error from server (BadRequest): error when creating "STDIN": admission webhook "validation.webhook.pipeline.tekton.dev" denied the request: validation failed: invalid resource name "demo.pipeline": must be a valid DNS label: metadata.name

Looking closer at the Kubernetes docs, while a . is valid for DNS Subdomain names, it is not a valid character for DNS Label names.

Assuming that the metadata.name for Pipelines and Tasks are DNS Labels rather than Subdomains (based on the fact that existing code was limiting names to <= 63 characters), it turns out that . may not be a valid character after all.

/meow

@tekton-robot
Copy link
Collaborator

@psschwei: cat image

In response to this:

So the integration tests are failing with the following error:

  Error from server (BadRequest): error when creating "STDIN": admission webhook "validation.webhook.pipeline.tekton.dev" denied the request: validation failed: invalid resource name "unit.tests": must be a valid DNS label: metadata.name
       Error from server (BadRequest): error when creating "STDIN": admission webhook "validation.webhook.pipeline.tekton.dev" denied the request: validation failed: invalid resource name "demo.pipeline": must be a valid DNS label: metadata.name

Looking closer at the Kubernetes docs, while a . is valid for DNS Subdomain names, it is not a valid character for DNS Label names.

Assuming that the metadata.name for Pipelines and Tasks are DNS Labels rather than Subdomains (based on the fact that existing code was limiting names to <= 63 characters), it turns out that . may not be a valid character after all.

/meow

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.

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/condition_validation.go 90.0% 80.0% -10.0
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 97.8% 97.0% -0.7
pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go 95.5% 90.9% -4.5
pkg/apis/pipeline/v1alpha1/run_validation.go 93.8% 87.5% -6.2
pkg/apis/pipeline/v1alpha1/taskrun_validation.go 89.8% 88.1% -1.7
pkg/apis/validate/metadata.go 83.3% 75.0% -8.3

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/condition_validation.go 90.0% 80.0% -10.0
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 97.8% 97.0% -0.7
pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go 95.5% 90.9% -4.5
pkg/apis/pipeline/v1alpha1/run_validation.go 93.8% 87.5% -6.2
pkg/apis/pipeline/v1alpha1/taskrun_validation.go 89.8% 88.1% -1.7
pkg/apis/validate/metadata.go 83.3% 75.0% -8.3

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/condition_validation.go 90.0% 80.0% -10.0
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 97.8% 97.0% -0.7
pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go 95.5% 90.9% -4.5
pkg/apis/pipeline/v1alpha1/run_validation.go 93.8% 87.5% -6.2
pkg/apis/pipeline/v1alpha1/taskrun_validation.go 89.8% 88.1% -1.7
pkg/apis/validate/metadata.go 83.3% 75.0% -8.3

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/condition_validation.go 90.0% 80.0% -10.0
pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go 95.5% 90.9% -4.5
pkg/apis/pipeline/v1alpha1/run_validation.go 93.8% 87.5% -6.2
pkg/apis/pipeline/v1alpha1/taskrun_validation.go 89.8% 88.1% -1.7
pkg/apis/validate/metadata.go 83.3% 50.0% -33.3

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/condition_validation.go 90.0% 80.0% -10.0
pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go 95.5% 90.9% -4.5
pkg/apis/pipeline/v1alpha1/run_validation.go 93.8% 87.5% -6.2
pkg/apis/pipeline/v1alpha1/taskrun_validation.go 89.8% 88.1% -1.7
pkg/apis/validate/metadata.go 83.3% 50.0% -33.3

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/run_validation.go 93.8% 87.5% -6.2

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/run_validation.go 93.8% 87.5% -6.2

@psschwei
Copy link
Contributor Author

PR description has been updated with more detail. This should be ready to go now.
/hold cancel
/meow

@tekton-robot
Copy link
Collaborator

@psschwei: cat image

In response to this:

PR description has been updated with more detail. This should be ready to go now.
/hold cancel
/meow

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.

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 22, 2021
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/run_validation.go 93.8% 87.5% -6.2

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/run_validation.go 93.8% 87.5% -6.2

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

One comment on the DNS1123 validation.

pkg/apis/validate/metadata.go Show resolved Hide resolved
@psschwei
Copy link
Contributor Author

psschwei commented Apr 22, 2021

One comment on the DNS1123 validation.
Does this mean that we allowed name like fooBar and now we don't ? Or was it already not allowed by the kubernetes api server ?

It appears the api server blocked it:

$ cat echo-hello-world.yaml 
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: echo-Hello-world
spec:
  steps:
    - name: echo
      image: ubuntu
      command:
        - echo
      args:
        - "Hello World"
$ k apply -f echo-hello-world.yaml -n paul
The Task "echo-Hello-world" is invalid: metadata.name: Invalid value: "echo-Hello-world": a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')

(tested on Pipelines v0.15.2)

@vdemeester
Copy link
Member

@psschwei indeed, it seems it is either the api-server or the generic validation knative.dev/pkg provides us.
/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 22, 2021
@psschwei
Copy link
Contributor Author

/test pull-tekton-pipeline-go-coverage

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/run_validation.go 93.8% 87.5% -6.2

@pritidesai
Copy link
Member

thanks @psschwei for all the work which started as a simple change 😜

/approve

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pritidesai

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 23, 2021
@tekton-robot tekton-robot merged commit 3dc52df into tektoncd:main Apr 23, 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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

Why does a Tekton resource cannot contain a dot?
7 participants