diff --git a/examples/pipelineruns/conditional-pipelinerun.yaml b/examples/pipelineruns/conditional-pipelinerun.yaml index dca8f52460d..3624bcd3637 100644 --- a/examples/pipelineruns/conditional-pipelinerun.yaml +++ b/examples/pipelineruns/conditional-pipelinerun.yaml @@ -5,7 +5,6 @@ metadata: spec: params: - name: "path" - type: string resources: - name: workspace type: git diff --git a/examples/taskruns/steptemplate-env-merge.yaml b/examples/taskruns/steptemplate-env-merge.yaml index 89b76b85bb7..77b1069f21e 100644 --- a/examples/taskruns/steptemplate-env-merge.yaml +++ b/examples/taskruns/steptemplate-env-merge.yaml @@ -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 diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_defaults.go b/pkg/apis/pipeline/v1alpha1/taskrun_defaults.go index c9384b1d231..5a6de5d1b22 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_defaults.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_defaults.go @@ -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) + } } diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_defaults_test.go b/pkg/apis/pipeline/v1alpha1/taskrun_defaults_test.go index b54753c2db0..04952310e9e 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_defaults_test.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_defaults_test.go @@ -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()