Skip to content

Commit

Permalink
Implemented implicit parameter propagation.
Browse files Browse the repository at this point in the history
Implemented implicit parameter propagation.

Tekton Pipelines resources are verbose mostly because of explicitly propagating Parameters. Implicit Parameters feature was added to reduce the verbosity. However, there are challenges caused by mutating specifications to support Implicit Parameters. This proposal builds on this prior work by propagating Parameters without mutating specifications to improve usability of Tekton Pipelines.
  • Loading branch information
chitrangpatel committed May 6, 2022
1 parent d5ae54a commit 3f884da
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 13 deletions.
18 changes: 18 additions & 0 deletions examples/propagating_params_implicit_parameters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: pr-echo-
spec:
params:
- name: HELLO
value: "Pipeline Hello World!"
pipelineSpec:
tasks:
- name: echo-hello
taskSpec:
steps:
- name: echo
image: ubuntu
script: |
#!/usr/bin/env bash
echo "$(params.HELLO)"
21 changes: 21 additions & 0 deletions examples/propagating_params_with_scope_precedence.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: pr-echo-
spec:
params:
- name: HELLO
value: "Pipeline Hello World!"
pipelineSpec:
tasks:
- name: echo-hello
params:
- name: HELLO
value: "Task Hello World!"
taskSpec:
steps:
- name: echo
image: ubuntu
script: |
#!/usr/bin/env bash
echo "$(params.HELLO)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: pr-echo-
spec:
params:
- name: HELLO
value: "Pipeline Hello World!"
pipelineSpec:
tasks:
- name: echo-hello
taskSpec:
params:
- name: HELLO
default: "Default Hello World!"
steps:
- name: echo
image: ubuntu
script: |
#!/usr/bin/env bash
echo "$(params.HELLO)"
4 changes: 3 additions & 1 deletion pkg/apis/pipeline/v1beta1/task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ func validateStepVariables(step Step, prefix string, vars sets.String) *apis.Fie
errs := validateTaskVariable(step.Name, prefix, vars).ViaField("name")
errs = errs.Also(validateTaskVariable(step.Image, prefix, vars).ViaField("image"))
errs = errs.Also(validateTaskVariable(step.WorkingDir, prefix, vars).ViaField("workingDir"))
errs = errs.Also(validateTaskVariable(step.Script, prefix, vars).ViaField("script"))
if prefix != "params" {
errs = errs.Also(validateTaskVariable(step.Script, prefix, vars).ViaField("script"))
}
for i, cmd := range step.Command {
errs = errs.Also(validateTaskVariable(cmd, prefix, vars).ViaFieldIndex("command", i))
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/reconciler/pipelinerun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

"github.com/tektoncd/pipeline/pkg/apis/run/v1alpha1"
"github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/substitution"
Expand Down Expand Up @@ -158,6 +159,29 @@ func ApplyReplacements(p *v1beta1.PipelineSpec, replacements map[string]string,
c.Params = replaceParamValues(c.Params, replacements, arrayReplacements)
}
p.Tasks[i].WhenExpressions = p.Tasks[i].WhenExpressions.ReplaceWhenExpressionsVariables(replacements, arrayReplacements)
if p.Tasks[i].TaskSpec != nil {
patterns := []string{
"params.%s",
"params[%q]",
"params['%s']",
}
// check if there are task parameters defined that match the params at pipeline level
if len(p.Tasks[i].Params) > 0 {
for _, par := range p.Tasks[i].Params {
for _, pattern := range patterns {
checkName := fmt.Sprintf(pattern, par.Name)
// Scoping. Task Params will replace Pipeline Params
if _, ok := replacements[checkName]; ok {
replacements[checkName] = par.Value.StringVal
}
if _, ok := arrayReplacements[checkName]; ok {
arrayReplacements[checkName] = par.Value.ArrayVal
}
}
}
}
p.Tasks[i].TaskSpec.TaskSpec = *resources.ApplyReplacements(&p.Tasks[i].TaskSpec.TaskSpec, replacements, arrayReplacements)
}
}

for i := range p.Finally {
Expand Down
12 changes: 0 additions & 12 deletions pkg/reconciler/taskrun/validate_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"

"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
"github.com/tektoncd/pipeline/pkg/list"
Expand Down Expand Up @@ -93,17 +92,6 @@ func validateParams(ctx context.Context, paramSpecs []v1beta1.ParamSpec, params
if len(missingParamsNoDefaults) > 0 {
return fmt.Errorf("missing values for these params which have no default values: %s", missingParamsNoDefaults)
}
// If alpha features are enabled, disable checking for extra params.
// Extra params are needed to support
// https://github.com/tektoncd/community/blob/main/teps/0023-implicit-mapping.md
// So that parent params can be passed down to subresources (even if they
// are not explicitly used).
if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields != "alpha" {
extraParams := list.DiffLeft(providedParams, neededParams)
if len(extraParams) != 0 {
return fmt.Errorf("didn't need these params but they were provided anyway: %s", extraParams)
}
}

// Now that we have checked against missing/extra params, make sure each param's actual type matches
// the user-specified type.
Expand Down

0 comments on commit 3f884da

Please sign in to comment.