Skip to content

Commit

Permalink
Replace tmpfile with scriptfile in script init container
Browse files Browse the repository at this point in the history
Prior to this commit script blocks were written to a file
named with a variable called "tmpfile". This wasn't very
explicit and made understanding taskrun pod yaml a bit
harder.

This commit changes the variable name from "tmpfile" to
"scriptfile" to more explicitly declare the variable's
purpose.
  • Loading branch information
Scott authored and tekton-robot committed Jun 15, 2021
1 parent 584b527 commit 10079c9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
32 changes: 16 additions & 16 deletions pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,12 @@ func TestPodBuild(t *testing.T) {
Image: "busybox",
Command: []string{"sh"},
VolumeMounts: []corev1.VolumeMount{scriptsVolumeMount, toolsMount},
Args: []string{"-c", `tmpfile="/tekton/scripts/sidecar-script-0-9l9zj"
touch ${tmpfile} && chmod +x ${tmpfile}
cat > ${tmpfile} << '_EOF_'
Args: []string{"-c", `scriptfile="/tekton/scripts/sidecar-script-0-9l9zj"
touch ${scriptfile} && chmod +x ${scriptfile}
cat > ${scriptfile} << '_EOF_'
IyEvYmluL3NoCmVjaG8gaGVsbG8gZnJvbSBzaWRlY2Fy
_EOF_
/tekton/tools/entrypoint decode-script "${tmpfile}"
/tekton/tools/entrypoint decode-script "${scriptfile}"
`},
},
},
Expand Down Expand Up @@ -784,18 +784,18 @@ print("Hello from Python")`,
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} << '_EOF_'
Args: []string{"-c", `scriptfile="/tekton/scripts/script-0-9l9zj"
touch ${scriptfile} && chmod +x ${scriptfile}
cat > ${scriptfile} << '_EOF_'
IyEvYmluL3NoCmVjaG8gaGVsbG8gZnJvbSBzdGVwIG9uZQ==
_EOF_
/tekton/tools/entrypoint decode-script "${tmpfile}"
tmpfile="/tekton/scripts/script-1-mz4c7"
touch ${tmpfile} && chmod +x ${tmpfile}
cat > ${tmpfile} << '_EOF_'
/tekton/tools/entrypoint decode-script "${scriptfile}"
scriptfile="/tekton/scripts/script-1-mz4c7"
touch ${scriptfile} && chmod +x ${scriptfile}
cat > ${scriptfile} << '_EOF_'
IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCnByaW50KCJIZWxsbyBmcm9tIFB5dGhvbiIp
_EOF_
/tekton/tools/entrypoint decode-script "${tmpfile}"
/tekton/tools/entrypoint decode-script "${scriptfile}"
`},
VolumeMounts: []corev1.VolumeMount{scriptsVolumeMount, toolsMount},
},
Expand Down Expand Up @@ -903,12 +903,12 @@ _EOF_
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} << '_EOF_'
Args: []string{"-c", `scriptfile="/tekton/scripts/script-0-9l9zj"
touch ${scriptfile} && chmod +x ${scriptfile}
cat > ${scriptfile} << '_EOF_'
IyEvYmluL3NoCiQk
_EOF_
/tekton/tools/entrypoint decode-script "${tmpfile}"
/tekton/tools/entrypoint decode-script "${scriptfile}"
`},
VolumeMounts: []corev1.VolumeMount{scriptsVolumeMount, toolsMount},
}},
Expand Down
14 changes: 7 additions & 7 deletions pkg/pod/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,22 @@ func convertListOfSteps(steps []v1beta1.Step, initContainer *corev1.Container, p

// 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)))
scriptFile := filepath.Join(scriptsDir, names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("%s-%d", namePrefix, i)))
heredoc := "_EOF_" // underscores because base64 doesnt include them in its alphabet
initContainer.Args[1] += fmt.Sprintf(`tmpfile="%s"
touch ${tmpfile} && chmod +x ${tmpfile}
cat > ${tmpfile} << '%s'
initContainer.Args[1] += fmt.Sprintf(`scriptfile="%s"
touch ${scriptfile} && chmod +x ${scriptfile}
cat > ${scriptfile} << '%s'
%s
%s
/tekton/tools/entrypoint decode-script "${tmpfile}"
`, tmpFile, heredoc, script, heredoc)
/tekton/tools/entrypoint decode-script "${scriptfile}"
`, scriptFile, heredoc, script, heredoc)

// Set the command to execute the correct script in the mounted
// volume.
// A previous merge with stepTemplate may have populated
// Command and Args, even though this is not normally valid, so
// we'll clear out the Args and overwrite Command.
steps[i].Command = []string{tmpFile}
steps[i].Command = []string{scriptFile}
steps[i].VolumeMounts = append(steps[i].VolumeMounts, scriptsVolumeMount)
containers = append(containers, steps[i].Container)
}
Expand Down
48 changes: 24 additions & 24 deletions pkg/pod/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,24 @@ script-3`,
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} << '_EOF_'
Args: []string{"-c", `scriptfile="/tekton/scripts/script-0-9l9zj"
touch ${scriptfile} && chmod +x ${scriptfile}
cat > ${scriptfile} << '_EOF_'
IyEvYmluL3NoCnNjcmlwdC0x
_EOF_
/tekton/tools/entrypoint decode-script "${tmpfile}"
tmpfile="/tekton/scripts/script-2-mz4c7"
touch ${tmpfile} && chmod +x ${tmpfile}
cat > ${tmpfile} << '_EOF_'
/tekton/tools/entrypoint decode-script "${scriptfile}"
scriptfile="/tekton/scripts/script-2-mz4c7"
touch ${scriptfile} && chmod +x ${scriptfile}
cat > ${scriptfile} << '_EOF_'
CiMhL2Jpbi9zaApzY3JpcHQtMw==
_EOF_
/tekton/tools/entrypoint decode-script "${tmpfile}"
tmpfile="/tekton/scripts/script-3-mssqb"
touch ${tmpfile} && chmod +x ${tmpfile}
cat > ${tmpfile} << '_EOF_'
/tekton/tools/entrypoint decode-script "${scriptfile}"
scriptfile="/tekton/scripts/script-3-mssqb"
touch ${scriptfile} && chmod +x ${scriptfile}
cat > ${scriptfile} << '_EOF_'
IyEvYmluL3NoCnNldCAteGUKbm8tc2hlYmFuZw==
_EOF_
/tekton/tools/entrypoint decode-script "${tmpfile}"
/tekton/tools/entrypoint decode-script "${scriptfile}"
`},
VolumeMounts: []corev1.VolumeMount{scriptsVolumeMount, toolsMount},
}
Expand Down Expand Up @@ -247,24 +247,24 @@ sidecar-1`,
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} << '_EOF_'
Args: []string{"-c", `scriptfile="/tekton/scripts/script-0-9l9zj"
touch ${scriptfile} && chmod +x ${scriptfile}
cat > ${scriptfile} << '_EOF_'
IyEvYmluL3NoCnNjcmlwdC0x
_EOF_
/tekton/tools/entrypoint decode-script "${tmpfile}"
tmpfile="/tekton/scripts/script-2-mz4c7"
touch ${tmpfile} && chmod +x ${tmpfile}
cat > ${tmpfile} << '_EOF_'
/tekton/tools/entrypoint decode-script "${scriptfile}"
scriptfile="/tekton/scripts/script-2-mz4c7"
touch ${scriptfile} && chmod +x ${scriptfile}
cat > ${scriptfile} << '_EOF_'
IyEvYmluL3NoCnNjcmlwdC0z
_EOF_
/tekton/tools/entrypoint decode-script "${tmpfile}"
tmpfile="/tekton/scripts/sidecar-script-0-mssqb"
touch ${tmpfile} && chmod +x ${tmpfile}
cat > ${tmpfile} << '_EOF_'
/tekton/tools/entrypoint decode-script "${scriptfile}"
scriptfile="/tekton/scripts/sidecar-script-0-mssqb"
touch ${scriptfile} && chmod +x ${scriptfile}
cat > ${scriptfile} << '_EOF_'
IyEvYmluL3NoCnNpZGVjYXItMQ==
_EOF_
/tekton/tools/entrypoint decode-script "${tmpfile}"
/tekton/tools/entrypoint decode-script "${scriptfile}"
`},
VolumeMounts: []corev1.VolumeMount{scriptsVolumeMount, toolsMount},
}
Expand Down

0 comments on commit 10079c9

Please sign in to comment.