Skip to content

Commit

Permalink
Add support for params between Step and StepActions
Browse files Browse the repository at this point in the history
Following the previous [PR](tektoncd#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 tektoncd#7259.
  • Loading branch information
chitrangpatel committed Nov 3, 2023
1 parent 695311e commit 7112cad
Show file tree
Hide file tree
Showing 17 changed files with 1,014 additions and 25 deletions.
28 changes: 27 additions & 1 deletion docs/pipeline-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ map[string]string
<h3 id="tekton.dev/v1.Params">Params
(<code>[]github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Param</code> alias)</h3>
<p>
(<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>)
(<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>)
</p>
<div>
<p>Params is a list of Param</p>
Expand Down Expand Up @@ -4427,6 +4427,20 @@ Ref
<p>Contains the reference to an existing StepAction.</p>
</td>
</tr>
<tr>
<td>
<code>params</code><br/>
<em>
<a href="#tekton.dev/v1.Params">
Params
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>Parameters declares parameters passed to this step action.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="tekton.dev/v1.StepOutputConfig">StepOutputConfig
Expand Down Expand Up @@ -7081,6 +7095,18 @@ Hub resource: <a href="https://artifacthub.io/*">https://artifacthub.io/*</a>,</
</tr>
</tbody>
</table>
<h3 id="tekton.dev/v1alpha1.ResultsType">ResultsType
(<code>string</code> alias)</h3>
<p>
(<em>Appears on:</em><a href="#tekton.dev/v1alpha1.StepActionResult">StepActionResult</a>)
</p>
<div>
<p>ResultsType indicates the type of a result;
Used to distinguish between a single string and an array of strings.
Note that there is ResultType used to find out whether a
RunResult is from a task result or not, which is different from
this ResultsType.</p>
</div>
<h3 id="tekton.dev/v1alpha1.RunReason">RunReason
(<code>string</code> alias)</h3>
<div>
Expand Down
62 changes: 62 additions & 0 deletions examples/v1/pipelineruns/alpha/stepaction-params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
apiVersion: tekton.dev/v1alpha1
kind: StepAction
metadata:
name: step-action
spec:
params:
- name: not
default: "a mysterious GH action"
- name: array-param
type: array
default:
- ho
- ho
- ho
- name: object-param
type: object
properties:
foo:
type: string
bar:
type: string
default:
foo: "default foo"
image: bash:3.2
args: [
"echo",
"$(params.array-param[*])",
"$(params.not)",
"$(params.object-param.foo)",
"$(params.object-param.bar)"
]
---
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: step-action-pipeline-run
spec:
params:
- name: notaction
value: "a github, mysterious or Task action"
- name: arrayparam
value:
- "hello, "
- "hi!!"
- name: objectparam
value:
bar: "chocolate bar"
PipelineSpec:
tasks:
- name: run-action
taskSpec:
steps:
- name: action-runner
ref:
name: step-action
params:
- name: not
value: $(params.notaction)
- name: array-param
value: $(params.arrayparam[*])
- name: object-param
value: $(params.objectparam[*])
68 changes: 68 additions & 0 deletions examples/v1/taskruns/alpha/stepaction-params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
apiVersion: tekton.dev/v1alpha1
kind: StepAction
metadata:
name: step-action
spec:
params:
- name: not
default: "a mysterious GH action"
- name: array-param
type: array
default:
- ho
- ho
- ho
- name: object-param
type: object
properties:
foo:
type: string
bar:
type: string
default:
foo: "default foo"
image: bash:3.2
args: [
"echo",
"$(params.array-param[*])",
"$(params.not)",
"$(params.object-param.foo)",
"$(params.object-param.bar)"
]
---
apiVersion: tekton.dev/v1
kind: TaskRun
metadata:
name: step-action-run
spec:
params:
- name: notaction
value: "a github, mysterious or Task action"
- name: arrayparam
value:
- "hello, "
- "hi!!"
- name: objectparam
value:
bar: "chocolate bar"
TaskSpec:
#params:
# - name: objectparam
# properties:
# foo:
# type: string
# bar:
# type: string
# default:
# bar: "default bar"
steps:
- name: action-runner
ref:
name: step-action
params:
- name: not
value: $(params.notaction)
- name: array-param
value: $(params.arrayparam[*])
- name: object-param
value: $(params.objectparam[*])
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ type Step struct {
// Contains the reference to an existing StepAction.
//+optional
Ref *Ref `json:"ref,omitempty"`
// Parameters declares parameters passed to this step action.
// +optional
// +listType=atomic
Params Params `json:"params,omitempty"`
}

// Ref can be used to refer to a specific instance of a StepAction.
Expand Down
21 changes: 20 additions & 1 deletion pkg/apis/pipeline/v1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions pkg/apis/pipeline/v1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,15 @@
"description": "OnError defines the exiting behavior of a container on error can be set to [ continue | stopAndFail ]",
"type": "string"
},
"params": {
"description": "Parameters declares parameters passed to this step action.",
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/v1.Param"
},
"x-kubernetes-list-type": "atomic"
},
"ref": {
"description": "Contains the reference to an existing StepAction.",
"$ref": "#/definitions/v1.Ref"
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/pipeline/v1/task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ func validateStep(ctx context.Context, s Step, names sets.String) (errs *apis.Fi
})
}
} else {
if len(s.Params) > 0 {
errs = errs.Also(&apis.FieldError{
Message: "params cannot be used without Ref",
Paths: []string{"params"},
})
}
if s.Image == "" {
errs = errs.Also(apis.ErrMissingField("Image"))
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/apis/pipeline/v1/task_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,16 @@ func TestTaskSpecStepActionReferenceValidate(t *testing.T) {
Name: "stepAction",
},
}},
}, {
name: "valid use of params with Ref",
Steps: []v1.Step{{
Ref: &v1.Ref{
Name: "stepAction",
},
Params: v1.Params{{
Name: "param",
}},
}},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1490,6 +1500,19 @@ func TestTaskSpecValidateErrorWithStepActionRef(t *testing.T) {
Message: "env cannot be used with Ref",
Paths: []string{"steps[0].env"},
},
}, {
name: "Cannot use params without Ref",
Steps: []v1.Step{{
Image: "my-image",
Params: v1.Params{{
Name: "param",
}},
}},
enableStepActions: true,
expectedError: apis.FieldError{
Message: "params cannot be used without Ref",
Paths: []string{"steps[0].params"},
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/pipeline/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/reconciler/pipelinerun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ func propagateParams(t v1.PipelineTask, stringReplacements map[string]string, ar
}
}
}
t.TaskSpec.TaskSpec = *resources.ApplyReplacements(&t.TaskSpec.TaskSpec, stringReplacementsDup, arrayReplacementsDup)
t.TaskSpec.TaskSpec = *resources.ApplyReplacements(&t.TaskSpec.TaskSpec, stringReplacementsDup, arrayReplacementsDup, objectReplacementsDup)
} else {
t.TaskSpec.TaskSpec = *resources.ApplyReplacements(&t.TaskSpec.TaskSpec, stringReplacements, arrayReplacements)
t.TaskSpec.TaskSpec = *resources.ApplyReplacements(&t.TaskSpec.TaskSpec, stringReplacements, arrayReplacements, objectReplacements)
}
return t
}
Expand All @@ -395,7 +395,7 @@ func PropagateResults(rpt *ResolvedPipelineTask, runStates PipelineRunState) {
}
}
}
rpt.ResolvedTask.TaskSpec = resources.ApplyReplacements(rpt.ResolvedTask.TaskSpec, stringReplacements, arrayReplacements)
rpt.ResolvedTask.TaskSpec = resources.ApplyReplacements(rpt.ResolvedTask.TaskSpec, stringReplacements, arrayReplacements, map[string]map[string]string{})
}

// ApplyTaskResultsToPipelineResults applies the results of completed TasksRuns and Runs to a Pipeline's
Expand Down
Loading

0 comments on commit 7112cad

Please sign in to comment.