Skip to content

Commit bb85571

Browse files
bobcatfishtekton-robot
authored andcommitted
Remove containerTemplate (now called stepTemplate) 👠
In #931 we added `stepTemplate` in addition to `containerTemplate` and this chagne went out with 0.5. In this release we can now remove containerTemplate completely. Fixes #977
1 parent d905b3e commit bb85571

File tree

11 files changed

+10
-156
lines changed

11 files changed

+10
-156
lines changed

‎docs/tasks.md

-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ following fields:
7777
available to your `Task`'s steps.
7878
- [`stepTemplate`](#step-template) - Specifies a `Container` step
7979
definition to use as the basis for all steps within your `Task`.
80-
- [`containerTemplate`](#step-template) - **deprecated** Previous name of `stepTemplate`.
8180

8281
[kubernetes-overview]:
8382
https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#required-fields
@@ -370,9 +369,6 @@ steps:
370369
value: "baz"
371370
```
372371

373-
_The field `containerTemplate` provides the same functionality but is **deprecated**
374-
and will be removed in a future release ([#977](https://github.com/tektoncd/pipeline/issues/977))._
375-
376372
### Templating
377373

378374
`Tasks` support templating using values from all [`inputs`](#inputs) and

‎pkg/apis/pipeline/v1alpha1/task_types.go

-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ type TaskSpec struct {
5656
// StepTemplate can be used as the basis for all step containers within the
5757
// Task, so that the steps inherit settings on the base container.
5858
StepTemplate *corev1.Container `json:"stepTemplate,omitempty"`
59-
60-
// ContainerTemplate is the deprecated previous name of the StepTemplate
61-
// field (#977).
62-
ContainerTemplate *corev1.Container `json:"containerTemplate,omitempty"`
6359
}
6460

6561
// Check that Task may be validated and defaulted.

‎pkg/apis/pipeline/v1alpha1/task_validation.go

-9
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,6 @@ func (ts *TaskSpec) Validate(ctx context.Context) *apis.FieldError {
5555
}
5656
}
5757

58-
// The ContainerTemplate field is deprecated (#977)
59-
mergedSteps, err = merge.CombineStepsWithStepTemplate(ts.ContainerTemplate, mergedSteps)
60-
if err != nil {
61-
return &apis.FieldError{
62-
Message: fmt.Sprintf("error merging containerTemplate and steps: %s", err),
63-
Paths: []string{"stepTemplate"},
64-
}
65-
}
66-
6758
if err := validateSteps(mergedSteps).ViaField("steps"); err != nil {
6859
return err
6960
}

‎pkg/apis/pipeline/v1alpha1/task_validation_test.go

+8-40
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ var invalidBuildSteps = []corev1.Container{{
5151

5252
func TestTaskSpecValidate(t *testing.T) {
5353
type fields struct {
54-
Inputs *v1alpha1.Inputs
55-
Outputs *v1alpha1.Outputs
56-
BuildSteps []corev1.Container
57-
StepTemplate *corev1.Container
58-
ContainerTemplate *corev1.Container
54+
Inputs *v1alpha1.Inputs
55+
Outputs *v1alpha1.Outputs
56+
BuildSteps []corev1.Container
57+
StepTemplate *corev1.Container
5958
}
6059
tests := []struct {
6160
name string
@@ -193,45 +192,14 @@ func TestTaskSpecValidate(t *testing.T) {
193192
Image: "some-image",
194193
},
195194
},
196-
}, {
197-
name: "deprecated (#977) container template included in validation",
198-
fields: fields{
199-
BuildSteps: []corev1.Container{{
200-
Name: "astep",
201-
Command: []string{"echo"},
202-
Args: []string{"hello"},
203-
}},
204-
ContainerTemplate: &corev1.Container{
205-
Image: "some-image",
206-
},
207-
},
208-
}, {
209-
name: "deprecated (#977) container template supported with step template",
210-
fields: fields{
211-
BuildSteps: []corev1.Container{{
212-
Name: "astep",
213-
Command: []string{"echo"},
214-
Args: []string{"hello"},
215-
}},
216-
StepTemplate: &corev1.Container{
217-
Env: []corev1.EnvVar{{
218-
Name: "somevar",
219-
Value: "someval",
220-
}},
221-
},
222-
ContainerTemplate: &corev1.Container{
223-
Image: "some-image",
224-
},
225-
},
226195
}}
227196
for _, tt := range tests {
228197
t.Run(tt.name, func(t *testing.T) {
229198
ts := &v1alpha1.TaskSpec{
230-
Inputs: tt.fields.Inputs,
231-
Outputs: tt.fields.Outputs,
232-
Steps: tt.fields.BuildSteps,
233-
StepTemplate: tt.fields.StepTemplate,
234-
ContainerTemplate: tt.fields.ContainerTemplate,
199+
Inputs: tt.fields.Inputs,
200+
Outputs: tt.fields.Outputs,
201+
Steps: tt.fields.BuildSteps,
202+
StepTemplate: tt.fields.StepTemplate,
235203
}
236204
ctx := context.Background()
237205
ts.SetDefaults(ctx)

‎pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go

-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pkg/reconciler/v1alpha1/taskrun/resources/apply.go

-6
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ func ApplyReplacements(spec *v1alpha1.TaskSpec, stringReplacements map[string]st
9797
templating.ApplyContainerReplacements(&steps[i], stringReplacements, arrayReplacements)
9898
}
9999

100-
// Apply variable expansion to containerTemplate fields.
101-
// Should eventually be removed; ContainerTemplate is the deprecated previous name of the StepTemplate field (#977).
102-
if spec.ContainerTemplate != nil {
103-
templating.ApplyContainerReplacements(spec.ContainerTemplate, stringReplacements, arrayReplacements)
104-
}
105-
106100
// Apply variable expansion to stepTemplate fields.
107101
if spec.StepTemplate != nil {
108102
templating.ApplyContainerReplacements(spec.StepTemplate, stringReplacements, arrayReplacements)

‎pkg/reconciler/v1alpha1/taskrun/resources/apply_test.go

-47
Original file line numberDiff line numberDiff line change
@@ -95,27 +95,6 @@ var envTaskSpec = &v1alpha1.TaskSpec{
9595
}},
9696
}
9797

98-
// containerTemplate is deprecated but is functional (and tested) for now (#977).
99-
var containerTemplateTaskSpec = &v1alpha1.TaskSpec{
100-
ContainerTemplate: &corev1.Container{
101-
Env: []corev1.EnvVar{{
102-
Name: "template-var",
103-
Value: "${inputs.params.FOO}",
104-
}},
105-
},
106-
Steps: []corev1.Container{{
107-
Name: "simple-image",
108-
Image: "${inputs.params.myimage}",
109-
}, {
110-
Name: "image-with-env-specified",
111-
Image: "some-other-image",
112-
Env: []corev1.EnvVar{{
113-
Name: "template-var",
114-
Value: "overridden-value",
115-
}},
116-
}},
117-
}
118-
11998
var stepTemplateTaskSpec = &v1alpha1.TaskSpec{
12099
StepTemplate: &corev1.Container{
121100
Env: []corev1.EnvVar{{
@@ -500,32 +479,6 @@ func TestApplyParameters(t *testing.T) {
500479
spec.Steps[0].EnvFrom[1].SecretRef.LocalObjectReference.Name = "secret-world"
501480
spec.Steps[0].Image = "busybox:world"
502481
}),
503-
}, {
504-
// containerTemplate is deprecated but is functional (and tested) for now (#977).
505-
name: "containerTemplate parameter",
506-
args: args{
507-
ts: containerTemplateTaskSpec,
508-
tr: &v1alpha1.TaskRun{
509-
Spec: v1alpha1.TaskRunSpec{
510-
Inputs: v1alpha1.TaskRunInputs{
511-
Params: []v1alpha1.Param{{
512-
Name: "FOO",
513-
Value: *builder.ArrayOrString("BAR"),
514-
}},
515-
},
516-
},
517-
},
518-
dp: []v1alpha1.ParamSpec{
519-
{
520-
Name: "myimage",
521-
Default: builder.ArrayOrString("replaced-image-name"),
522-
},
523-
},
524-
},
525-
want: applyMutation(containerTemplateTaskSpec, func(spec *v1alpha1.TaskSpec) {
526-
spec.ContainerTemplate.Env[0].Value = "BAR"
527-
spec.Steps[0].Image = "replaced-image-name"
528-
}),
529482
}, {
530483
name: "stepTemplate parameter",
531484
args: args{

‎pkg/reconciler/v1alpha1/taskrun/resources/pod.go

-10
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,6 @@ func MakePod(taskRun *v1alpha1.TaskRun, taskSpec v1alpha1.TaskSpec, kubeclient k
324324
return nil, err
325325
}
326326

327-
// The ContainerTemplate field is deprecated (#977)
328-
mergedInitContainers, err = merge.CombineStepsWithStepTemplate(taskSpec.ContainerTemplate, mergedInitContainers)
329-
if err != nil {
330-
return nil, err
331-
}
332-
mergedPodContainers, err = merge.CombineStepsWithStepTemplate(taskSpec.ContainerTemplate, mergedPodContainers)
333-
if err != nil {
334-
return nil, err
335-
}
336-
337327
podTemplate := v1alpha1.CombinedPodTemplate(taskRun.Spec.PodTemplate, taskRun.Spec.NodeSelector, taskRun.Spec.Tolerations, taskRun.Spec.Affinity)
338328

339329
return &corev1.Pod{

‎pkg/reconciler/v1alpha1/taskrun/taskrun_test.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ var (
100100
saTask = tb.Task("test-with-sa", "foo", tb.TaskSpec(tb.Step("sa-step", "foo", tb.Command("/mycmd"))))
101101

102102
taskEnvTask = tb.Task("test-task-env", "foo", tb.TaskSpec(
103-
// The ContainerTemplate field is deprecated (#977)
104-
tb.TaskContainerTemplate(
105-
tb.EnvVar("BREAD", "PUMPERNICKEL"),
106-
),
107103
tb.TaskStepTemplate(
108104
tb.EnvVar("FRUIT", "APPLE"),
109105
),
@@ -894,8 +890,8 @@ func TestReconcile(t *testing.T) {
894890
tb.PodSpec(
895891
tb.PodVolumes(toolsVolume, downward, workspaceVolume, homeVolume),
896892
tb.PodRestartPolicy(corev1.RestartPolicyNever),
897-
getCredentialsInitContainer("9l9zj", tb.EnvVar("FRUIT", "APPLE"), tb.EnvVar("BREAD", "PUMPERNICKEL")),
898-
getPlaceToolsInitContainer(tb.EnvVar("FRUIT", "APPLE"), tb.EnvVar("BREAD", "PUMPERNICKEL")),
893+
getCredentialsInitContainer("9l9zj", tb.EnvVar("FRUIT", "APPLE")),
894+
getPlaceToolsInitContainer(tb.EnvVar("FRUIT", "APPLE")),
899895
tb.PodContainer("step-env-step", "foo", tb.Command(entrypointLocation),
900896
tb.Command(entrypointLocation),
901897
tb.Args("-wait_file", "/builder/downward/ready", "-post_file", "/builder/tools/0", "-wait_file_content", "-entrypoint", "/mycmd", "--"),
@@ -912,7 +908,6 @@ func TestReconcile(t *testing.T) {
912908
tb.VolumeMount("home", "/builder/home"),
913909
tb.EnvVar("ANOTHER", "VARIABLE"),
914910
tb.EnvVar("FRUIT", "LEMON"),
915-
tb.EnvVar("BREAD", "PUMPERNICKEL"),
916911
),
917912
),
918913
),

‎test/builder/task.go

-13
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,6 @@ func TaskStepTemplate(ops ...ContainerOp) TaskSpecOp {
166166
}
167167
}
168168

169-
// TaskContainerTemplate adds the deprecated (#977) base container for
170-
// all steps in the task. ContainerTemplate is now StepTemplate.
171-
func TaskContainerTemplate(ops ...ContainerOp) TaskSpecOp {
172-
return func(spec *v1alpha1.TaskSpec) {
173-
base := &corev1.Container{}
174-
175-
for _, op := range ops {
176-
op(base)
177-
}
178-
spec.ContainerTemplate = base
179-
}
180-
}
181-
182169
// TaskVolume adds a volume with specified name to the TaskSpec.
183170
// Any number of Volume modifier can be passed to transform it.
184171
func TaskVolume(name string, ops ...VolumeOp) TaskSpecOp {

‎test/builder/task_test.go

-11
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ func TestTask(t *testing.T) {
5757
tb.TaskStepTemplate(
5858
tb.EnvVar("FRUIT", "BANANA"),
5959
),
60-
// The ContainerTemplate field is deprecated (#977)
61-
tb.TaskContainerTemplate(
62-
tb.EnvVar("JUICE", "MELON"),
63-
),
6460
))
6561
expectedTask := &v1alpha1.Task{
6662
ObjectMeta: metav1.ObjectMeta{Name: "test-task", Namespace: "foo"},
@@ -106,13 +102,6 @@ func TestTask(t *testing.T) {
106102
Value: "BANANA",
107103
}},
108104
},
109-
// The ContainerTemplate field is deprecated (#977)
110-
ContainerTemplate: &corev1.Container{
111-
Env: []corev1.EnvVar{{
112-
Name: "JUICE",
113-
Value: "MELON",
114-
}},
115-
},
116105
},
117106
}
118107
if d := cmp.Diff(expectedTask, task); d != "" {

0 commit comments

Comments
 (0)