Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TaskParam and PipelineParam. #1037

Merged
merged 1 commit into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions pkg/apis/pipeline/v1alpha1/param_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2019 The Tekton Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

// ParamSpec defines arbitrary parameters needed beyond typed inputs (such as
// resources). Parameter values are provided by users as inputs on a TaskRun
// or PipelineRun.
type ParamSpec struct {
// Name declares the name by which a parameter is referenced.
Name string `json:"name"`
// Description is a user-facing description of the parameter that may be
// used to populate a UI.
// +optional
Description string `json:"description,omitempty"`
// Default is the value a parameter takes if no input value is supplied. If
// default is set, a Task may be executed without a supplied value for the
// parameter.
// +optional
Default string `json:"default,omitempty"`
}

// Param declares a value to use for the Param called Name.
type Param struct {
Name string `json:"name"`
Value string `json:"value"`
}
17 changes: 1 addition & 16 deletions pkg/apis/pipeline/v1alpha1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type PipelineSpec struct {
Tasks []PipelineTask `json:"tasks,omitempty"`
// Params declares a list of input parameters that must be supplied when
// this Pipeline is run.
Params []PipelineParam `json:"params,omitempty"`
Params []ParamSpec `json:"params,omitempty"`
}

// PipelineStatus does not contain anything because Pipelines on their own
Expand Down Expand Up @@ -107,21 +107,6 @@ type PipelineTaskParam struct {
Value string `json:"value"`
}

// PipelineParam defines an arbitrary parameter needed by a Pipeline beyond typed inputs
// such as resources.
type PipelineParam struct {
// Name is the name of the parameter.
Name string `json:"name"`
// Description is an informational description of what the parameter
// represents.
// +optional
Description string `json:"description,omitempty"`
// Default specifies the value that this parameter should take if a value is
// not specified in a PipelineRun.
// +optional
Default string `json:"default,omitempty"`
}

// PipelineDeclaredResource is used by a Pipeline to declare the types of the
// PipelineResources that it will required to run and names which can be used to
// refer to these PipelineResources in PipelineTaskResourceBindings.
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1alpha1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (ps *PipelineSpec) Validate(ctx context.Context) *apis.FieldError {
return nil
}

