Skip to content

Commit 7e3897a

Browse files
chitrangpateltekton-robot
authored andcommitted
TEP-0142: Add syntax for providing params to StepActions
Following the previous [PR](#7317), which introduced Params to the `StepAction` CRD, this PR integrates `param` usage between `Steps` and `StepActions`. This PR adds the necessary syntax to `Steps` to pass `params` to `StepActions`. This work is part of issue #7259.
1 parent 515c4a3 commit 7e3897a

16 files changed

+214
-4
lines changed

docs/pipeline-api.md

Lines changed: 30 additions & 2 deletions
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>Params declares parameters passed to this step action.</p>
4442+
</td>
4443+
</tr>
44304444
</tbody>
44314445
</table>
44324446
<h3 id="tekton.dev/v1.StepOutputConfig">StepOutputConfig
@@ -10215,7 +10229,7 @@ map[string]string
1021510229
<h3 id="tekton.dev/v1beta1.Params">Params
1021610230
(<code>[]github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param</code> alias)</h3>
1021710231
<p>
10218-
(<em>Appears on:</em><a href="#tekton.dev/v1alpha1.RunSpec">RunSpec</a>, <a href="#tekton.dev/v1beta1.CustomRunSpec">CustomRunSpec</a>, <a href="#tekton.dev/v1beta1.IncludeParams">IncludeParams</a>, <a href="#tekton.dev/v1beta1.Matrix">Matrix</a>, <a href="#tekton.dev/v1beta1.PipelineRunSpec">PipelineRunSpec</a>, <a href="#tekton.dev/v1beta1.PipelineTask">PipelineTask</a>, <a href="#tekton.dev/v1beta1.ResolverRef">ResolverRef</a>, <a href="#tekton.dev/v1beta1.TaskRunSpec">TaskRunSpec</a>)
10232+
(<em>Appears on:</em><a href="#tekton.dev/v1alpha1.RunSpec">RunSpec</a>, <a href="#tekton.dev/v1beta1.CustomRunSpec">CustomRunSpec</a>, <a href="#tekton.dev/v1beta1.IncludeParams">IncludeParams</a>, <a href="#tekton.dev/v1beta1.Matrix">Matrix</a>, <a href="#tekton.dev/v1beta1.PipelineRunSpec">PipelineRunSpec</a>, <a href="#tekton.dev/v1beta1.PipelineTask">PipelineTask</a>, <a href="#tekton.dev/v1beta1.ResolverRef">ResolverRef</a>, <a href="#tekton.dev/v1beta1.Step">Step</a>, <a href="#tekton.dev/v1beta1.TaskRunSpec">TaskRunSpec</a>)
1021910233
</p>
1022010234
<div>
1022110235
<p>Params is a list of Param</p>
@@ -13227,6 +13241,20 @@ Ref
1322713241
<p>Contains the reference to an existing StepAction.</p>
1322813242
</td>
1322913243
</tr>
13244+
<tr>
13245+
<td>
13246+
<code>params</code><br/>
13247+
<em>
13248+
<a href="#tekton.dev/v1beta1.Params">
13249+
Params
13250+
</a>
13251+
</em>
13252+
</td>
13253+
<td>
13254+
<em>(Optional)</em>
13255+
<p>Params declares parameters passed to this step action.</p>
13256+
</td>
13257+
</tr>
1323013258
</tbody>
1323113259
</table>
1323213260
<h3 id="tekton.dev/v1beta1.StepOutputConfig">StepOutputConfig

docs/stepactions.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ When a `Step` is referencing a `StepAction`, it can contain the following fields
206206
- `securityContext`
207207
- `envFrom`
208208
- `timeout`
209+
- `ref`
210+
- `params`
209211

210212
Using any of the above fields and referencing a `StepAction` is allowed and will not cause an error. For example, the `TaskRun` below will execute without any errors:
211213

@@ -220,10 +222,39 @@ spec:
220222
- name: action-runner
221223
ref:
222224
name: step-action
225+
params:
226+
- name: step-action-param
227+
value: hello
223228
computeResources:
224229
requests:
225230
memory: 1Gi
226231
cpu: 500m
227232
timeout: 1h
228233
onError: continue
229234
```
235+
236+
### Passing Params to StepAction
237+
238+
A `StepAction` may require [params](#(declaring-parameters)). In this case, a `Task` needs to ensure that the `StepAction` has access to all the required `params`.
239+
When referencing a `StepAction`, a `Step` can also provide it with `params`, just like how a `TaskRun` provides params to the underlying `Task`.
240+
241+
```yaml
242+
apiVersion: tekton.dev/v1
243+
kind: Task
244+
metadata:
245+
name: step-action
246+
spec:
247+
TaskSpec:
248+
params:
249+
- name: param-for-step-action
250+
description: "this is a param that the step action needs."
251+
steps:
252+
- name: action-runner
253+
ref:
254+
name: step-action
255+
params:
256+
- name: step-action-param
257+
value: $(params.param-for-step-action)
258+
```
259+
260+
**Note:** If a `Step` declares `params` for an `inlined Step`, it will also lead to a validation error. This is because an `inlined Step` gets it's `params` from the `TaskRun`.

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+
// Params 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": "Params 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/apis/pipeline/v1beta1/container_conversion.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ func (s Step) convertTo(ctx context.Context, sink *v1.Step) {
6565
sink.Ref = &v1.Ref{}
6666
s.Ref.convertTo(ctx, sink.Ref)
6767
}
68+
sink.Params = nil
69+
for _, p := range s.Params {
70+
new := v1.Param{}
71+
p.convertTo(ctx, &new)
72+
sink.Params = append(sink.Params, new)
73+
}
6874
}
6975

7076
func (s *Step) convertFrom(ctx context.Context, source v1.Step) {
@@ -97,6 +103,12 @@ func (s *Step) convertFrom(ctx context.Context, source v1.Step) {
97103
newRef.convertFrom(ctx, *source.Ref)
98104
s.Ref = &newRef
99105
}
106+
s.Params = nil
107+
for _, p := range source.Params {
108+
new := Param{}
109+
new.ConvertFrom(ctx, p)
110+
s.Params = append(s.Params, new)
111+
}
100112
}
101113

102114
func (s StepTemplate) convertTo(ctx context.Context, sink *v1.StepTemplate) {

pkg/apis/pipeline/v1beta1/container_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ type Step struct {
232232
// Contains the reference to an existing StepAction.
233233
//+optional
234234
Ref *Ref `json:"ref,omitempty"`
235+
// Params declares parameters passed to this step action.
236+
// +optional
237+
// +listType=atomic
238+
Params Params `json:"params,omitempty"`
235239
}
236240

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

0 commit comments

Comments
 (0)