Skip to content

Commit 94d2fd7

Browse files
committed
Introduce StepAction referencing syntax in Steps
This PR adds the referencing syntax for `StepActions` in `Stpes`. It also adds the necessary conversion between `v1beta1` and `v1` and the necessary validation.
1 parent 08ee164 commit 94d2fd7

17 files changed

+807
-14
lines changed

docs/pipeline-api.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3270,6 +3270,35 @@ github.com/tektoncd/pipeline/pkg/apis/config.FeatureFlags
32703270
</tr>
32713271
</tbody>
32723272
</table>
3273+
<h3 id="tekton.dev/v1.Ref">Ref
3274+
</h3>
3275+
<p>
3276+
(<em>Appears on:</em><a href="#tekton.dev/v1.Step">Step</a>)
3277+
</p>
3278+
<div>
3279+
<p>Ref can be used to refer to a specific instance of a StepAction.</p>
3280+
</div>
3281+
<table>
3282+
<thead>
3283+
<tr>
3284+
<th>Field</th>
3285+
<th>Description</th>
3286+
</tr>
3287+
</thead>
3288+
<tbody>
3289+
<tr>
3290+
<td>
3291+
<code>name</code><br/>
3292+
<em>
3293+
string
3294+
</em>
3295+
</td>
3296+
<td>
3297+
<p>Name of the referenced step</p>
3298+
</td>
3299+
</tr>
3300+
</tbody>
3301+
</table>
32733302
<h3 id="tekton.dev/v1.RefSource">RefSource
32743303
</h3>
32753304
<p>
@@ -4353,6 +4382,20 @@ StepOutputConfig
43534382
<p>Stores configuration for the stderr stream of the step.</p>
43544383
</td>
43554384
</tr>
4385+
<tr>
4386+
<td>
4387+
<code>ref</code><br/>
4388+
<em>
4389+
<a href="#tekton.dev/v1.Ref">
4390+
Ref
4391+
</a>
4392+
</em>
4393+
</td>
4394+
<td>
4395+
<em>(Optional)</em>
4396+
<p>Contains the reference to an existing stepaction</p>
4397+
</td>
4398+
</tr>
43564399
</tbody>
43574400
</table>
43584401
<h3 id="tekton.dev/v1.StepOutputConfig">StepOutputConfig
@@ -11758,6 +11801,35 @@ github.com/tektoncd/pipeline/pkg/apis/config.FeatureFlags
1175811801
</tr>
1175911802
</tbody>
1176011803
</table>
11804+
<h3 id="tekton.dev/v1beta1.Ref">Ref
11805+
</h3>
11806+
<p>
11807+
(<em>Appears on:</em><a href="#tekton.dev/v1beta1.Step">Step</a>)
11808+
</p>
11809+
<div>
11810+
<p>Ref can be used to refer to a specific instance of a StepAction.</p>
11811+
</div>
11812+
<table>
11813+
<thead>
11814+
<tr>
11815+
<th>Field</th>
11816+
<th>Description</th>
11817+
</tr>
11818+
</thead>
11819+
<tbody>
11820+
<tr>
11821+
<td>
11822+
<code>name</code><br/>
11823+
<em>
11824+
string
11825+
</em>
11826+
</td>
11827+
<td>
11828+
<p>Name of the referenced step</p>
11829+
</td>
11830+
</tr>
11831+
</tbody>
11832+
</table>
1176111833
<h3 id="tekton.dev/v1beta1.RefSource">RefSource
1176211834
</h3>
1176311835
<p>
@@ -12954,6 +13026,20 @@ StepOutputConfig
1295413026
<p>Stores configuration for the stderr stream of the step.</p>
1295513027
</td>
1295613028
</tr>
13029+
<tr>
13030+
<td>
13031+
<code>ref</code><br/>
13032+
<em>
13033+
<a href="#tekton.dev/v1beta1.Ref">
13034+
Ref
13035+
</a>
13036+
</em>
13037+
</td>
13038+
<td>
13039+
<em>(Optional)</em>
13040+
<p>Contains the reference to an existing stepaction</p>
13041+
</td>
13042+
</tr>
1295713043
</tbody>
1295813044
</table>
1295913045
<h3 id="tekton.dev/v1beta1.StepOutputConfig">StepOutputConfig