func validatePipelineParameterVariables(tasks []PipelineTask, params []PipelineParam) *apis.FieldError {
func validatePipelineParameterVariables(tasks []PipelineTask, params []ParamSpec) *apis.FieldError {
parameterNames := map[string]struct{}{}
for _, p := range params {
parameterNames[p.Name] = struct{}{}
Expand Down
27 changes: 1 addition & 26 deletions pkg/apis/pipeline/v1alpha1/task_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type Inputs struct {
// must be supplied as inputs in TaskRuns unless they declare a default
// value.
// +optional
Params []TaskParam `json:"params,omitempty"`
Params []ParamSpec `json:"params,omitempty"`
}

// TaskResource defines an input or output Resource declared as a requirement
Expand All @@ -127,31 +127,6 @@ type TaskResource struct {
OutputImageDir string `json:"outputImageDir"`
}

// TaskParam defines arbitrary parameters needed by a task beyond typed inputs
// such as resources. Parameter values are provided by users as inputs on a
// TaskRun.
type TaskParam struct {
// Name declares the name by which a parameter is referenced in the Task's
// definition. Parameters may be referenced by name in the definition of a
// Task's steps.
Name string `json:"name"`
// Description is a user-facing description of the parameter that may be
// used to populate a UI.
// +optional
Description string `json:"description,omitempty"`
// Default is the value a parameter takes if no input value is supplied. If
// default is set, a Task maybe be executed by a TaskRun that does not
// supply a value for the parameter.
// +optional
Default string `json:"default,omitempty"`
}

// Param declares a value to use for the Param called Name.
type Param struct {
Name string `json:"name"`
Value string `json:"value"`
}

// Outputs allow a task to declare what data the Build/Task will be producing,
// i.e. results such as logs and artifacts such as images.
type Outputs struct {
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/pipeline/v1alpha1/task_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestTaskSpecValidate(t *testing.T) {
fields: fields{
Inputs: &Inputs{
Resources: []TaskResource{validResource},
Params: []TaskParam{
Params: []ParamSpec{
{
Name: "task",
Description: "param",
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestTaskSpecValidate(t *testing.T) {
Name: "foo",
Type: PipelineResourceTypeImage,
}},
Params: []TaskParam{{
Params: []ParamSpec{{
Name: "baz",
}, {
Name: "foo-is-baz",
Expand Down Expand Up @@ -367,7 +367,7 @@ func TestTaskSpecValidateError(t *testing.T) {
name: "Inexistent param variable with existing",
fields: fields{
Inputs: &Inputs{
Params: []TaskParam{
Params: []ParamSpec{
{
Name: "foo",
Description: "param",
Expand Down
52 changes: 18 additions & 34 deletions 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.

2 changes: 1 addition & 1 deletion pkg/reconciler/v1alpha1/taskrun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

// ApplyParameters applies the params from a TaskRun.Input.Parameters to a TaskSpec
func ApplyParameters(spec *v1alpha1.TaskSpec, tr *v1alpha1.TaskRun, defaults ...v1alpha1.TaskParam) *v1alpha1.TaskSpec {
func ApplyParameters(spec *v1alpha1.TaskSpec, tr *v1alpha1.TaskRun, defaults ...v1alpha1.ParamSpec) *v1alpha1.TaskSpec {
// This assumes that the TaskRun inputs have been validated against what the Task requests.
replacements := map[string]string{}
// Set all the default replacements
Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/v1alpha1/taskrun/resources/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestApplyParameters(t *testing.T) {
type args struct {
ts *v1alpha1.TaskSpec
tr *v1alpha1.TaskRun
dp []v1alpha1.TaskParam
dp []v1alpha1.ParamSpec
}
tests := []struct {
name string
Expand Down Expand Up @@ -282,7 +282,7 @@ func TestApplyParameters(t *testing.T) {
},
},
},
dp: []v1alpha1.TaskParam{
dp: []v1alpha1.ParamSpec{
{
Name: "myimage",
Default: "replaced-image-name",
Expand All @@ -298,7 +298,7 @@ func TestApplyParameters(t *testing.T) {
args: args{
ts: simpleTaskSpec,
tr: &v1alpha1.TaskRun{},
dp: []v1alpha1.TaskParam{
dp: []v1alpha1.ParamSpec{
{
Name: "myimage",
Default: "mydefault",
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/v1alpha1/taskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func (c *Reconciler) createPod(tr *v1alpha1.TaskRun, rtr *resources.ResolvedTask
return nil, xerrors.Errorf("couldn't create redirected TaskSpec: %w", err)
}

var defaults []v1alpha1.TaskParam
var defaults []v1alpha1.ParamSpec
if ts.Inputs != nil {
defaults = append(defaults, ts.Inputs.Params...)
}
Expand Down
18 changes: 9 additions & 9 deletions test/builder/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type PipelineOp func(*v1alpha1.Pipeline)
// PipelineSpecOp is an operation which modify a PipelineSpec struct.
type PipelineSpecOp func(*v1alpha1.PipelineSpec)

// PipelineParamOp is an operation which modify a PipelineParam struct.
type PipelineParamOp func(*v1alpha1.PipelineParam)
// PipelineParamOp is an operation which modify a ParamSpec struct.
type PipelineParamOp func(*v1alpha1.ParamSpec)

// PipelineTaskOp is an operation which modify a PipelineTask struct.
type PipelineTaskOp func(*v1alpha1.PipelineTask)
Expand Down Expand Up @@ -110,28 +110,28 @@ func PipelineDeclaredResource(name string, t v1alpha1.PipelineResourceType) Pipe
}
}

// PipelineParam adds a param, with specified name, to the Spec.
// Any number of PipelineParam modifiers can be passed to transform it.
// ParamSpec adds a param, with specified name, to the Spec.
// Any number of ParamSpec modifiers can be passed to transform it.
func PipelineParam(name string, ops ...PipelineParamOp) PipelineSpecOp {
return func(ps *v1alpha1.PipelineSpec) {
pp := &v1alpha1.PipelineParam{Name: name}
pp := &v1alpha1.ParamSpec{Name: name}
for _, op := range ops {
op(pp)
}
ps.Params = append(ps.Params, *pp)
}
}

// PipelineParamDescription sets the description to the PipelineParam.
// PipelineParamDescription sets the description to the ParamSpec.
func PipelineParamDescription(desc string) PipelineParamOp {
return func(pp *v1alpha1.PipelineParam) {
return func(pp *v1alpha1.ParamSpec) {
pp.Description = desc
}
}

// PipelineParamDefault sets the default value to the PipelineParam.
// PipelineParamDefault sets the default value to the ParamSpec.
func PipelineParamDefault(value string) PipelineParamOp {
return func(pp *v1alpha1.PipelineParam) {
return func(pp *v1alpha1.ParamSpec) {
pp.Default = value
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/builder/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestPipeline(t *testing.T) {
Name: "my-only-image-resource",
Type: "image",
}},
Params: []v1alpha1.PipelineParam{{
Params: []v1alpha1.ParamSpec{{
Name: "first-param",
Default: "default-value",
Description: "default description",
Expand Down
16 changes: 8 additions & 8 deletions test/builder/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type InputsOp func(*v1alpha1.Inputs)
// OutputsOp is an operation which modify an Outputs struct.
type OutputsOp func(*v1alpha1.Outputs)

// TaskParamOp is an operation which modify a TaskParam struct.
type TaskParamOp func(*v1alpha1.TaskParam)
// TaskParamOp is an operation which modify a ParamSpec struct.
type TaskParamOp func(*v1alpha1.ParamSpec)

// TaskRunOp is an operation which modify a TaskRun struct.
type TaskRunOp func(*v1alpha1.TaskRun)
Expand Down Expand Up @@ -249,27 +249,27 @@ func OutputsResource(name string, resourceType v1alpha1.PipelineResourceType) Ou
}

// InputsParam adds a param, with specified name, to the Inputs.
// Any number of TaskParam modifier can be passed to transform it.
// Any number of ParamSpec modifier can be passed to transform it.
func InputsParam(name string, ops ...TaskParamOp) InputsOp {
return func(i *v1alpha1.Inputs) {
tp := &v1alpha1.TaskParam{Name: name}
tp := &v1alpha1.ParamSpec{Name: name}
for _, op := range ops {
op(tp)
}
i.Params = append(i.Params, *tp)
}
}

// ParamDescripiton sets the description to the TaskParam.
// ParamDescripiton sets the description to the ParamSpec.
func ParamDescription(desc string) TaskParamOp {
return func(tp *v1alpha1.TaskParam) {
return func(tp *v1alpha1.ParamSpec) {
tp.Description = desc
}
}

// ParamDefault sets the default value to the TaskParam.
// ParamDefault sets the default value to the ParamSpec.
func ParamDefault(value string) TaskParamOp {
return func(tp *v1alpha1.TaskParam) {
return func(tp *v1alpha1.ParamSpec) {
tp.Default = value
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/builder/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestTask(t *testing.T) {
Type: v1alpha1.PipelineResourceTypeGit,
TargetPath: "/foo/bar",
}},
Params: []v1alpha1.TaskParam{{Name: "param", Description: "mydesc", Default: "default"}},
Params: []v1alpha1.ParamSpec{{Name: "param", Description: "mydesc", Default: "default"}},
},
Outputs: &v1alpha1.Outputs{
Resources: []v1alpha1.TaskResource{{
Expand Down