Skip to content

Commit 7112cad

Browse files
committed
Add support for params between Step and StepActions
Following the previous [PR](#7317), which introduced Params to the `StepAction` CRD, this PR integrates `param` usage between `Steps` and `StepActions`. This completes support for params in `StepActions`. This work is part of issue #7259.
1 parent 695311e commit 7112cad

File tree

17 files changed

+1014
-25
lines changed

17 files changed

+1014
-25
lines changed

docs/pipeline-api.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ map[string]string
18021802
<h3 id="tekton.dev/v1.Params">Params
18031803
(<code>[]github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Param</code> alias)</h3>
18041804
<p>
1805-
(<em>Appears on:</em><a href="#tekton.dev/v1.IncludeParams">IncludeParams</a>, <a href="#tekton.dev/v1.Matrix">Matrix</a>, <a href="#tekton.dev/v1.PipelineRunSpec">PipelineRunSpec</a>, <a href="#tekton.dev/v1.PipelineTask">PipelineTask</a>, <a href="#tekton.dev/v1.ResolverRef">ResolverRef</a>, <a href="#tekton.dev/v1.TaskRunInputs">TaskRunInputs</a>, <a href="#tekton.dev/v1.TaskRunSpec">TaskRunSpec</a>)
1805+
(<em>Appears on:</em><a href="#tekton.dev/v1.IncludeParams">IncludeParams</a>, <a href="#tekton.dev/v1.Matrix">Matrix</a>, <a href="#tekton.dev/v1.PipelineRunSpec">PipelineRunSpec</a>, <a href="#tekton.dev/v1.PipelineTask">PipelineTask</a>, <a href="#tekton.dev/v1.ResolverRef">ResolverRef</a>, <a href="#tekton.dev/v1.Step">Step</a>, <a href="#tekton.dev/v1.TaskRunInputs">TaskRunInputs</a>, <a href="#tekton.dev/v1.TaskRunSpec">TaskRunSpec</a>)
18061806
</p>
18071807
<div>
18081808
<p>Params is a list of Param</p>
@@ -4427,6 +4427,20 @@ Ref
44274427
<p>Contains the reference to an existing StepAction.</p>
44284428
</td>
44294429
</tr>
4430+
<tr>
4431+
<td>
4432+
<code>params</code><br/>
4433+
<em>
4434+
<a href="#tekton.dev/v1.Params">
4435+
Params
4436+
</a>
4437+
</em>
4438+
</td>
4439+
<td>
4440+
<em>(Optional)</em>
4441+
<p>Parameters declares parameters passed to this step action.</p>
4442+
</td>
4443+
</tr>
44304444
</tbody>
44314445
</table>
44324446
<h3 id="tekton.dev/v1.StepOutputConfig">StepOutputConfig
@@ -7081,6 +7095,18 @@ Hub resource: <a href="https://artifacthub.io/*">https://artifacthub.io/*</a>,</
70817095
</tr>
70827096
</tbody>
70837097
</table>
7098+
<h3 id="tekton.dev/v1alpha1.ResultsType">ResultsType
7099+
(<code>string</code> alias)</h3>
7100+
<p>
7101+
(<em>Appears on:</em><a href="#tekton.dev/v1alpha1.StepActionResult">StepActionResult</a>)
7102+
</p>
7103+
<div>
7104+
<p>ResultsType indicates the type of a result;
7105+
Used to distinguish between a single string and an array of strings.
7106+
Note that there is ResultType used to find out whether a
7107+
RunResult is from a task result or not, which is different from
7108+
this ResultsType.</p>
7109+
</div>
70847110
<h3 id="tekton.dev/v1alpha1.RunReason">RunReason
70857111
(<code>string</code> alias)</h3>
70867112
<div>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
apiVersion: tekton.dev/v1alpha1
2+
kind: StepAction
3+
metadata:
4+
name: step-action
5+
spec:
6+
params:
7+
- name: not
8+
default: "a mysterious GH action"
9+
- name: array-param
10+
type: array
11+
default:
12+
- ho
13+
- ho
14+
- ho
15+
- name: object-param
16+
type: object
17+
properties:
18+
foo:
19+
type: string
20+
bar:
21+
type: string
22+
default:
23+
foo: "default foo"
24+
image: bash:3.2
25+
args: [
26+
"echo",
27+
"$(params.array-param[*])",
28+
"$(params.not)",
29+
"$(params.object-param.foo)",
30+
"$(params.object-param.bar)"
31+
]
32+
---
33+
apiVersion: tekton.dev/v1
34+
kind: PipelineRun
35+
metadata:
36+
name: step-action-pipeline-run
37+
spec:
38+
params:
39+
- name: notaction
40+
value: "a github, mysterious or Task action"
41+
- name: arrayparam
42+
value:
43+
- "hello, "
44+
- "hi!!"
45+
- name: objectparam
46+
value:
47+
bar: "chocolate bar"
48+
PipelineSpec:
49+
tasks:
50+
- name: run-action
51+
taskSpec:
52+
steps:
53+
- name: action-runner
54+
ref:
55+
name: step-action
56+
params:
57+
- name: not
58+
value: $(params.notaction)
59+
- name: array-param
60+
value: $(params.arrayparam[*])
61+
- name: object-param
62+
value: $(params.objectparam[*])
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
apiVersion: tekton.dev/v1alpha1
2+
kind: StepAction
3+
metadata:
4+
name: step-action
5+
spec:
6+
params:
7+
- name: not
8+
default: "a mysterious GH action"
9+
- name: array-param
10+
type: array
11+
default:
12+
- ho
13+
- ho
14+
- ho
15+
- name: object-param
16+
type: object
17+
properties:
18+
foo:
19+
type: string
20+
bar:
21+
type: string
22+
default:
23+
foo: "default foo"
24+
image: bash:3.2
25+
args: [
26+
"echo",
27+
"$(params.array-param[*])",
28+
"$(params.not)",
29+
"$(params.object-param.foo)",
30+
"$(params.object-param.bar)"
31+
]
32+
---
33+
apiVersion: tekton.dev/v1
34+
kind: TaskRun
35+
metadata:
36+
name: step-action-run
37+
spec:
38+
params:
39+
- name: notaction
40+
value: "a github, mysterious or Task action"
41+
- name: arrayparam
42+
value:
43+
- "hello, "
44+
- "hi!!"
45+
- name: objectparam
46+
value:
47+
bar: "chocolate bar"
48+
TaskSpec:
49+
#params:
50+
# - name: objectparam
51+
# properties:
52+
# foo:
53+
# type: string
54+
# bar:
55+
# type: string
56+
# default:
57+
# bar: "default bar"
58+
steps:
59+
- name: action-runner
60+
ref:
61+
name: step-action
62+
params:
63+
- name: not
64+
value: $(params.notaction)
65+
- name: array-param
66+
value: $(params.arrayparam[*])
67+
- name: object-param
68+
value: $(params.objectparam[*])

pkg/apis/pipeline/v1/container_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ type Step struct {
138138
// Contains the reference to an existing StepAction.
139139
//+optional
140140
Ref *Ref `json:"ref,omitempty"`
141+
// Parameters declares parameters passed to this step action.
142+
// +optional
143+
// +listType=atomic
144+
Params Params `json:"params,omitempty"`
141145
}
142146

143147
// Ref can be used to refer to a specific instance of a StepAction.

pkg/apis/pipeline/v1/openapi_generated.go

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/pipeline/v1/swagger.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,15 @@
14631463
"description": "OnError defines the exiting behavior of a container on error can be set to [ continue | stopAndFail ]",
14641464
"type": "string"
14651465
},
1466+
"params": {
1467+
"description": "Parameters declares parameters passed to this step action.",
1468+
"type": "array",
1469+
"items": {
1470+
"default": {},
1471+
"$ref": "#/definitions/v1.Param"
1472+
},
1473+
"x-kubernetes-list-type": "atomic"
1474+
},
14661475
"ref": {
14671476
"description": "Contains the reference to an existing StepAction.",
14681477
"$ref": "#/definitions/v1.Ref"

pkg/apis/pipeline/v1/task_validation.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ func validateStep(ctx context.Context, s Step, names sets.String) (errs *apis.Fi
300300
})
301301
}
302302
} else {
303+
if len(s.Params) > 0 {
304+
errs = errs.Also(&apis.FieldError{
305+
Message: "params cannot be used without Ref",
306+
Paths: []string{"params"},
307+
})
308+
}
303309
if s.Image == "" {
304310
errs = errs.Also(apis.ErrMissingField("Image"))
305311
}

pkg/apis/pipeline/v1/task_validation_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,16 @@ func TestTaskSpecStepActionReferenceValidate(t *testing.T) {
534534
Name: "stepAction",
535535
},
536536
}},
537+
}, {
538+
name: "valid use of params with Ref",
539+
Steps: []v1.Step{{
540+
Ref: &v1.Ref{
541+
Name: "stepAction",
542+
},
543+
Params: v1.Params{{
544+
Name: "param",
545+
}},
546+
}},
537547
}}
538548
for _, tt := range tests {
539549
t.Run(tt.name, func(t *testing.T) {
@@ -1490,6 +1500,19 @@ func TestTaskSpecValidateErrorWithStepActionRef(t *testing.T) {
14901500
Message: "env cannot be used with Ref",
14911501
Paths: []string{"steps[0].env"},
14921502
},
1503+
}, {
1504+
name: "Cannot use params without Ref",
1505+
Steps: []v1.Step{{
1506+
Image: "my-image",
1507+
Params: v1.Params{{
1508+
Name: "param",
1509+
}},
1510+
}},
1511+
enableStepActions: true,
1512+
expectedError: apis.FieldError{
1513+
Message: "params cannot be used without Ref",
1514+
Paths: []string{"steps[0].params"},
1515+
},
14931516
}}
14941517
for _, tt := range tests {
14951518
t.Run(tt.name, func(t *testing.T) {

pkg/apis/pipeline/v1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/reconciler/pipelinerun/resources/apply.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ func propagateParams(t v1.PipelineTask, stringReplacements map[string]string, ar
367367
}
368368
}
369369
}
370-
t.TaskSpec.TaskSpec = *resources.ApplyReplacements(&t.TaskSpec.TaskSpec, stringReplacementsDup, arrayReplacementsDup)
370+
t.TaskSpec.TaskSpec = *resources.ApplyReplacements(&t.TaskSpec.TaskSpec, stringReplacementsDup, arrayReplacementsDup, objectReplacementsDup)
371371
} else {
372-
t.TaskSpec.TaskSpec = *resources.ApplyReplacements(&t.TaskSpec.TaskSpec, stringReplacements, arrayReplacements)
372+
t.TaskSpec.TaskSpec = *resources.ApplyReplacements(&t.TaskSpec.TaskSpec, stringReplacements, arrayReplacements, objectReplacements)
373373
}
374374
return t
375375
}
@@ -395,7 +395,7 @@ func PropagateResults(rpt *ResolvedPipelineTask, runStates PipelineRunState) {
395395
}
396396
}
397397
}
398-
rpt.ResolvedTask.TaskSpec = resources.ApplyReplacements(rpt.ResolvedTask.TaskSpec, stringReplacements, arrayReplacements)
398+
rpt.ResolvedTask.TaskSpec = resources.ApplyReplacements(rpt.ResolvedTask.TaskSpec, stringReplacements, arrayReplacements, map[string]map[string]string{})
399399
}
400400

401401
// ApplyTaskResultsToPipelineResults applies the results of completed TasksRuns and Runs to a Pipeline's

0 commit comments

Comments
 (0)