docs/stepactions.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,51 @@ spec:
5454
command: ["ls"]
5555
args:: ["-lh"]
5656
```
57+
58+
## Referencing a StepAction
59+
60+
`StepActions` can be referenced from the `Step` using the `ref` field, as follows:
61+
62+
```yaml
63+
apiVersion: tekton.dev/v1
64+
kind: TaskRun
65+
metadata:
66+
name: step-action-run
67+
spec:
68+
TaskSpec:
69+
steps:
70+
- name: action-runner
71+
ref:
72+
name: step-action
73+
```
74+
75+
If a `Step` is referencing a `StepAction`, it cannot contain the fields supported by `StepActions`. This includes:
76+
- `image`
77+
- `command`
78+
- `args`
79+
- `script`
80+
- `env`
81+
82+
Using any of the above fields and referencing a `StepAction` in the same `Step` is not allowed and will cause an validation error.
83+
84+
```yaml
85+
# This is not allowed and will result in a validation error.
86+
# Because the image is expected to be provided by the StepAction
87+
# and not inlined.
88+
apiVersion: tekton.dev/v1
89+
kind: TaskRun
90+
metadata:
91+
name: step-action-run
92+
spec:
93+
TaskSpec:
94+
steps:
95+
- name: action-runner
96+
ref:
97+
name: step-action
98+
image: ubuntu
99+
```
100+
Executing the above `TaskRun` will result in an error that looks like:
101+
102+
```
103+
Error from server (BadRequest): error when creating "STDIN": admission webhook "validation.webhook.pipeline.tekton.dev" denied the request: validation failed: image cannot be used with Ref: spec.taskSpec.steps[0].image
104+
```

pkg/apis/pipeline/v1/container_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ type Step struct {
135135
// Stores configuration for the stderr stream of the step.
136136
// +optional
137137
StderrConfig *StepOutputConfig `json:"stderrConfig,omitempty"`
138+
// Contains the reference to an existing stepaction
139+
//+optional
140+
Ref *Ref `json:"ref,omitempty"`
141+
}
142+
143+
// Ref can be used to refer to a specific instance of a StepAction.
144+
type Ref struct {
145+
// Name of the referenced step
146+
Name string `json:"name,omitempty"`
138147
}
139148

140149
// OnErrorType defines a list of supported exiting behavior of a container on error

pkg/apis/pipeline/v1/openapi_generated.go

Lines changed: 28 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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,16 @@
10931093
}
10941094
}
10951095
},
1096+
"v1.Ref": {
1097+
"description": "Ref can be used to refer to a specific instance of a StepAction.",
1098+
"type": "object",
1099+
"properties": {
1100+
"name": {
1101+
"description": "Name of the referenced step",
1102+
"type": "string"
1103+
}
1104+
}
1105+
},
10961106
"v1.RefSource": {
10971107
"description": "RefSource contains the information that can uniquely identify where a remote built definition came from i.e. Git repositories, Tekton Bundles in OCI registry and hub.",
10981108
"type": "object",
@@ -1445,6 +1455,10 @@
14451455
"description": "OnError defines the exiting behavior of a container on error can be set to [ continue | stopAndFail ]",
14461456
"type": "string"
14471457
},
1458+
"ref": {
1459+
"description": "Contains the reference to an existing stepaction",
1460+
"$ref": "#/definitions/v1.Ref"
1461+
},
14481462
"script": {
14491463
"description": "Script is the contents of an executable file to execute.\n\nIf Script is not empty, the Step cannot have an Command and the Args will be passed to the Script.",
14501464
"type": "string"

pkg/apis/pipeline/v1/task_validation.go

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,53 @@ func validateSteps(ctx context.Context, steps []Step) (errs *apis.FieldError) {
264264
}
265265

266266
func validateStep(ctx context.Context, s Step, names sets.String) (errs *apis.FieldError) {
267-
if s.Image == "" {
268-
errs = errs.Also(apis.ErrMissingField("Image"))
269-
}
270-
271-
if s.Script != "" {
267+
if s.Ref != nil {
268+
if !config.FromContextOrDefaults(ctx).FeatureFlags.EnableStepActions {
269+
return apis.ErrGeneric("feature flag %s should be set to true to reference StepActions in Steps.", config.EnableStepActions)
270+
}
271+
if s.Image != "" {
272+
errs = errs.Also(&apis.FieldError{
273+
Message: "image cannot be used with Ref",
274+
Paths: []string{"image"},
275+
})
276+
}
272277
if len(s.Command) > 0 {
273278
errs = errs.Also(&apis.FieldError{
274-
Message: "script cannot be used with command",
279+
Message: "command cannot be used with Ref",
280+
Paths: []string{"command"},
281+
})
282+
}
283+
if len(s.Args) > 0 {
284+
errs = errs.Also(&apis.FieldError{
285+
Message: "args cannot be used with Ref",
286+
Paths: []string{"args"},
287+
})
288+
}
289+
if s.Script != "" {
290+
errs = errs.Also(&apis.FieldError{
291+
Message: "script cannot be used with Ref",
275292
Paths: []string{"script"},
276293
})
277294
}
295+
if s.Env != nil {
296+
errs = errs.Also(&apis.FieldError{
297+
Message: "env cannot be used with Ref",
298+
Paths: []string{"env"},
299+
})
300+
}
301+
} else {
302+
if s.Image == "" {
303+
errs = errs.Also(apis.ErrMissingField("Image"))
304+
}
305+
306+
if s.Script != "" {
307+
if len(s.Command) > 0 {
308+
errs = errs.Also(&apis.FieldError{
309+
Message: "script cannot be used with command",
310+
Paths: []string{"script"},
311+
})
312+
}
313+
}
278314
}
279315

280316
if s.Name != "" {

0 commit comments

Comments
 (0)