Skip to content

Commit

Permalink
Automatically create named directories for each output resource in a …
Browse files Browse the repository at this point in the history
…TaskRun.

TaskRuns are expected to place files related to an Output in a directory named
for each Output. Right now, we expect Task authors to create this directory before
placing files there. This is onerous and error-prone, so we should automatically create
them.

There are a few approaches to doing this:
- a mkdir init container
- a volume
- a mkdir pod container

I chose to use the final one, a mkdir pod container for consistency with Input resources.
This is prepended to the Task steps.
  • Loading branch information
dlorenc authored and tekton-robot committed Aug 5, 2019
1 parent 63b4873 commit ba25d4e
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 137 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1alpha1/artifact_pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func GetPvcMount(name string) corev1.VolumeMount {
// CreateDirContainer returns a container step to create a dir
func CreateDirContainer(name, destinationPath string) corev1.Container {
return corev1.Container{
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("create-dir-%s", name)),
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("create-dir-%s", strings.ToLower(name))),
Image: *BashNoopImage,
Command: []string{"/ko-app/bash"},
Args: []string{"-args", strings.Join([]string{"mkdir", "-p", destinationPath}, " ")},
Expand Down
4 changes: 4 additions & 0 deletions pkg/reconciler/v1alpha1/taskrun/resources/output_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ func AddOutputResources(
resourceVolumes = append(resourceVolumes, as.GetSecretsVolumes()...)
}

// Add containers to mkdir each output directory. This should run before the build steps themselves.
mkdirStep := []corev1.Container{v1alpha1.CreateDirContainer(boundResource.Name, sourcePath)}
taskSpec.Steps = append(mkdirStep, taskSpec.Steps...)

taskSpec.Steps = append(taskSpec.Steps, resourceContainers...)
taskSpec.Volumes = append(taskSpec.Volumes, resourceVolumes...)

Expand Down
Loading

0 comments on commit ba25d4e

Please sign in to comment.