Skip to content

Commit

Permalink
Propagate params in pipelines
Browse files Browse the repository at this point in the history
Prior to this, we allowed parameter propagation in an inlined
pipelinerun. However, within a pipeline, we requrie a verbose spec.
This was an oversight as indicated in
#7901.
This PR fixes that issue by updating the validation logic in the
webhook.

Fixes #7901.
  • Loading branch information
chitrangpatel committed May 6, 2024
1 parent 59794e3 commit 991f1e9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
34 changes: 34 additions & 0 deletions examples/v1/pipelineruns/propagating-params-in-pipelines.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: param-example
spec:
params:
- name: p1
- name: p2
tasks:
- name: t1
taskSpec:
steps:
- image: ubuntu
command: ["echo"]
args: ["$(params.p1)"]
- name: t2
taskSpec:
steps:
- image: ubuntu
command: ["echo"]
args: ["$(params.p2)"]
---
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: param-example-run
spec:
pipelineRef:
name: param-example
params:
- name: p1
value: foo
- name: p2
value: bar
32 changes: 32 additions & 0 deletions examples/v1/pipelineruns/propagating-workspaces-in-pipelines.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: workspace-example
spec:
workspaces:
- name: shared-data
tasks:
- name: t1
taskSpec:
steps:
- image: ubuntu
command: ["ls"]
args: ["$(workspaces.shared-data.path)"]
---
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: workspace-example-run
spec:
pipelineRef:
name: workspace-example
workspaces:
- name: shared-data
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 16Mi
volumeMode: Filesystem
8 changes: 4 additions & 4 deletions pkg/apis/pipeline/v1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ func (l PipelineTaskList) Validate(ctx context.Context, taskNames sets.String, p
}

// validateUsageOfDeclaredPipelineTaskParameters validates that all parameters referenced in the pipeline Task are declared by the pipeline Task.
func (l PipelineTaskList) validateUsageOfDeclaredPipelineTaskParameters(ctx context.Context, path string) (errs *apis.FieldError) {
func (l PipelineTaskList) validateUsageOfDeclaredPipelineTaskParameters(ctx context.Context, additionalParams []ParamSpec, path string) (errs *apis.FieldError) {
for i, t := range l {
if t.TaskSpec != nil {
errs = errs.Also(ValidateUsageOfDeclaredParameters(ctx, t.TaskSpec.Steps, t.TaskSpec.Params).ViaFieldIndex(path, i))
errs = errs.Also(ValidateUsageOfDeclaredParameters(ctx, t.TaskSpec.Steps, append(t.TaskSpec.Params, additionalParams...)).ViaFieldIndex(path, i))
}
}
return errs
Expand Down Expand Up @@ -385,8 +385,8 @@ func validatePipelineWorkspacesDeclarations(wss []PipelineWorkspaceDeclaration)

// validatePipelineParameterUsage validates that parameters referenced in the Pipeline are declared by the Pipeline
func (ps *PipelineSpec) validatePipelineParameterUsage(ctx context.Context) (errs *apis.FieldError) {
errs = errs.Also(PipelineTaskList(ps.Tasks).validateUsageOfDeclaredPipelineTaskParameters(ctx, "tasks"))
errs = errs.Also(PipelineTaskList(ps.Finally).validateUsageOfDeclaredPipelineTaskParameters(ctx, "finally"))
errs = errs.Also(PipelineTaskList(ps.Tasks).validateUsageOfDeclaredPipelineTaskParameters(ctx, ps.Params, "tasks"))
errs = errs.Also(PipelineTaskList(ps.Finally).validateUsageOfDeclaredPipelineTaskParameters(ctx, ps.Params, "finally"))
errs = errs.Also(validatePipelineTaskParameterUsage(ps.Tasks, ps.Params).ViaField("tasks"))
errs = errs.Also(validatePipelineTaskParameterUsage(ps.Finally, ps.Params).ViaField("finally"))
return errs
Expand Down

0 comments on commit 991f1e9

Please sign in to comment.