Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Fix issue with "$$" in Script blocks" #3938

Merged
merged 1 commit into from May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions examples/v1alpha1/taskruns/step-script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,3 @@ spec:
[[ $# == 2 ]]
[[ $1 == "hello" ]]
[[ $2 == "world" ]]

# Test that multiple dollar signs next to each other are not replaced by Kubernetes
- name: dollar-signs-allowed
image: python
script: |
#!/usr/bin/env python3
if '$' != '\u0024':
print('single dollar signs ($) are not passed through as expected :(')
exit(1)
if '$$' != '\u0024\u0024':
print('double dollar signs ($$) are not passed through as expected :(')
exit(2)
if '$$$' != '\u0024\u0024\u0024':
print('three dollar signs ($$$) are not passed through as expected :(')
exit(3)
if '$$$$' != '\u0024\u0024\u0024\u0024':
print('four dollar signs ($$$$) are not passed through as expected :(')
exit(3)
print('dollar signs appear to be handled correctly! :)')
19 changes: 0 additions & 19 deletions examples/v1beta1/taskruns/step-script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,3 @@ spec:
[[ $# == 2 ]]
[[ $1 == "hello" ]]
[[ $2 == "world" ]]

# Test that multiple dollar signs next to each other are not replaced by Kubernetes
- name: dollar-signs-allowed
image: python
script: |
#!/usr/bin/env python3
if '$' != '\u0024':
print('single dollar signs ($) are not passed through as expected :(')
exit(1)
if '$$' != '\u0024\u0024':
print('double dollar signs ($$) are not passed through as expected :(')
exit(2)
if '$$$' != '\u0024\u0024\u0024':
print('three dollar signs ($$$) are not passed through as expected :(')
exit(3)
if '$$$$' != '\u0024\u0024\u0024\u0024':
print('four dollar signs ($$$$) are not passed through as expected :(')
exit(3)
print('dollar signs appear to be handled correctly! :)')
61 changes: 0 additions & 61 deletions pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,67 +889,6 @@ script-heredoc-randomly-generated-78c5n
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
}, {
desc: "step with script that uses two dollar signs",
ts: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{
Container: corev1.Container{
Name: "one",
Image: "image",
},
Script: "#!/bin/sh\n$$",
}},
},
want: &corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
InitContainers: []corev1.Container{
{
Name: "place-scripts",
Image: images.ShellImage,
Command: []string{"sh"},
Args: []string{"-c", `tmpfile="/tekton/scripts/script-0-9l9zj"
touch ${tmpfile} && chmod +x ${tmpfile}
cat > ${tmpfile} << 'script-heredoc-randomly-generated-mz4c7'
#!/bin/sh
$$$$
script-heredoc-randomly-generated-mz4c7
`},
VolumeMounts: []corev1.VolumeMount{scriptsVolumeMount},
},
{
Name: "place-tools",
Image: images.EntrypointImage,
Command: []string{"/ko-app/entrypoint", "cp", "/ko-app/entrypoint", "/tekton/tools/entrypoint"},
VolumeMounts: []corev1.VolumeMount{toolsMount},
}},
Containers: []corev1.Container{{
Name: "step-one",
Image: "image",
Command: []string{"/tekton/tools/entrypoint"},
Args: []string{
"-wait_file",
"/tekton/downward/ready",
"-wait_file_content",
"-post_file",
"/tekton/tools/0",
"-termination_path",
"/tekton/termination",
"-entrypoint",
"/tekton/scripts/script-0-9l9zj",
"--",
},
VolumeMounts: append([]corev1.VolumeMount{scriptsVolumeMount, toolsMount, downwardMount, {
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
Resources: corev1.ResourceRequirements{Requests: allZeroQty()},
TerminationMessagePath: "/tekton/termination",
}},
Volumes: append(implicitVolumes, scriptsVolume, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
}, {
desc: "using another scheduler",
ts: v1beta1.TaskSpec{
Expand Down
6 changes: 0 additions & 6 deletions pkg/pod/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ func convertListOfSteps(steps []v1beta1.Step, initContainer *corev1.Container, p
// non-nil init container.
*placeScripts = true

// Kubernetes replaces instances of "$$" with "$". So we double-up
// on these instances in our args and Kubernetes reduces them back down
// to the expected number of dollar signs. This is a workaround for
// https://github.com/kubernetes/kubernetes/issues/101137
script = strings.ReplaceAll(script, "$$", "$$$$")

// Append to the place-scripts script to place the
// script file in a known location in the scripts volume.
tmpFile := filepath.Join(scriptsDir, names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("%s-%d", namePrefix, i)))
Expand Down