Skip to content

Commit 255b52d

Browse files
Scotttekton-robot
authored andcommitted
Revert "Fix issue with "$$" in Script blocks"
This reverts commit 9a9f896. Attempting to fix instances of "$$" introduced a new bug in the way bash scripts are interpreted: #3935
1 parent b86a9a2 commit 255b52d

File tree

4 files changed

+0
-105
lines changed

4 files changed

+0
-105
lines changed

examples/v1alpha1/taskruns/step-script.yaml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,3 @@ spec:
9797
[[ $# == 2 ]]
9898
[[ $1 == "hello" ]]
9999
[[ $2 == "world" ]]
100-
101-
# Test that multiple dollar signs next to each other are not replaced by Kubernetes
102-
- name: dollar-signs-allowed
103-
image: python
104-
script: |
105-
#!/usr/bin/env python3
106-
if '$' != '\u0024':
107-
print('single dollar signs ($) are not passed through as expected :(')
108-
exit(1)
109-
if '$$' != '\u0024\u0024':
110-
print('double dollar signs ($$) are not passed through as expected :(')
111-
exit(2)
112-
if '$$$' != '\u0024\u0024\u0024':
113-
print('three dollar signs ($$$) are not passed through as expected :(')
114-
exit(3)
115-
if '$$$$' != '\u0024\u0024\u0024\u0024':
116-
print('four dollar signs ($$$$) are not passed through as expected :(')
117-
exit(3)
118-
print('dollar signs appear to be handled correctly! :)')

examples/v1beta1/taskruns/step-script.yaml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,3 @@ spec:
9696
[[ $# == 2 ]]
9797
[[ $1 == "hello" ]]
9898
[[ $2 == "world" ]]
99-
100-
# Test that multiple dollar signs next to each other are not replaced by Kubernetes
101-
- name: dollar-signs-allowed
102-
image: python
103-
script: |
104-
#!/usr/bin/env python3
105-
if '$' != '\u0024':
106-
print('single dollar signs ($) are not passed through as expected :(')
107-
exit(1)
108-
if '$$' != '\u0024\u0024':
109-
print('double dollar signs ($$) are not passed through as expected :(')
110-
exit(2)
111-
if '$$$' != '\u0024\u0024\u0024':
112-
print('three dollar signs ($$$) are not passed through as expected :(')
113-
exit(3)
114-
if '$$$$' != '\u0024\u0024\u0024\u0024':
115-
print('four dollar signs ($$$$) are not passed through as expected :(')
116-
exit(3)
117-
print('dollar signs appear to be handled correctly! :)')

pkg/pod/pod_test.go

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -889,67 +889,6 @@ script-heredoc-randomly-generated-78c5n
889889
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
890890
}),
891891
},
892-
}, {
893-
desc: "step with script that uses two dollar signs",
894-
ts: v1beta1.TaskSpec{
895-
Steps: []v1beta1.Step{{
896-
Container: corev1.Container{
897-
Name: "one",
898-
Image: "image",
899-
},
900-
Script: "#!/bin/sh\n$$",
901-
}},
902-
},
903-
want: &corev1.PodSpec{
904-
RestartPolicy: corev1.RestartPolicyNever,
905-
InitContainers: []corev1.Container{
906-
{
907-
Name: "place-scripts",
908-
Image: images.ShellImage,
909-
Command: []string{"sh"},
910-
Args: []string{"-c", `tmpfile="/tekton/scripts/script-0-9l9zj"
911-
touch ${tmpfile} && chmod +x ${tmpfile}
912-
cat > ${tmpfile} << 'script-heredoc-randomly-generated-mz4c7'
913-
#!/bin/sh
914-
$$$$
915-
script-heredoc-randomly-generated-mz4c7
916-
`},
917-
VolumeMounts: []corev1.VolumeMount{scriptsVolumeMount},
918-
},
919-
{
920-
Name: "place-tools",
921-
Image: images.EntrypointImage,
922-
Command: []string{"/ko-app/entrypoint", "cp", "/ko-app/entrypoint", "/tekton/tools/entrypoint"},
923-
VolumeMounts: []corev1.VolumeMount{toolsMount},
924-
}},
925-
Containers: []corev1.Container{{
926-
Name: "step-one",
927-
Image: "image",
928-
Command: []string{"/tekton/tools/entrypoint"},
929-
Args: []string{
930-
"-wait_file",
931-
"/tekton/downward/ready",
932-
"-wait_file_content",
933-
"-post_file",
934-
"/tekton/tools/0",
935-
"-termination_path",
936-
"/tekton/termination",
937-
"-entrypoint",
938-
"/tekton/scripts/script-0-9l9zj",
939-
"--",
940-
},
941-
VolumeMounts: append([]corev1.VolumeMount{scriptsVolumeMount, toolsMount, downwardMount, {
942-
Name: "tekton-creds-init-home-0",
943-
MountPath: "/tekton/creds",
944-
}}, implicitVolumeMounts...),
945-
Resources: corev1.ResourceRequirements{Requests: allZeroQty()},
946-
TerminationMessagePath: "/tekton/termination",
947-
}},
948-
Volumes: append(implicitVolumes, scriptsVolume, toolsVolume, downwardVolume, corev1.Volume{
949-
Name: "tekton-creds-init-home-0",
950-
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
951-
}),
952-
},
953892
}, {
954893
desc: "using another scheduler",
955894
ts: v1beta1.TaskSpec{

pkg/pod/script.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,6 @@ func convertListOfSteps(steps []v1beta1.Step, initContainer *corev1.Container, p
107107
// non-nil init container.
108108
*placeScripts = true
109109

110-
// Kubernetes replaces instances of "$$" with "$". So we double-up
111-
// on these instances in our args and Kubernetes reduces them back down
112-
// to the expected number of dollar signs. This is a workaround for
113-
// https://github.com/kubernetes/kubernetes/issues/101137
114-
script = strings.ReplaceAll(script, "$$", "$$$$")
115-
116110
// Append to the place-scripts script to place the
117111
// script file in a known location in the scripts volume.
118112
tmpFile := filepath.Join(scriptsDir, names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("%s-%d", namePrefix, i)))

0 commit comments

Comments
 (0)