Skip to content

Commit defef46

Browse files
committed
separate Step from Sidecar
separate Step from Sidecar Originally the Sidecar type is an alias of the Step type. Both #3013 and #1690 will require the two types to divert from each other. This commit separates the two types and updates code to accomodate convertListOfSteps() which originally depended on theses types to be the same. Partially based on: https://github.com/tektoncd/pipeline/pull/3013/files
1 parent 51dde91 commit defef46

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

pkg/apis/pipeline/v1beta1/task_types.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,16 @@ type Step struct {
125125
Script string `json:"script,omitempty"`
126126
}
127127

128-
// A sidecar has the same data structure as a Step, consisting of a Container, and optional Script.
129-
type Sidecar = Step
128+
// Sidecar embeds the Container type, which allows it to include fields not
129+
// provided by Container.
130+
type Sidecar struct {
131+
corev1.Container `json:",inline"`
132+
133+
// Script is the contents of an executable file to execute.
134+
//
135+
// If Script is not empty, the Step cannot have an Command or Args.
136+
Script string `json:"script,omitempty"`
137+
}
130138

131139
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
132140
// TaskList contains a list of Task

pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go

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

pkg/pod/script.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,17 @@ func convertScripts(shellImage string, steps []v1beta1.Step, sidecars []v1beta1.
6262
}
6363

6464
convertedStepContainers := convertListOfSteps(steps, &placeScriptsInit, &placeScripts, "script")
65-
sidecarContainers := convertListOfSteps(sidecars, &placeScriptsInit, &placeScripts, "sidecar-script")
65+
// convertListOfSteps operates on overlapping fields across Step and Sidecar, hence a conversion
66+
// from Sidecar into Step
67+
sideCarSteps := []v1beta1.Step{}
68+
for _, step := range sidecars {
69+
sidecarStep := v1beta1.Step{
70+
step.Container,
71+
step.Script,
72+
}
73+
sideCarSteps = append(sideCarSteps, sidecarStep)
74+
}
75+
sidecarContainers := convertListOfSteps(sideCarSteps, &placeScriptsInit, &placeScripts, "sidecar-script")
6676

6777
if placeScripts {
6878
return &placeScriptsInit, convertedStepContainers, sidecarContainers

pkg/pod/script_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestConvertScripts_NothingToConvert_EmptySidecars(t *testing.T) {
3535
Container: corev1.Container{
3636
Image: "step-2",
3737
},
38-
}}, []v1alpha1.Step{})
38+
}}, []v1alpha1.Sidecar{})
3939
want := []corev1.Container{{
4040
Image: "step-1",
4141
}, {
@@ -89,7 +89,7 @@ func TestConvertScripts_NothingToConvert_WithSidecar(t *testing.T) {
8989
Container: corev1.Container{
9090
Image: "step-2",
9191
},
92-
}}, []v1alpha1.Step{{
92+
}}, []v1alpha1.Sidecar{{
9393
Container: corev1.Container{
9494
Image: "sidecar-1",
9595
},
@@ -153,7 +153,7 @@ script-3`,
153153
VolumeMounts: preExistingVolumeMounts,
154154
Args: []string{"my", "args"},
155155
},
156-
}}, []v1alpha1.Step{})
156+
}}, []v1alpha1.Sidecar{})
157157
wantInit := &corev1.Container{
158158
Name: "place-scripts",
159159
Image: images.ShellImage,
@@ -241,7 +241,7 @@ script-3`,
241241
VolumeMounts: preExistingVolumeMounts,
242242
Args: []string{"my", "args"},
243243
},
244-
}}, []v1alpha1.Step{{
244+
}}, []v1alpha1.Sidecar{{
245245
Script: `#!/bin/sh
246246
sidecar-1`,
247247
Container: corev1.Container{Image: "sidecar-1"},

0 commit comments

Comments
 (0)