Skip to content

Commit

Permalink
Onpy copy output resource to PVC for storage/git output
Browse files Browse the repository at this point in the history
At the moment the output_resource module unconditionally adds a
copy step for every output resource in the taskrun.
However not every output resource will generate content to be
copied. Limit the copy to Storage and Git outoputs for now.

This is meant as a hotfix for bug #401 until an implementation
of the image output resource is available via #216. Until
image resource output is implemented, any consumer won't
have guarantee that the image has been actually built and pushed,
and won't know the hash of the created image.
  • Loading branch information
afrittoli committed Jan 21, 2019
1 parent 41d513b commit 8ddbc96
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 21 deletions.
49 changes: 28 additions & 21 deletions pkg/reconciler/v1alpha1/taskrun/resources/output_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,34 @@ func AddOutputResources(
}
}

// copy to pvc if pvc is present
if pipelineRunpvcName != "" {
var newSteps []corev1.Container
for _, dPath := range boundResource.Paths {
newSteps = append(newSteps, []corev1.Container{{
Name: fmt.Sprintf("source-mkdir-%s", resource.GetName()),
Image: *bashNoopImage,
Args: []string{
"-args", strings.Join([]string{"mkdir", "-p", dPath}, " "),
},
VolumeMounts: []corev1.VolumeMount{getPvcMount(pipelineRunpvcName)},
}, {
Name: fmt.Sprintf("source-copy-%s", resource.GetName()),
Image: *bashNoopImage,
Args: []string{
"-args", strings.Join([]string{"cp", "-r", fmt.Sprintf("%s/.", sourcePath), dPath}, " "),
},
VolumeMounts: []corev1.VolumeMount{getPvcMount(pipelineRunpvcName)},
}}...)
}
b.Spec.Steps = append(b.Spec.Steps, newSteps...)
// Workaround for issue #401. Unless all resource types are implemented as
// outputs, or until we have metadata on the resource that declares whether
// the output should be copied to the PVC, only copy git and storage output
// resources.
if (resource.Spec.Type == v1alpha1.PipelineResourceTypeStorage ||
resource.Spec.Type == v1alpha1.PipelineResourceTypeGit) {
// copy to pvc if pvc is present
if pipelineRunpvcName != "" {
var newSteps []corev1.Container
for _, dPath := range boundResource.Paths {
newSteps = append(newSteps, []corev1.Container{{
Name: fmt.Sprintf("source-mkdir-%s", resource.GetName()),
Image: *bashNoopImage,
Args: []string{
"-args", strings.Join([]string{"mkdir", "-p", dPath}, " "),
},
VolumeMounts: []corev1.VolumeMount{getPvcMount(pipelineRunpvcName)},
}, {
Name: fmt.Sprintf("source-copy-%s", resource.GetName()),
Image: *bashNoopImage,
Args: []string{
"-args", strings.Join([]string{"cp", "-r", fmt.Sprintf("%s/.", sourcePath), dPath}, " "),
},
VolumeMounts: []corev1.VolumeMount{getPvcMount(pipelineRunpvcName)},
}}...)
}
b.Spec.Steps = append(b.Spec.Steps, newSteps...)
}
}
}

Expand Down
47 changes: 47 additions & 0 deletions pkg/reconciler/v1alpha1/taskrun/resources/output_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ func outputResourcesetUp() {
FieldName: "STORAGE_CREDS",
}},
},
}, {
ObjectMeta: metav1.ObjectMeta{
Name: "source-image",
Namespace: "marshmallow",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: "image",
},
}}

for _, r := range rs {
Expand Down Expand Up @@ -549,6 +557,45 @@ func Test_Valid_OutputResources(t *testing.T) {
Secret: &corev1.SecretVolumeSource{SecretName: "sname"},
},
}},
}, {
name: "image resource as output",
desc: "image resource defined only in output",
taskRun: &v1alpha1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Name: "test-taskrun-run-only-output-step",
Namespace: "marshmallow",
OwnerReferences: []metav1.OwnerReference{{
Kind: "PipelineRun",
Name: "pipelinerun",
}},
},
Spec: v1alpha1.TaskRunSpec{
Outputs: v1alpha1.TaskRunOutputs{
Resources: []v1alpha1.TaskResourceBinding{{
Name: "source-workspace",
ResourceRef: v1alpha1.PipelineResourceRef{
Name: "source-image",
},
}},
},
},
},
task: &v1alpha1.Task{
ObjectMeta: metav1.ObjectMeta{
Name: "task1",
Namespace: "marshmallow",
},
Spec: v1alpha1.TaskSpec{
Outputs: &v1alpha1.Outputs{
Resources: []v1alpha1.TaskResource{{
Name: "source-workspace",
Type: "image",
}},
},
},
},
wantSteps: nil,
build: build(),
}} {
t.Run(c.name, func(t *testing.T) {
outputResourcesetUp()
Expand Down

0 comments on commit 8ddbc96

Please sign in to comment.