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

Set defaults for Tasks embedded in TaskRuns #1431

Merged
merged 1 commit into from
Oct 16, 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
1 change: 0 additions & 1 deletion examples/pipelineruns/conditional-pipelinerun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ metadata:
spec:
params:
- name: "path"
type: string
resources:
- name: workspace
type: git
Expand Down
3 changes: 0 additions & 3 deletions examples/taskruns/steptemplate-env-merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ spec:
params:
- name: FOO
description: FOO variable
type: string
- name: BAR
description: BAR variable
type: string
- name: FOOBAR
description: FOOBAR variable
default: foobar
type: string
steps:
# Test the environment variables are set in the task
- name: foo
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/pipeline/v1alpha1/taskrun_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ func (trs *TaskRunSpec) SetDefaults(ctx context.Context) {
if trs.ServiceAccountName == "" && defaultSA != "" {
trs.ServiceAccountName = defaultSA
}

// If this taskrun has an embedded task, apply the usual task defaults
if trs.TaskSpec != nil {
trs.TaskSpec.SetDefaults(ctx)
}
}
76 changes: 47 additions & 29 deletions pkg/apis/pipeline/v1alpha1/taskrun_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,58 @@ func TestTaskRunSpec_SetDefaults(t *testing.T) {
desc string
trs *v1alpha1.TaskRunSpec
want *v1alpha1.TaskRunSpec
}{
{
desc: "taskref is nil",
trs: &v1alpha1.TaskRunSpec{
TaskRef: nil,
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
want: &v1alpha1.TaskRunSpec{
TaskRef: nil,
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
}{{
desc: "taskref is nil",
trs: &v1alpha1.TaskRunSpec{
TaskRef: nil,
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
{
desc: "taskref kind is empty",
trs: &v1alpha1.TaskRunSpec{
TaskRef: &v1alpha1.TaskRef{},
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
want: &v1alpha1.TaskRunSpec{
TaskRef: &v1alpha1.TaskRef{Kind: v1alpha1.NamespacedTaskKind},
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
want: &v1alpha1.TaskRunSpec{
TaskRef: nil,
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
}, {
desc: "taskref kind is empty",
trs: &v1alpha1.TaskRunSpec{
TaskRef: &v1alpha1.TaskRef{},
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
want: &v1alpha1.TaskRunSpec{
TaskRef: &v1alpha1.TaskRef{Kind: v1alpha1.NamespacedTaskKind},
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
}, {
desc: "timeout is nil",
trs: &v1alpha1.TaskRunSpec{
TaskRef: &v1alpha1.TaskRef{Kind: v1alpha1.ClusterTaskKind},
},
want: &v1alpha1.TaskRunSpec{
TaskRef: &v1alpha1.TaskRef{Kind: v1alpha1.ClusterTaskKind},
Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute},
},
{
desc: "timeout is nil",
trs: &v1alpha1.TaskRunSpec{
TaskRef: &v1alpha1.TaskRef{Kind: v1alpha1.ClusterTaskKind},
}, {
desc: "embedded taskSpec",
trs: &v1alpha1.TaskRunSpec{
TaskSpec: &v1alpha1.TaskSpec{
Inputs: &v1alpha1.Inputs{
Params: []v1alpha1.ParamSpec{{
Name: "param-name",
}},
},
},
want: &v1alpha1.TaskRunSpec{
TaskRef: &v1alpha1.TaskRef{Kind: v1alpha1.ClusterTaskKind},
Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute},
},
want: &v1alpha1.TaskRunSpec{
TaskSpec: &v1alpha1.TaskSpec{
Inputs: &v1alpha1.Inputs{
Params: []v1alpha1.ParamSpec{{
Name: "param-name",
Type: v1alpha1.ParamTypeString,
}},
},
},
Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute},
},
}
}}
for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
ctx := context.Background()
Expand Down