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

Task validation : fix variable validation in case of multiple variables 👼 #472

Merged
merged 1 commit into from
Feb 4, 2019

Conversation

vdemeester
Copy link
Member

There was a problem if a single string contains more than one
variables when validating it. For example, the following Task would
fail validation at creation.

apiVersion: pipeline.knative.dev/v1alpha1
kind: Task
metadata:
  name: foo
spec:
  inputs:
    params:
    - name: foo
      description: foo is FOO
      default: banana
    - name: bar
      description: bar is BAR
      default: baz
  steps:
  - name: run-me
    image: busybok
    command: ["/bin/sh", "-c"]
    args: ["echo I am a ${inputs.params.foo} named ${inputs.params.baz}"]

The regular expression used was too naive, it is now fixed. Before
this change, the extracted variable would be:

inputs param.foo} named ${inputs.params.baz

… and thus, the validation would fail.

With this fix, it extracts both variables and validate both.

/cc @bobcatfish @shashwathi

Signed-off-by: Vincent Demeester [email protected]

@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Feb 4, 2019
@knative-prow-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vdemeester

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 4, 2019
@@ -27,6 +27,8 @@ import (
"k8s.io/apimachinery/pkg/util/validation"
)

const substitution = "[_a-zA-Z][_a-zA-Z0-9.-]*"
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is a good "base" for variable name but might be too restrictive though

Copy link
Member

Choose a reason for hiding this comment

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

seems fine to me, it allows - and _

Copy link
Member

@nader-ziada nader-ziada left a comment

Choose a reason for hiding this comment

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

nice job @vdemeester 👍

Can you just add in the docs the allowed rules for naming variables in templating so it passes the regex?

@@ -27,6 +27,8 @@ import (
"k8s.io/apimachinery/pkg/util/validation"
)

const substitution = "[_a-zA-Z][_a-zA-Z0-9.-]*"
Copy link
Member

Choose a reason for hiding this comment

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

seems fine to me, it allows - and _

@abayer
Copy link
Contributor

abayer commented Feb 4, 2019

Nice! I’m gonna pull this over to #471 as well. =)

…es 👼

There was a problem if a single string contains more than one
variables when validating it. For example, the following Task would
fail validation at creation.

```yaml
apiVersion: pipeline.knative.dev/v1alpha1
kind: Task
metadata:
  name: foo
spec:
  inputs:
    params:
    - name: foo
      description: foo is FOO
      default: banana
    - name: bar
      description: bar is BAR
      default: baz
  steps:
  - name: run-me
    image: busybok
    command: ["/bin/sh", "-c"]
    args: ["echo I am a ${inputs.params.foo} named ${inputs.params.baz}"]
```

The regular expression used was too naive, it is now fixed. Before
this change, the extracted variable would be:

`inputs param.foo} named ${inputs.params.baz`

… and thus, the validation would fail.

With this fix, it extracts both variables and validate both.

Signed-off-by: Vincent Demeester <[email protected]>
@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-build-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/task_validation.go 83.1% 84.9% 1.8

@nader-ziada
Copy link
Member

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 4, 2019
@knative-prow-robot knative-prow-robot merged commit b25cc84 into tektoncd:master Feb 4, 2019
@vdemeester vdemeester deleted the fix-validation-args branch February 4, 2019 15:46
@bobcatfish
Copy link
Collaborator

nice catch @vdemeester 👊

@vdemeester vdemeester restored the fix-validation-args branch February 26, 2019 09:17
@vdemeester vdemeester deleted the fix-validation-args branch February 26, 2019 09:17
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 Trying to make the CLA bot happy with ppl from different companies work on one commit lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants