Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the behavior of outputs that are also used as inputs. #1122

Merged
merged 2 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions cmd/bash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ package main

import (
"flag"
"log"
"os/exec"
"strings"

"github.com/tektoncd/pipeline/pkg/logging"
)
Expand All @@ -59,8 +59,7 @@ func main() {
cmd := exec.Command("sh", "-c", *args)
stdoutStderr, err := cmd.CombinedOutput()
if err != nil {
logger.Errorf("Error executing command %q with arguments %s", *args, stdoutStderr)
log.Fatal(err)
logger.Fatalf("Error executing command %q ; error %s; cmd_output %s", strings.Join(cmd.Args, " "), err.Error(), stdoutStderr)
}
logger.Infof("Successfully executed command %q", *args)
logger.Infof("Successfully executed command %q; output %s", strings.Join(cmd.Args, " "), stdoutStderr)
}
2 changes: 1 addition & 1 deletion examples/pipelineruns/output-pipelinerun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec:
- name: write-new-stuff
image: ubuntu
command: ['bash']
args: ['-c', 'echo some stuff > /workspace/damnworkspace/stuff']
args: ['-c', 'ln -s /workspace/damnworkspace /workspace/output/workspace && echo some stuff > /workspace/output/workspace/stuff']
---
# Reads a file from a predefined path in the workspace git PipelineResource
apiVersion: tekton.dev/v1alpha1
Expand Down
26 changes: 5 additions & 21 deletions pkg/reconciler/taskrun/resources/output_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
// upload steps (like upload to blob store )
//
// Resource source path determined
// 1. If resource is declared in inputs then target path from input resource is used to identify source path
// 1. If resource has a targetpath that is used. Otherwise:
// 2. If resource is declared in outputs only then the default is /output/resource_name
func AddOutputResources(
kubeclient kubernetes.Interface,
Expand All @@ -70,15 +70,6 @@ func AddOutputResources(
return nil, err
}

// track resources that are present in input of task cuz these resources will be copied onto PVC
inputResourceMap := map[string]string{}

if taskSpec.Inputs != nil {
for _, input := range taskSpec.Inputs.Resources {
inputResourceMap[input.Name] = destinationPath(input.Name, input.TargetPath)
}
}

for _, output := range taskSpec.Outputs.Resources {
boundResource, err := getBoundResource(output.Name, taskRun.Spec.Outputs.Resources)
if err != nil {
Expand All @@ -90,18 +81,11 @@ func AddOutputResources(
return nil, xerrors.Errorf("failed to get output pipeline Resource for task %q resource %v", taskName, boundResource)
}

// if resource is declared in input then copy outputs to pvc
// To build copy step it needs source path(which is targetpath of input resourcemap) from task input source
sourcePath := inputResourceMap[boundResource.Name]
if sourcePath != "" {
logger.Warn(`This task uses the same resource as an input and output. The behavior of this will change in a future release.
See https://github.com/tektoncd/pipeline/issues/1118 for more information.`)
var sourcePath string
if output.TargetPath == "" {
sourcePath = filepath.Join(outputDir, boundResource.Name)
} else {
if output.TargetPath == "" {
sourcePath = filepath.Join(outputDir, boundResource.Name)
} else {
sourcePath = output.TargetPath
}
sourcePath = output.TargetPath
}

resourceSteps, err := resource.GetUploadSteps(sourcePath)
Expand Down
14 changes: 7 additions & 7 deletions pkg/reconciler/taskrun/resources/output_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestValidOutputResources(t *testing.T) {
Name: "create-dir-source-workspace-mssqb",
Image: "override-with-bash-noop:latest",
Command: []string{"/ko-app/bash"},
Args: []string{"-args", "mkdir -p /workspace/source-workspace"},
Args: []string{"-args", "mkdir -p /workspace/output/source-workspace"},
}}, {Container: corev1.Container{
Name: "source-mkdir-source-git-9l9zj",
Image: "override-with-bash-noop:latest",
Expand All @@ -178,7 +178,7 @@ func TestValidOutputResources(t *testing.T) {
Name: "source-copy-source-git-mz4c7",
Image: "override-with-bash-noop:latest",
Command: []string{"/ko-app/bash"},
Args: []string{"-args", "cp -r /workspace/source-workspace/. pipeline-task-name"},
Args: []string{"-args", "cp -r /workspace/output/source-workspace/. pipeline-task-name"},
VolumeMounts: []corev1.VolumeMount{{
Name: "pipelinerun-pvc",
MountPath: "/pvc",
Expand Down Expand Up @@ -392,7 +392,7 @@ func TestValidOutputResources(t *testing.T) {
Name: "create-dir-source-workspace-78c5n",
Image: "override-with-bash-noop:latest",
Command: []string{"/ko-app/bash"},
Args: []string{"-args", "mkdir -p /workspace/faraway-disk"},
Args: []string{"-args", "mkdir -p /workspace/output/source-workspace"},
}}, {Container: corev1.Container{
Name: "upload-source-gcs-9l9zj",
Image: "override-with-gsutil-image:latest",
Expand All @@ -401,7 +401,7 @@ func TestValidOutputResources(t *testing.T) {
MountPath: "/var/secret/sname",
}},
Command: []string{"/ko-app/gsutil"},
Args: []string{"-args", "rsync -d -r /workspace/faraway-disk gs://some-bucket"},
Args: []string{"-args", "rsync -d -r /workspace/output/source-workspace gs://some-bucket"},
Env: []corev1.EnvVar{{
Name: "GOOGLE_APPLICATION_CREDENTIALS", Value: "/var/secret/sname/key.json",
}},
Expand All @@ -415,7 +415,7 @@ func TestValidOutputResources(t *testing.T) {
Name: "source-copy-source-gcs-mssqb",
Image: "override-with-bash-noop:latest",
Command: []string{"/ko-app/bash"},
Args: []string{"-args", "cp -r /workspace/faraway-disk/. pipeline-task-path"},
Args: []string{"-args", "cp -r /workspace/output/source-workspace/. pipeline-task-path"},
VolumeMounts: []corev1.VolumeMount{{Name: "pipelinerun-parent-pvc", MountPath: "/pvc"}},
}}},
wantVolumes: []corev1.Volume{{
Expand Down Expand Up @@ -842,12 +842,12 @@ func TestValidOutputResourcesWithBucketStorage(t *testing.T) {
Name: "create-dir-source-workspace-mz4c7",
Image: "override-with-bash-noop:latest",
Command: []string{"/ko-app/bash"},
Args: []string{"-args", "mkdir -p /workspace/source-workspace"},
Args: []string{"-args", "mkdir -p /workspace/output/source-workspace"},
}}, {Container: corev1.Container{
Name: "artifact-copy-to-source-git-9l9zj",
Image: "override-with-gsutil-image:latest",
Command: []string{"/ko-app/gsutil"},
Args: []string{"-args", "cp -P -r /workspace/source-workspace gs://fake-bucket/pipeline-task-name"},
Args: []string{"-args", "cp -P -r /workspace/output/source-workspace gs://fake-bucket/pipeline-task-name"},
}}},
}, {
name: "git resource in output only with bucket storage",
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ func TestReconcile(t *testing.T) {
tb.PodRestartPolicy(corev1.RestartPolicyNever),
getCredentialsInitContainer("l22wn"),
getPlaceToolsInitContainer(),
getMkdirResourceContainer("git-resource", "/workspace/git-resource", "vr6ds"),
getMkdirResourceContainer("git-resource", "/workspace/output/git-resource", "vr6ds"),
tb.PodContainer("step-create-dir-another-git-resource-78c5n", "override-with-bash-noop:latest",
tb.Command(entrypointLocation),
tb.Args("-wait_file", "/builder/tools/0", "-post_file", "/builder/tools/1", "-entrypoint", "/ko-app/bash", "--",
Expand Down Expand Up @@ -696,7 +696,7 @@ func TestReconcile(t *testing.T) {
tb.PodContainer("step-source-copy-git-resource-j2tds", "override-with-bash-noop:latest",
tb.Command(entrypointLocation),
tb.Args("-wait_file", "/builder/tools/6", "-post_file", "/builder/tools/7", "-entrypoint", "/ko-app/bash", "--",
"-args", "cp -r /workspace/git-resource/. output-folder"),
"-args", "cp -r /workspace/output/git-resource/. output-folder"),
tb.WorkingDir(workspaceDir),
tb.EnvVar("HOME", "/builder/home"),
tb.VolumeMount("test-pvc", "/pvc"),
Expand Down
1 change: 1 addition & 0 deletions test/dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestDAGPipelineRun(t *testing.T) {
),
tb.TaskOutputs(tb.OutputsResource("repo", v1alpha1.PipelineResourceTypeGit)),
tb.Step("echo-text", "busybox", tb.StepCommand("echo"), tb.StepArgs("$(inputs.params.text)")),
tb.Step("ln", "busybox", tb.StepCommand("ln"), tb.StepArgs("-s", "${inputs.resources.repo.path}", "${outputs.resources.repo.path}")),
))
if _, err := c.TaskClient.Create(echoTask); err != nil {
t.Fatalf("Failed to create echo Task: %s", err)
Expand Down
13 changes: 5 additions & 8 deletions test/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ func getFanInFanOutTasks(namespace string) []*v1alpha1.Task {
)),
tb.TaskOutputs(outWorkspaceResource),
tb.Step("write-data-task-0-step-0", "ubuntu", tb.StepCommand("/bin/bash"),
tb.StepArgs("-c", "echo stuff > $(inputs.resources.workspace.path)/stuff"),
tb.StepArgs("-c", "echo stuff > $(outputs.resources.workspace.path)/stuff"),
),
tb.Step("write-data-task-0-step-1", "ubuntu", tb.StepCommand("/bin/bash"),
// TODO(#1170): This test is using a mix of ${} and $() syntax to make sure both work.
// In the next release we will remove support for $() entirely.
tb.StepArgs("-c", "echo other > ${inputs.resources.workspace.path}/other"),
tb.StepArgs("-c", "echo other > ${outputs.resources.workspace.path}/other"),
),
)),
tb.Task("check-create-files-exists", namespace, tb.TaskSpec(
Expand All @@ -268,7 +268,7 @@ func getFanInFanOutTasks(namespace string) []*v1alpha1.Task {
tb.StepArgs("-c", "[[ stuff == $(cat ${inputs.resources.workspace.path}/stuff) ]]"),
),
tb.Step("write-data-task-1", "ubuntu", tb.StepCommand("/bin/bash"),
tb.StepArgs("-c", "echo something > $(inputs.resources.workspace.path)/something"),
tb.StepArgs("-c", "echo something > $(outputs.resources.workspace.path)/something"),
),
)),
tb.Task("check-create-files-exists-2", namespace, tb.TaskSpec(
Expand All @@ -278,20 +278,17 @@ func getFanInFanOutTasks(namespace string) []*v1alpha1.Task {
tb.StepArgs("-c", "[[ other == $(cat $(inputs.resources.workspace.path)/other) ]]"),
),
tb.Step("write-data-task-1", "ubuntu", tb.StepCommand("/bin/bash"),
tb.StepArgs("-c", "echo else > $(inputs.resources.workspace.path)/else"),
tb.StepArgs("-c", "echo else > $(outputs.resources.workspace.path)/else"),
),
)),
tb.Task("read-files", namespace, tb.TaskSpec(
tb.TaskInputs(tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit,
tb.ResourceTargetPath("readingspace"),
)),
tb.Step("read-from-task-0", "ubuntu", tb.StepCommand("/bin/bash"),
tb.StepArgs("-c", "[[ stuff == $(cat $(inputs.resources.workspace.path)/stuff) ]]"),
),
tb.Step("read-from-task-1", "ubuntu", tb.StepCommand("/bin/bash"),
tb.StepArgs("-c", "[[ something == $(cat $(inputs.resources.workspace.path)/something) ]]"),
),
tb.Step("read-from-task-2", "ubuntu", tb.StepCommand("/bin/bash"),
tb.Step("read-from-task-1", "ubuntu", tb.StepCommand("/bin/bash"),
// TODO(#1170): This test is using a mix of ${} and $() syntax to make sure both work.
// In the next release we will remove support for $() entirely.
tb.StepArgs("-c", "[[ else == $(cat ${inputs.resources.workspace.path}/else) ]]"),
Expand Down