Skip to content

Commit

Permalink
Passed parameters from Pipeline to TaskRuns
Browse files Browse the repository at this point in the history
Turned out that the pipelinerun controller wasn't yet passing along
parameters which were supplied in Pipelines (for tektoncd#64).

Also removed unneeded `value` field from parameter delcaration.

Some remaining work that needs to be done:
- It should be an error to provide a parameter to a Task that it doesn't
need
- It should be an error to apply templating with required params not
supplied

Co-authored-by: Christie Wilson <[email protected]>
  • Loading branch information
nader-ziada and bobcatfish committed Oct 15, 2018
1 parent 5d286dd commit 4d892db
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ from is not known to a task, so they can be provided by a Pipeline or by a user
`Tasks` are basically [Knative BuildTemplates](https://github.com/knative/build-templates)
with additional input types and clearly defined outputs.

See [docs/task-parameters.md](./docs/task-parameters.md) for how to use parameters with Tasks.

### Pipeline

`Pipeline` describes a graph of [Tasks](#task) to execute. It defines the DAG
Expand Down
4 changes: 2 additions & 2 deletions docs/task-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Some example use-cases of this include:

The following example shows how Tasks can be parameterized, and these parameters can be passed to the `Task` from a `TaskRun`.

Input parameters in the form of `${inputs.foo}` are replaced inside of the buildSpec.
Input parameters in the form of `${inputs.params.foo}` are replaced inside of the buildSpec.

The following `Task` declares an input parameter called 'flags', and uses it in the `buildSpec.steps.args` list.

Expand All @@ -29,7 +29,7 @@ spec:
steps:
- name: build
image: my-builder
args: ['build', '--flags=${inputs.flags}']
args: ['build', '--flags=${inputs.params.flags}']
```
The following `TaskRun` supplies a value for `flags`:
Expand Down
9 changes: 7 additions & 2 deletions pkg/apis/pipeline/v1alpha1/task_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,19 @@ type Inputs struct {
// +optional
Resources []TaskResource `json:"resources,omitempty"`
// +optional
Params []Param `json:"params,omitempty"`
Params []TaskParam `json:"params,omitempty"`
// TODO(#68) a cluster and/or deployment should be a type of Resource
// +optional
Clusters []Cluster `json:"clusters,omitempty"`
}

// Param defines arbitrary parameters needed by a task beyond typed inputs
// TaskParam defines arbitrary parameters needed by a task beyond typed inputs
// such as resources.
type TaskParam struct {
Name string `json:"name"`
}

// Param declares a value to use for the Param called Name.
type Param struct {
Name string `json:"name"`
Value string `json:"value"`
Expand Down
18 changes: 17 additions & 1 deletion pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go

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

8 changes: 5 additions & 3 deletions pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1alpha1.PipelineRun) er
prtr := resources.GetNextTask(pr.Name, state, c.Logger)
if prtr != nil {
c.Logger.Infof("Creating a new TaskRun object %s", prtr.TaskRunName)
prtr.TaskRun, err = c.createTaskRun(prtr.Task, prtr.TaskRunName, pr)
prtr.TaskRun, err = c.createTaskRun(prtr.Task, prtr.TaskRunName, pr, prtr.PipelineTask)
if err != nil {
return fmt.Errorf("error creating TaskRun called %s for PipelineTask %s from PipelineRun %s: %s", prtr.TaskRunName, prtr.PipelineTask.Name, pr.Name, err)
}
Expand All @@ -194,8 +194,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1alpha1.PipelineRun) er
return nil
}

func (c *Reconciler) createTaskRun(t *v1alpha1.Task, trName string, pr *v1alpha1.PipelineRun) (*v1alpha1.TaskRun, error) {
// Create empty tasks
func (c *Reconciler) createTaskRun(t *v1alpha1.Task, trName string, pr *v1alpha1.PipelineRun, pt *v1alpha1.PipelineTask) (*v1alpha1.TaskRun, error) {
tr := &v1alpha1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Name: trName,
Expand All @@ -208,6 +207,9 @@ func (c *Reconciler) createTaskRun(t *v1alpha1.Task, trName string, pr *v1alpha1
TaskRef: v1alpha1.TaskRef{
Name: t.Name,
},
Inputs: v1alpha1.TaskRunInputs{
Params: pt.Params,
},
},
}
return c.PipelineClientSet.PipelineV1alpha1().TaskRuns(t.Namespace).Create(tr)
Expand Down
20 changes: 19 additions & 1 deletion pkg/reconciler/v1alpha1/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func TestReconcile(t *testing.T) {
Spec: v1alpha1.PipelineSpec{Tasks: []v1alpha1.PipelineTask{{
Name: "unit-test-1",
TaskRef: v1alpha1.TaskRef{Name: "unit-test-task"},
Params: []v1alpha1.Param{{
Name: "foo",
Value: "somethingfun",
}},
}},
}},
}
Expand All @@ -62,7 +66,15 @@ func TestReconcile(t *testing.T) {
Name: "unit-test-task",
Namespace: "foo",
},
Spec: v1alpha1.TaskSpec{},
Spec: v1alpha1.TaskSpec{
Inputs: &v1alpha1.Inputs{
Params: []v1alpha1.TaskParam{{
Name: "foo",
}, {
Name: "bar",
}},
},
},
}}
d := testData{
prs: prs,
Expand Down Expand Up @@ -110,6 +122,12 @@ func TestReconcile(t *testing.T) {
TaskRef: v1alpha1.TaskRef{
Name: "unit-test-task",
},
Inputs: v1alpha1.TaskRunInputs{
Params: []v1alpha1.Param{{
Name: "foo",
Value: "somethingfun",
}},
},
},
}
if d := cmp.Diff(actual, expectedTaskRun); d != "" {
Expand Down

0 comments on commit 4d892db

Please sign in to comment.