From 74126995f986c139ba22d5ef5fa417fe0faf17f8 Mon Sep 17 00:00:00 2001 From: Andrea Frittoli Date: Mon, 21 Jan 2019 15:30:54 +0000 Subject: [PATCH] Onpy copy output resource to PVC for storage/git output 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. --- .../taskrun/resources/output_resource.go | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/pkg/reconciler/v1alpha1/taskrun/resources/output_resource.go b/pkg/reconciler/v1alpha1/taskrun/resources/output_resource.go index 39dc6f82f86..99a3a1799bb 100644 --- a/pkg/reconciler/v1alpha1/taskrun/resources/output_resource.go +++ b/pkg/reconciler/v1alpha1/taskrun/resources/output_resource.go @@ -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...) + } } }