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

Parameter variable substitution support for conditionals #1143

Merged
merged 2 commits into from
Aug 2, 2019

Conversation

dibyom
Copy link
Member

@dibyom dibyom commented Jul 31, 2019

Changes

Add parameter variable substitution support for conditionals
A Condition's spec.Check can refer to its declared parameters using
the ${params.param-name} syntax just like in a Task. Values can be
provided via the pipelinerun's parameters or via default values in the
condition or in the PipelineTaskCondition

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

Part of #1019, #1137

Release Notes

- Adds the ability to declare and use parameters in a Condition 
whose values can be defined in a pipelinerun. 

@tekton-robot tekton-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 31, 2019
@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Jul 31, 2019
@tekton-robot tekton-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 31, 2019
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go Do not exist 82.3%
pkg/reconciler/v1alpha1/pipelinerun/resources/conditionresolution.go 76.7% 80.0% 3.3
pkg/templating/container_replacements.go Do not exist 100.0%
test/builder/pipeline.go 86.1% 86.7% 0.7

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go Do not exist 82.3%
pkg/reconciler/v1alpha1/pipelinerun/resources/conditionresolution.go 76.7% 80.0% 3.3
pkg/templating/container_replacements.go Do not exist 100.0%
test/builder/pipeline.go 86.1% 86.7% 0.7

"github.com/tektoncd/pipeline/pkg/templating"
)

func TestApplyContainerReplacements(t *testing.T) {
Copy link

Choose a reason for hiding this comment

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

nice

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for improving the test coverage here!
Since you're at it 👼 it would be nice to test the case of replacement when the variable is not defined.

@dibyom dibyom changed the title WIP: Parameter variable substitution support for conditionals Parameter variable substitution support for conditionals Aug 1, 2019
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 1, 2019
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go Do not exist 82.3%
pkg/reconciler/v1alpha1/pipelinerun/resources/conditionresolution.go 76.7% 80.0% 3.3
pkg/templating/container_replacements.go Do not exist 100.0%
test/builder/pipeline.go 86.1% 86.7% 0.7

docs/conditions.md Outdated Show resolved Hide resolved
docs/conditions.md Outdated Show resolved Hide resolved
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go Do not exist 82.3%
pkg/reconciler/v1alpha1/pipelinerun/resources/conditionresolution.go 76.7% 80.0% 3.3
pkg/templating/container_replacements.go Do not exist 100.0%
test/builder/pipeline.go 86.1% 86.7% 0.7

@ghost
Copy link

ghost commented Aug 1, 2019

/lgtm

@tekton-robot tekton-robot assigned ghost Aug 1, 2019
@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 1, 2019
@afrittoli
Copy link
Member

I've not reviewed the code yet, but I noticed that the params are limited to string - I wonder if we should support the newly added array params too? That could be a separate PR of course.

@dibyom
Copy link
Member Author

dibyom commented Aug 1, 2019

I wonder if we should support the newly added array params too?

Array params should be supported for the args and command fields just like in a task. Could not think of a good use case for it for the examples at the moment, but I could add it in!

This makes it easier to reuse this functionality across taskruns and
conditions.

Signed-off-by: Dibyo Mukherjee <dibyo@google.com>
A Condition's `spec.Check` can refer to its declared parameters using
the ${params.param-name} syntax just like in a Task. Values can be
provided via the pipelinerun's parameters or via default values in the
condition or in the PipelineTaskCondition

Signed-off-by: Dibyo Mukherjee <dibyo@google.com>
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 1, 2019
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/pipelinerun/resources/conditionresolution.go 76.7% 80.0% 3.3
pkg/templating/container_replacements.go Do not exist 100.0%
test/builder/pipeline.go 86.1% 86.7% 0.7

@ghost
Copy link

ghost commented Aug 2, 2019

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 2, 2019
Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

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

Thank you, nice work!!
I have a couple of minor comments, but nothing important so I'm going to approve this anyways.

parameter name, `barIsBa$` or `0banana` are not.

Each declared parameter has a type field, assumed to be string if not provided by the user.
The other possible type is array — useful,checking a pushed branch name doesn't match any of
Copy link
Member

Choose a reason for hiding this comment

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

NIT: space after the comma

parameter name, `barIsBa$` or `0banana` are not.

Each declared parameter has a type field, assumed to be string if not provided by the user.
The other possible type is array — useful,checking a pushed branch name doesn't match any of
Copy link
Member

Choose a reason for hiding this comment

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

NIT: space after the comma

}

return p
}

func replaceParamValues(params []v1alpha1.Param, stringReplacements map[string]string, arrayReplacements map[string][]string) []v1alpha1.Param {
Copy link
Member

Choose a reason for hiding this comment

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

Nice :)

@@ -69,6 +70,49 @@ func TestApplyParameters(t *testing.T) {
tb.PipelineTask("first-task-1", "first-task",
tb.PipelineTaskParam("first-task-first-param", "${input.workspace.default-value}"),
))),
}, {
name: "single parameter in task condition",
Copy link
Member

Choose a reason for hiding this comment

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

NIT: I guess the test name refers to the amount of parameters passed in the run? One is left to default and one not. Perhaps the name could be changed?

),
))),
}, {
name: "pipeline parameter nested inside condition parameter",
Copy link
Member

Choose a reason for hiding this comment

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

NIT: again, the name of the test is a bit confusing for me, in this case there is only one parameter and it's left to default.

"github.com/tektoncd/pipeline/pkg/templating"
)

func TestApplyContainerReplacements(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for improving the test coverage here!
Since you're at it 👼 it would be nice to test the case of replacement when the variable is not defined.

@afrittoli
Copy link
Member

/lgtm
/approve

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: afrittoli, dibyom

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 Aug 2, 2019
@tekton-robot tekton-robot merged commit 7b06d63 into tektoncd:master Aug 2, 2019
@dibyom dibyom deleted the cond-params branch August 2, 2019 20:47
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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants