Skip to content

Commit

Permalink
fix: debug scripts are not mounted to steps with no scripts
Browse files Browse the repository at this point in the history
Fix bug for issue tektoncd#4613

When script is empty then the logic which mount the debug script
will skip for container and the signal of placeScripts is the
default value false. Then no debug script volume will be mount.

But now will check breakpoint first and add volumeMount for
container if breakpoint is not null. And if breakpoint is not
null then will set the signal placeScripts to be true

Signed-off-by: yuzhipeng <[email protected]>
  • Loading branch information
yuzp1996 committed Apr 19, 2022
1 parent 8fdcc09 commit b97c1cd
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions pkg/pod/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,18 @@ func convertScripts(shellImageLinux string, shellImageWin string, steps []v1beta
func convertListOfSteps(steps []v1beta1.Step, initContainer *corev1.Container, placeScripts *bool, breakpoints []string, namePrefix string) []corev1.Container {
containers := []corev1.Container{}
for i, s := range steps {
// Add debug mounts if breakpoints are present
if len(breakpoints) > 0 {
debugInfoVolumeMount := corev1.VolumeMount{
Name: debugInfoVolumeName,
MountPath: filepath.Join(debugInfoDir, fmt.Sprintf("%d", i)),
}
steps[i].Container.VolumeMounts = append(steps[i].VolumeMounts, debugScriptsVolumeMount, debugInfoVolumeMount)
}

if s.Script == "" {
// Nothing to convert.
containers = append(containers, s.Container)
containers = append(containers, steps[i].Container)
continue
}

Expand Down Expand Up @@ -186,19 +195,15 @@ cat > ${scriptfile} << '%s'
}
steps[i].VolumeMounts = append(steps[i].VolumeMounts, scriptsVolumeMount)

// Add debug mounts if breakpoints are present
if len(breakpoints) > 0 {
debugInfoVolumeMount := corev1.VolumeMount{
Name: debugInfoVolumeName,
MountPath: filepath.Join(debugInfoDir, fmt.Sprintf("%d", i)),
}
steps[i].VolumeMounts = append(steps[i].VolumeMounts, debugScriptsVolumeMount, debugInfoVolumeMount)
}
containers = append(containers, steps[i].Container)
}

// Place debug scripts if breakpoints are enabled
if len(breakpoints) > 0 {
// If breakpoint is not nil then should add the init container
// to write debug script files
*placeScripts = true

type script struct {
name string
content string
Expand Down

0 comments on commit b97c1cd

Please sign in to comment.