From 8953621577d913952e60f1ba71d2a6547e836625 Mon Sep 17 00:00:00 2001 From: Christie Wilson Date: Fri, 13 Sep 2019 20:30:36 -0400 Subject: [PATCH] =?UTF-8?q?Add=20a=20warning=20if=20git=20used=20as=20an?= =?UTF-8?q?=20output=20=F0=9F=9A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In #1109 we will be removing support for git as an output. In the current implementation, git as an output is just a volume that holds the data from the git repo, and copies it between Tasks (when git as an output is linked to git as an input). As discussed in #1076, the model we want for PipelineResources is for them to take the outside world and represent it on disk when used as an input, and when used as an output, to update the outside world. In order to do this, what we actually want for a git output is for it to create a commit the repo it is referencing. However up until this point folks have been using git resources in the way that we want Volume Resources to behave #1062, so we want to transition folks to Volume Resources and away from using git outputs. Fixes #1283 --- docs/resources.md | 2 + .../taskrun/resources/output_resource.go | 4 ++ .../taskrun/resources/output_resource_test.go | 54 +++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/docs/resources.md b/docs/resources.md index d000e4911f9..d7c39324811 100644 --- a/docs/resources.md +++ b/docs/resources.md @@ -217,6 +217,8 @@ the source code to be built by the pipeline. Adding the git resource as an input to a Task will clone this repository and allow the Task to perform the required actions on the contents of the repo. +_Git resources as outputs will soon not be supported, see https://github.com/tektoncd/pipeline/pull/1109._ + To create a git resource using the `PipelineResource` CRD: ```yaml diff --git a/pkg/reconciler/taskrun/resources/output_resource.go b/pkg/reconciler/taskrun/resources/output_resource.go index f11d0e3cef0..26e1615f9a9 100644 --- a/pkg/reconciler/taskrun/resources/output_resource.go +++ b/pkg/reconciler/taskrun/resources/output_resource.go @@ -81,6 +81,10 @@ func AddOutputResources( return nil, xerrors.Errorf("failed to get output pipeline Resource for task %q resource %v", taskName, boundResource) } + if resource.GetType() == v1alpha1.PipelineResourceTypeGit { + logger.Warn("The Task %s uses a git output: in the next release, support for git outputs will be removed (See #1109)") + } + var sourcePath string if output.TargetPath == "" { sourcePath = filepath.Join(outputDir, boundResource.Name) diff --git a/pkg/reconciler/taskrun/resources/output_resource_test.go b/pkg/reconciler/taskrun/resources/output_resource_test.go index cb4c6485af9..a2a86e2e72c 100644 --- a/pkg/reconciler/taskrun/resources/output_resource_test.go +++ b/pkg/reconciler/taskrun/resources/output_resource_test.go @@ -19,10 +19,13 @@ package resources import ( "testing" + "go.uber.org/zap" + "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/logging" "github.com/tektoncd/pipeline/test/names" + "go.uber.org/zap/zaptest/observer" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" fakek8s "k8s.io/client-go/kubernetes/fake" @@ -777,6 +780,57 @@ func TestValidOutputResources(t *testing.T) { } } +// TestGitOutputWarns ensures we warn if git is used as an output. +// In #1109 we will remove support for the git resource as an output, until we add +// a different version via #1280 where a git output would create a new commit +func TestGitOutputWarns(t *testing.T) { + tr := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "git-output-run", + }, + Spec: v1alpha1.TaskRunSpec{ + Outputs: v1alpha1.TaskRunOutputs{ + Resources: []v1alpha1.TaskResourceBinding{{ + Name: "some-repo", + ResourceRef: v1alpha1.PipelineResourceRef{ + Name: "source-git", + }, + }}, + }, + }, + } + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "task", + }, + Spec: v1alpha1.TaskSpec{ + Outputs: &v1alpha1.Outputs{ + Resources: []v1alpha1.TaskResource{{ + ResourceDeclaration: v1alpha1.ResourceDeclaration{ + Name: "some-repo", + Type: "git", + }}}, + }, + }, + } + r := map[string]v1alpha1.PipelineResourceInterface{ + "some-repo": &v1alpha1.GitResource{ + Name: "source-git", + }, + } + + outputResourceSetup(t) + o, ol := observer.New(zap.WarnLevel) + z := zap.New(o).Sugar() + _, err := AddOutputResources(fakek8s.NewSimpleClientset(), task.Name, &task.Spec, tr, r, z) + if err != nil { + t.Fatalf("Did not expect error but got %v", err) + } + if len(ol.All()) != 1 { + t.Errorf("Expected to see a warning logged for a git output but saw none") + } +} + func TestValidOutputResourcesWithBucketStorage(t *testing.T) { for _, c := range []struct { name string