Skip to content

Commit 32cba17

Browse files
imjasonhtekton-robot
authored andcommitted
Support stepTemplate alongside script mode
MergeStepsWithStepTemplate now takes into account a step Script, instead of zeroing it out. There's still room for improvement here; Merge can happen after script conversion, if script mode is able to accept template-provided args.
1 parent ec9db68 commit 32cba17

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

pkg/apis/pipeline/v1alpha1/merge.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ func MergeStepsWithStepTemplate(template *v1.Container, steps []Step) ([]Step, e
8484
merged.Args = []string{}
8585
}
8686

87-
steps[i] = Step{Container: *merged}
87+
// Pass through original step Script, for later conversion.
88+
steps[i] = Step{Container: *merged, Script: s.Script}
8889
}
8990
return steps, nil
9091
}

pkg/pod/entrypoint_lookup_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package pod
1818

1919
import (
20-
"errors"
2120
"fmt"
2221
"testing"
2322

@@ -92,7 +91,7 @@ func (f fakeCache) Get(imageName, _, _ string) ([]string, name.Digest, error) {
9291

9392
d, found := f[imageName]
9493
if !found {
95-
return nil, name.Digest{}, errors.New("not found")
94+
return nil, name.Digest{}, fmt.Errorf("Image %q not found", imageName)
9695
}
9796
if d.seen {
9897
return nil, name.Digest{}, fmt.Errorf("Image %q was already looked up!", imageName)

pkg/pod/pod_test.go

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,12 @@ func TestMakePod(t *testing.T) {
479479
Volumes: append(implicitVolumes, toolsVolume, downwardVolume),
480480
},
481481
}, {
482-
desc: "step with script",
482+
desc: "step with script and stepTemplate",
483483
ts: v1alpha1.TaskSpec{
484+
StepTemplate: &corev1.Container{
485+
Env: []corev1.EnvVar{{Name: "FOO", Value: "bar"}},
486+
Args: []string{"template", "args"},
487+
},
484488
Steps: []v1alpha1.Step{{
485489
Container: corev1.Container{
486490
Name: "one",
@@ -495,6 +499,12 @@ func TestMakePod(t *testing.T) {
495499
},
496500
Script: `#!/usr/bin/env python
497501
print("Hello from Python")`,
502+
}, {
503+
Container: corev1.Container{
504+
Name: "regular-step",
505+
Image: "image",
506+
Command: []string{"regular", "command"},
507+
},
498508
}},
499509
},
500510
want: &corev1.PodSpec{
@@ -537,7 +547,7 @@ script-heredoc-randomly-generated-6nl7g
537547
"/tekton/scripts/script-0-mz4c7",
538548
"--",
539549
},
540-
Env: implicitEnvVars,
550+
Env: append(implicitEnvVars, corev1.EnvVar{Name: "FOO", Value: "bar"}),
541551
VolumeMounts: append([]corev1.VolumeMount{scriptsVolumeMount, toolsMount, downwardMount}, implicitVolumeMounts...),
542552
WorkingDir: workspaceDir,
543553
Resources: corev1.ResourceRequirements{
@@ -560,7 +570,7 @@ script-heredoc-randomly-generated-6nl7g
560570
"/tekton/scripts/script-1-78c5n",
561571
"--",
562572
},
563-
Env: implicitEnvVars,
573+
Env: append(implicitEnvVars, corev1.EnvVar{Name: "FOO", Value: "bar"}),
564574
VolumeMounts: append([]corev1.VolumeMount{{Name: "i-have-a-volume-mount"}, scriptsVolumeMount, toolsMount}, implicitVolumeMounts...),
565575
WorkingDir: workspaceDir,
566576
Resources: corev1.ResourceRequirements{
@@ -570,6 +580,32 @@ script-heredoc-randomly-generated-6nl7g
570580
corev1.ResourceEphemeralStorage: resource.MustParse("0"),
571581
},
572582
},
583+
}, {
584+
Name: "step-regular-step",
585+
Image: "image",
586+
Command: []string{"/tekton/tools/entrypoint"},
587+
Args: []string{
588+
"-wait_file",
589+
"/tekton/tools/1",
590+
"-post_file",
591+
"/tekton/tools/2",
592+
"-entrypoint",
593+
"regular",
594+
"--",
595+
"command",
596+
"template",
597+
"args",
598+
},
599+
Env: append(implicitEnvVars, corev1.EnvVar{Name: "FOO", Value: "bar"}),
600+
VolumeMounts: append([]corev1.VolumeMount{toolsMount}, implicitVolumeMounts...),
601+
WorkingDir: workspaceDir,
602+
Resources: corev1.ResourceRequirements{
603+
Requests: corev1.ResourceList{
604+
corev1.ResourceCPU: resource.MustParse("0"),
605+
corev1.ResourceMemory: resource.MustParse("0"),
606+
corev1.ResourceEphemeralStorage: resource.MustParse("0"),
607+
},
608+
},
573609
}},
574610
Volumes: append(implicitVolumes, scriptsVolume, toolsVolume, downwardVolume),
575611
},
@@ -604,10 +640,10 @@ script-heredoc-randomly-generated-6nl7g
604640
},
605641
Spec: c.trs,
606642
}
607-
entrypointCache, err := NewEntrypointCache(kubeclient)
608-
if err != nil {
609-
t.Fatalf("NewEntrypointCache: %v", err)
610-
}
643+
644+
// No entrypoints should be looked up.
645+
entrypointCache := fakeCache{}
646+
611647
got, err := MakePod(images, tr, c.ts, kubeclient, entrypointCache)
612648
if err != nil {
613649
t.Fatalf("MakePod: %v", err)

pkg/pod/script.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,13 @@ cat > ${tmpfile} << '%s'
9090
%s
9191
`, tmpFile, heredoc, s.Script, heredoc)
9292

93-
// Set the command to execute the correct script in the mounted volume.
93+
// Set the command to execute the correct script in the mounted
94+
// volume.
95+
// A previous merge with stepTemplate may have populated
96+
// Command and Args, even though this is not normally valid, so
97+
// we'll clear out the Args and overwrite Command.
9498
steps[i].Command = []string{tmpFile}
99+
steps[i].Args = nil // TODO(#1652): Don't overwrite this.
95100
steps[i].VolumeMounts = append(steps[i].VolumeMounts, scriptsVolumeMount)
96101
containers = append(containers, steps[i].Container)
97102
}

0 commit comments

Comments
 (0)