diff --git a/cmd/git-init/main.go b/cmd/git-init/main.go index ae7ef29b2cd..fda96dc792a 100644 --- a/cmd/git-init/main.go +++ b/cmd/git-init/main.go @@ -65,6 +65,7 @@ func main() { ResourceRef: v1beta1.PipelineResourceRef{ Name: resourceName, }, + ResourceName: resourceName, }, } diff --git a/cmd/imagedigestexporter/main.go b/cmd/imagedigestexporter/main.go index 1751b19fdfd..d7cced05a39 100644 --- a/cmd/imagedigestexporter/main.go +++ b/cmd/imagedigestexporter/main.go @@ -64,8 +64,9 @@ func main() { logger.Fatalf("Unexpected error getting image digest for %s: %v", imageResource.Name, err) } output = append(output, v1beta1.PipelineResourceResult{ - Key: "digest", - Value: digest.String(), + Key: "digest", + Value: digest.String(), + ResourceName: imageResource.Name, ResourceRef: v1beta1.PipelineResourceRef{ Name: imageResource.Name, }, diff --git a/docs/deprecations.md b/docs/deprecations.md index 926329a3eda..e926722b524 100644 --- a/docs/deprecations.md +++ b/docs/deprecations.md @@ -23,3 +23,4 @@ being deprecated. | [`tekton.dev/task` label on ClusterTasks](https://github.com/tektoncd/pipeline/issues/2533) | [v0.12.0](https://github.com/tektoncd/pipeline/releases/tag/v0.12.0) | Beta | January 30 2021 | | [Step `$HOME` env var defaults to `/tekton/home`](https://github.com/tektoncd/pipeline/issues/2013) | [v0.11.0-rc1](https://github.com/tektoncd/pipeline/releases/tag/v0.11.0-rc1) | Beta | December 4 2020 | | [Step `workingDir` defaults to `/workspace`](https://github.com/tektoncd/pipeline/issues/1836) | [v0.11.0-rc1](https://github.com/tektoncd/pipeline/releases/tag/v0.11.0-rc1) | Beta | December 4 2020 | +| [The `TaskRun.Status.ResourceResults.ResourceRef` field is deprecated and will be removed.](https://github.com/tektoncd/pipeline/issues/2694) | [v0.14.0](https://github.com/tektoncd/pipeline/releases/tag/v0.13.0) | Beta | April 30 2021 | diff --git a/go.mod b/go.mod index cdb81eca85d..4886506ee96 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,9 @@ module github.com/tektoncd/pipeline go 1.13 require ( + cloud.google.com/go/storage v1.6.0 + contrib.go.opencensus.io/exporter/ocagent v0.6.0 // indirect + contrib.go.opencensus.io/exporter/prometheus v0.1.0 // indirect contrib.go.opencensus.io/exporter/stackdriver v0.13.1 // indirect github.com/GoogleCloudPlatform/cloud-builders/gcs-fetcher v0.0.0-20191203181535-308b93ad1f39 github.com/aws/aws-sdk-go v1.30.16 // indirect @@ -25,6 +28,8 @@ require ( golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 // indirect golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d gomodules.xyz/jsonpatch/v2 v2.1.0 + google.golang.org/api v0.20.0 + google.golang.org/appengine v1.6.5 // indirect google.golang.org/protobuf v1.22.0 // indirect gopkg.in/yaml.v2 v2.3.0 // indirect k8s.io/api v0.17.6 diff --git a/go.sum b/go.sum index 17cd064b401..19a2ee3e5bb 100644 --- a/go.sum +++ b/go.sum @@ -1236,7 +1236,6 @@ google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvx google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63 h1:YzfoEYWbODU5Fbt37+h7X16BWQbad7Q4S6gclTKFXM8= google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200317114155-1f3552e48f24 h1:IGPykv426z7LZSVPlaPufOyphngM4at5uZ7x5alaFvE= google.golang.org/genproto v0.0.0-20200317114155-1f3552e48f24/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= @@ -1252,7 +1251,6 @@ google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s= google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= @@ -1273,11 +1271,9 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20141024133853-64131543e789/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/gcfg.v1 v1.2.0/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo= @@ -1298,7 +1294,6 @@ gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76 gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.1/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= @@ -1308,12 +1303,10 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20190709130402-674ba3eaed22/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= helm.sh/helm/v3 v3.1.1/go.mod h1:WYsFJuMASa/4XUqLyv54s0U/f3mlAaRErGmyy4z921g= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= @@ -1322,19 +1315,20 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.2/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/api v0.16.5 h1:5ceVzCX+I9LI9wIw4CASqVsepRDeUp44/J8Tgl4ki2I= k8s.io/api v0.16.5/go.mod h1:6ijJb2BQAkGSn+8Z3173M0LXe2gBAH+i/JAJptd/rJo= k8s.io/apiextensions-apiserver v0.17.2/go.mod h1:4KdMpjkEjjDI2pPfBA15OscyNldHWdBCfsWMDWAmSTs= +k8s.io/apiextensions-apiserver v0.17.3/go.mod h1:CJbCyMfkKftAd/X/V6OTHYhVn7zXnDdnkUjS1h0GTeY= k8s.io/apiextensions-apiserver v0.17.6 h1:o5JWDya65ApIVez+RfR40PGrqjPUZHhlSmwAHCvL20E= k8s.io/apiextensions-apiserver v0.17.6/go.mod h1:Z3CHLP3Tha+Rbav7JR3S+ye427UaJkHBomK2c4XtZ3A= k8s.io/apimachinery v0.16.5 h1:5rnJuabGmLtgcMrdeTb48CvV0UW4TrM5vBbWWEy6OS0= k8s.io/apimachinery v0.16.5/go.mod h1:mhhO3hoLkWO+2eCvqjPtH2Ly92l9nJDwsswzWKpkN2w= k8s.io/apiserver v0.17.0/go.mod h1:ABM+9x/prjINN6iiffRVNCBR2Wk7uY4z+EtEGZD48cg= k8s.io/apiserver v0.17.2/go.mod h1:lBmw/TtQdtxvrTk0e2cgtOxHizXI+d0mmGQURIHQZlo= +k8s.io/apiserver v0.17.3/go.mod h1:iJtsPpu1ZpEnHaNawpSV0nYTGBhhX2dUlnn7/QS7QiY= k8s.io/apiserver v0.17.4/go.mod h1:5ZDQ6Xr5MNBxyi3iUZXS84QOhZl+W7Oq2us/29c0j9I= k8s.io/apiserver v0.17.6/go.mod h1:sAYqm8hUDNA9aj/TzqwsJoExWrxprKv0tqs/z88qym0= k8s.io/cli-runtime v0.17.2/go.mod h1:aa8t9ziyQdbkuizkNLAw3qe3srSyWh9zlSB7zTqRNPI= @@ -1347,6 +1341,7 @@ k8s.io/code-generator v0.16.5 h1:DQDucFIbyQChnbz5KY0SECZd2VH72qKVAd8+vA4h8kI= k8s.io/code-generator v0.16.5/go.mod h1:2aiDuxDU7RQK2PVypXAXHo6+YwOlF33iezHQbSmKSA4= k8s.io/component-base v0.17.0/go.mod h1:rKuRAokNMY2nn2A6LP/MiwpoaMRHpfRnrPaUJJj1Yoc= k8s.io/component-base v0.17.2/go.mod h1:zMPW3g5aH7cHJpKYQ/ZsGMcgbsA/VyhEugF3QT1awLs= +k8s.io/component-base v0.17.3/go.mod h1:GeQf4BrgelWm64PXkIXiPh/XS0hnO42d9gx9BtbZRp8= k8s.io/component-base v0.17.4/go.mod h1:5BRqHMbbQPm2kKu35v3G+CpVq4K0RJKC7TRioF0I9lE= k8s.io/component-base v0.17.6 h1:4S4FTX7/5VvO325vHm9/4pdql91OhrZpDYVzmyLSqNU= k8s.io/component-base v0.17.6/go.mod h1:jgRLWl0B0rOzFNtxQ9E4BphPmDqoMafujdau6AdG2Xo= @@ -1362,7 +1357,6 @@ k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= k8s.io/kube-openapi v0.0.0-20190816220812-743ec37842bf/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= -k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a h1:UcxjrRMyNx/i/y8G7kPvLyy7rfbeuf1PYyBf973pgyU= k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29 h1:NeQXVJ2XFSkRoPzRo8AId01ZER+j8oV4SZADT4iBOXQ= k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29/go.mod h1:F+5wygcW0wmRTnM3cOgIqGivxkwSWIWT5YdsDbeAOaU= @@ -1374,7 +1368,6 @@ k8s.io/legacy-cloud-providers v0.17.4/go.mod h1:FikRNoD64ECjkxO36gkDgJeiQWwyZTuB k8s.io/metrics v0.17.2/go.mod h1:3TkNHET4ROd+NfzNxkjoVfQ0Ob4iZnaHmSEA4vYpwLw= k8s.io/test-infra v0.0.0-20200407001919-bc7f71ef65b8/go.mod h1:/WpJWcaDvuykB322WXP4kJbX8IpalOzuPxA62GpwkJk= k8s.io/utils v0.0.0-20190801114015-581e00157fb1/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= -k8s.io/utils v0.0.0-20191114184206-e782cd3c129f h1:GiPwtSzdP43eI1hpPCbROQCCIgCuiMMNF8YUVLF3vJo= k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= k8s.io/utils v0.0.0-20200124190032-861946025e34 h1:HjlUD6M0K3P8nRXmr2B9o4F9dUy9TCj/aEpReeyi6+k= k8s.io/utils v0.0.0-20200124190032-861946025e34/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= @@ -1402,7 +1395,6 @@ sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5 sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= sigs.k8s.io/structured-merge-diff v1.0.1-0.20191108220359-b1b620dd3f06/go.mod h1:/ULNhyfzRopfcjskuui0cTITekDduZ7ycKN3oUT9R18= sigs.k8s.io/structured-merge-diff/v2 v2.0.1/go.mod h1:Wb7vfKAodbKgf6tn1Kl0VvGj7mRH6DGaRcixXEJXTsE= -sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= diff --git a/pkg/apis/pipeline/v1beta1/resource_types.go b/pkg/apis/pipeline/v1beta1/resource_types.go index def3199e78a..94225ebc66f 100644 --- a/pkg/apis/pipeline/v1beta1/resource_types.go +++ b/pkg/apis/pipeline/v1beta1/resource_types.go @@ -120,8 +120,11 @@ type PipelineResourceBinding struct { // PipelineResourceResult used to export the image name and digest as json type PipelineResourceResult struct { - Key string `json:"key"` - Value string `json:"value"` + Key string `json:"key"` + Value string `json:"value"` + ResourceName string `json:"resourceName,omitempty"` + // This field should be deprecated and removed in the next API version. + // See https://github.com/tektoncd/pipeline/issues/2694 for more information. ResourceRef PipelineResourceRef `json:"resourceRef,omitempty"` ResultType ResultType `json:"type,omitempty"` } diff --git a/pkg/apis/resource/resource.go b/pkg/apis/resource/resource.go index d633b58d507..eb6580fe474 100644 --- a/pkg/apis/resource/resource.go +++ b/pkg/apis/resource/resource.go @@ -33,20 +33,20 @@ import ( // FromType returns an instance of the correct PipelineResource object type which can be // used to add input and output containers as well as volumes to a TaskRun's pod in order to realize // a PipelineResource in a pod. -func FromType(r *resourcev1alpha1.PipelineResource, images pipeline.Images) (pipelinev1beta1.PipelineResourceInterface, error) { +func FromType(name string, r *resourcev1alpha1.PipelineResource, images pipeline.Images) (pipelinev1beta1.PipelineResourceInterface, error) { switch r.Spec.Type { case resourcev1alpha1.PipelineResourceTypeGit: - return git.NewResource(images.GitImage, r) + return git.NewResource(name, images.GitImage, r) case resourcev1alpha1.PipelineResourceTypeImage: - return image.NewResource(r) + return image.NewResource(name, r) case resourcev1alpha1.PipelineResourceTypeCluster: - return cluster.NewResource(images.KubeconfigWriterImage, r) + return cluster.NewResource(name, images.KubeconfigWriterImage, images.ShellImage, r) case resourcev1alpha1.PipelineResourceTypeStorage: - return storage.NewResource(images, r) + return storage.NewResource(name, images, r) case resourcev1alpha1.PipelineResourceTypePullRequest: - return pullrequest.NewResource(images.PRImage, r) + return pullrequest.NewResource(name, images.PRImage, r) case resourcev1alpha1.PipelineResourceTypeCloudEvent: - return cloudevent.NewResource(r) + return cloudevent.NewResource(name, r) } return nil, fmt.Errorf("%s is an invalid or unimplemented PipelineResource", r.Spec.Type) } diff --git a/pkg/apis/resource/v1alpha1/cloudevent/cloud_event_resource.go b/pkg/apis/resource/v1alpha1/cloudevent/cloud_event_resource.go index d2fcede62af..ece8912327d 100644 --- a/pkg/apis/resource/v1alpha1/cloudevent/cloud_event_resource.go +++ b/pkg/apis/resource/v1alpha1/cloudevent/cloud_event_resource.go @@ -35,7 +35,7 @@ type Resource struct { } // NewResource creates a new CloudEvent resource to pass to a Task -func NewResource(r *resource.PipelineResource) (*Resource, error) { +func NewResource(name string, r *resource.PipelineResource) (*Resource, error) { if r.Spec.Type != resource.PipelineResourceTypeCloudEvent { return nil, fmt.Errorf("cloudevent.Resource: Cannot create a Cloud Event resource from a %s Pipeline Resource", r.Spec.Type) } @@ -55,7 +55,7 @@ func NewResource(r *resource.PipelineResource) (*Resource, error) { return nil, fmt.Errorf("cloudevent.Resource: Need URI to be specified in order to create a CloudEvent resource %s", r.Name) } return &Resource{ - Name: r.Name, + Name: name, Type: r.Spec.Type, TargetURI: targetURI, }, nil diff --git a/pkg/apis/resource/v1alpha1/cloudevent/cloud_event_resource_test.go b/pkg/apis/resource/v1alpha1/cloudevent/cloud_event_resource_test.go index c008c04e283..a2916df0196 100644 --- a/pkg/apis/resource/v1alpha1/cloudevent/cloud_event_resource_test.go +++ b/pkg/apis/resource/v1alpha1/cloudevent/cloud_event_resource_test.go @@ -46,7 +46,7 @@ func TestNewResource_Invalid(t *testing.T) { }} for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - _, err := cloudevent.NewResource(tc.pipelineResource) + _, err := cloudevent.NewResource("test-resource", tc.pipelineResource) if err == nil { t.Error("Expected error creating CloudEvent resource") } @@ -60,12 +60,12 @@ func TestNewResource_Valid(t *testing.T) { tb.PipelineResourceSpecParam("TargetURI", "http://fake-sink"), )) expectedResource := &cloudevent.Resource{ - Name: "cloud-event-resource-uri", + Name: "test-resource", TargetURI: "http://fake-sink", Type: resourcev1alpha1.PipelineResourceTypeCloudEvent, } - r, err := cloudevent.NewResource(pr) + r, err := cloudevent.NewResource("test-resource", pr) if err != nil { t.Fatalf("Unexpected error creating CloudEvent resource: %s", err) } diff --git a/pkg/apis/resource/v1alpha1/cluster/cluster_resource.go b/pkg/apis/resource/v1alpha1/cluster/cluster_resource.go index b07c7f5f7ed..d5a330b38c8 100644 --- a/pkg/apis/resource/v1alpha1/cluster/cluster_resource.go +++ b/pkg/apis/resource/v1alpha1/cluster/cluster_resource.go @@ -20,9 +20,11 @@ import ( b64 "encoding/base64" "encoding/json" "fmt" + "path/filepath" "strconv" "strings" + "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/names" @@ -58,17 +60,23 @@ type Resource struct { Secrets []resource.SecretParam `json:"secrets"` KubeconfigWriterImage string `json:"-"` + ShellImage string `json:"-"` + + // Temporary field to hold the old, legacy value for name. See #2694 + LegacyName string `json:"-"` } // NewResource create a new k8s cluster resource to pass to a pipeline task -func NewResource(kubeconfigWriterImage string, r *resource.PipelineResource) (*Resource, error) { +func NewResource(name string, kubeconfigWriterImage, shellImage string, r *resource.PipelineResource) (*Resource, error) { if r.Spec.Type != resource.PipelineResourceTypeCluster { return nil, fmt.Errorf("cluster.Resource: Cannot create a Cluster resource from a %s Pipeline Resource", r.Spec.Type) } clusterResource := Resource{ Type: r.Spec.Type, KubeconfigWriterImage: kubeconfigWriterImage, - Name: r.Name, + ShellImage: shellImage, + Name: name, + LegacyName: r.Name, } for _, param := range r.Spec.Params { switch { @@ -189,6 +197,21 @@ func (s *Resource) GetInputTaskModifier(ts *v1beta1.TaskSpec, path string) (v1be Env: envVars, }} return &v1beta1.InternalTaskModifier{ - StepsToPrepend: []v1beta1.Step{step}, + StepsToPrepend: []v1beta1.Step{ + step, + // See #2694. + linkDirStep(s.ShellImage, s.Name, s.LegacyName), + }, }, nil } + +// See #2694 +func linkDirStep(shellImage string, name, legacyName string) v1beta1.Step { + srcPath := filepath.Join(pipeline.WorkspaceDir, name) + dstPath := filepath.Join(pipeline.WorkspaceDir, legacyName) + return v1beta1.Step{Container: corev1.Container{ + Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("ln-dir-%s", strings.ToLower(name))), + Image: shellImage, + Command: []string{"ln", "-s", srcPath, dstPath}, + }} +} diff --git a/pkg/apis/resource/v1alpha1/cluster/cluster_resource_test.go b/pkg/apis/resource/v1alpha1/cluster/cluster_resource_test.go index 3ff785912b5..4eb540151b9 100644 --- a/pkg/apis/resource/v1alpha1/cluster/cluster_resource_test.go +++ b/pkg/apis/resource/v1alpha1/cluster/cluster_resource_test.go @@ -36,14 +36,14 @@ func TestNewClusterResource(t *testing.T) { want *cluster.Resource }{{ desc: "basic cluster resource", - resource: tb.PipelineResource("test-cluster-resource", tb.PipelineResourceSpec( + resource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec( resourcev1alpha1.PipelineResourceTypeCluster, tb.PipelineResourceSpecParam("url", "http://10.10.10.10"), tb.PipelineResourceSpecParam("cadata", "bXktY2x1c3Rlci1jZXJ0Cg"), tb.PipelineResourceSpecParam("token", "my-token"), )), want: &cluster.Resource{ - Name: "test-cluster-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeCluster, URL: "http://10.10.10.10", CAData: []byte("my-cluster-cert"), @@ -52,7 +52,7 @@ func TestNewClusterResource(t *testing.T) { }, }, { desc: "resource with password instead of token", - resource: tb.PipelineResource("test-cluster-resource", tb.PipelineResourceSpec( + resource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec( resourcev1alpha1.PipelineResourceTypeCluster, tb.PipelineResourceSpecParam("url", "http://10.10.10.10"), tb.PipelineResourceSpecParam("cadata", "bXktY2x1c3Rlci1jZXJ0Cg"), @@ -60,7 +60,7 @@ func TestNewClusterResource(t *testing.T) { tb.PipelineResourceSpecParam("password", "pass"), )), want: &cluster.Resource{ - Name: "test-cluster-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeCluster, URL: "http://10.10.10.10", CAData: []byte("my-cluster-cert"), @@ -70,7 +70,7 @@ func TestNewClusterResource(t *testing.T) { }, }, { desc: "resource with clientKeyData and clientCertificateData instead of token or password", - resource: tb.PipelineResource("test-cluster-resource", tb.PipelineResourceSpec( + resource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec( resourcev1alpha1.PipelineResourceTypeCluster, tb.PipelineResourceSpecParam("url", "http://10.10.10.10"), tb.PipelineResourceSpecParam("username", "user"), @@ -79,7 +79,7 @@ func TestNewClusterResource(t *testing.T) { tb.PipelineResourceSpecParam("clientCertificateData", "Y2xpZW50LWNlcnRpZmljYXRlLWRhdGE="), )), want: &cluster.Resource{ - Name: "test-cluster-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeCluster, URL: "http://10.10.10.10", Username: "user", @@ -90,13 +90,13 @@ func TestNewClusterResource(t *testing.T) { }, }, { desc: "set insecure flag to true when there is no cert", - resource: tb.PipelineResource("test-cluster-resource", tb.PipelineResourceSpec( + resource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec( resourcev1alpha1.PipelineResourceTypeCluster, tb.PipelineResourceSpecParam("url", "http://10.10.10.10"), tb.PipelineResourceSpecParam("token", "my-token"), )), want: &cluster.Resource{ - Name: "test-cluster-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeCluster, URL: "http://10.10.10.10", Token: "my-token", @@ -105,7 +105,7 @@ func TestNewClusterResource(t *testing.T) { }, }, { desc: "basic cluster resource with namespace", - resource: tb.PipelineResource("test-cluster-resource", tb.PipelineResourceSpec( + resource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec( resourcev1alpha1.PipelineResourceTypeCluster, tb.PipelineResourceSpecParam("url", "http://10.10.10.10"), tb.PipelineResourceSpecParam("cadata", "bXktY2x1c3Rlci1jZXJ0Cg"), @@ -113,7 +113,7 @@ func TestNewClusterResource(t *testing.T) { tb.PipelineResourceSpecParam("namespace", "my-namespace"), )), want: &cluster.Resource{ - Name: "test-cluster-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeCluster, URL: "http://10.10.10.10", CAData: []byte("my-cluster-cert"), @@ -123,14 +123,14 @@ func TestNewClusterResource(t *testing.T) { }, }, { desc: "basic resource with secrets", - resource: tb.PipelineResource("test-cluster-resource", tb.PipelineResourceSpec( + resource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec( resourcev1alpha1.PipelineResourceTypeCluster, tb.PipelineResourceSpecParam("url", "http://10.10.10.10"), tb.PipelineResourceSpecSecretParam("cadata", "secret1", "cadatakey"), tb.PipelineResourceSpecSecretParam("token", "secret1", "tokenkey"), )), want: &cluster.Resource{ - Name: "test-cluster-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeCluster, URL: "http://10.10.10.10", Secrets: []resourcev1alpha1.SecretParam{{ @@ -146,10 +146,12 @@ func TestNewClusterResource(t *testing.T) { }, }} { t.Run(c.desc, func(t *testing.T) { - got, err := cluster.NewResource("override-with-kubeconfig-writer:latest", c.resource) + got, err := cluster.NewResource("test-resource", "override-with-kubeconfig-writer:latest", "override-with-shell-image:latest", c.resource) if err != nil { t.Errorf("Test: %q; TestNewClusterResource() error = %v", c.desc, err) } + c.want.ShellImage = "override-with-shell-image:latest" + c.want.LegacyName = "test-resource" if d := cmp.Diff(got, c.want); d != "" { t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) } @@ -172,25 +174,37 @@ func TestClusterResource_GetInputTaskModifier(t *testing.T) { } ts := v1beta1.TaskSpec{} - wantSteps := []v1beta1.Step{{Container: corev1.Container{ - Name: "kubeconfig-9l9zj", - Image: "override-with-kubeconfig-writer:latest", - Command: []string{"/ko-app/kubeconfigwriter"}, - Args: []string{"-clusterConfig", `{"name":"test-cluster-resource","type":"cluster","url":"http://10.10.10.10","revision":"","username":"","password":"","namespace":"","token":"","Insecure":false,"cadata":null,"clientKeyData":null,"clientCertificateData":null,"secrets":[{"fieldName":"cadata","secretKey":"cadatakey","secretName":"secret1"}]}`}, - Env: []corev1.EnvVar{{ - Name: "CADATA", - ValueFrom: &corev1.EnvVarSource{ - SecretKeyRef: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret1", + wantSteps := []v1beta1.Step{ + { + Container: corev1.Container{ + Name: "kubeconfig-9l9zj", + Image: "override-with-kubeconfig-writer:latest", + Command: []string{"/ko-app/kubeconfigwriter"}, + Args: []string{"-clusterConfig", `{"name":"test-cluster-resource","type":"cluster","url":"http://10.10.10.10","revision":"","username":"","password":"","namespace":"","token":"","Insecure":false,"cadata":null,"clientKeyData":null,"clientCertificateData":null,"secrets":[{"fieldName":"cadata","secretKey":"cadatakey","secretName":"secret1"}]}`}, + Env: []corev1.EnvVar{{ + Name: "CADATA", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: "secret1", + }, + Key: "cadatakey", + }, }, - Key: "cadatakey", - }, + }}, }, - }}, - }}} + }, + // We need to temporarily create another directory for the legacy name + // See #2694. + { + Container: corev1.Container{ + Name: "ln-dir-test-cluster-resource-mz4c7", + Command: []string{"ln", "-s", "/workspace/test-cluster-resource", "/workspace"}, + }, + }, + } - got, err := clusterResource.GetInputTaskModifier(&ts, "") + got, err := clusterResource.GetInputTaskModifier(&ts, "/location") if err != nil { t.Fatalf("GetDownloadSteps: %v", err) } diff --git a/pkg/apis/resource/v1alpha1/git/git_resource.go b/pkg/apis/resource/v1alpha1/git/git_resource.go index f80adf26551..4aa7b3b5b8a 100644 --- a/pkg/apis/resource/v1alpha1/git/git_resource.go +++ b/pkg/apis/resource/v1alpha1/git/git_resource.go @@ -53,12 +53,12 @@ type Resource struct { } // NewResource creates a new git resource to pass to a Task -func NewResource(gitImage string, r *resource.PipelineResource) (*Resource, error) { +func NewResource(name, gitImage string, r *resource.PipelineResource) (*Resource, error) { if r.Spec.Type != resource.PipelineResourceTypeGit { return nil, fmt.Errorf("git.Resource: Cannot create a Git resource from a %s Pipeline Resource", r.Spec.Type) } gitResource := Resource{ - Name: r.Name, + Name: name, Type: r.Spec.Type, GitImage: gitImage, Submodules: true, diff --git a/pkg/apis/resource/v1alpha1/git/git_resource_test.go b/pkg/apis/resource/v1alpha1/git/git_resource_test.go index 1cd0dae1b00..a36ce703ed2 100644 --- a/pkg/apis/resource/v1alpha1/git/git_resource_test.go +++ b/pkg/apis/resource/v1alpha1/git/git_resource_test.go @@ -31,7 +31,7 @@ import ( ) func TestNewGitResource_Invalid(t *testing.T) { - if _, err := git.NewResource("override-with-git:latest", tb.PipelineResource("git-resource", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGCS))); err == nil { + if _, err := git.NewResource("test-resource", "override-with-git:latest", tb.PipelineResource("git-resource", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGCS))); err == nil { t.Error("Expected error creating Git resource") } } @@ -50,7 +50,7 @@ func TestNewGitResource_Valid(t *testing.T) { ), ), want: &git.Resource{ - Name: "git-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeGit, URL: "git@github.com:test/test.git", Revision: "test", @@ -65,13 +65,13 @@ func TestNewGitResource_Valid(t *testing.T) { }, }, { desc: "Without Revision", - pipelineResource: tb.PipelineResource("git-resource", + pipelineResource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "git@github.com:test/test.git"), ), ), want: &git.Resource{ - Name: "git-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeGit, URL: "git@github.com:test/test.git", Revision: "master", @@ -86,14 +86,14 @@ func TestNewGitResource_Valid(t *testing.T) { }, }, { desc: "With Refspec", - pipelineResource: tb.PipelineResource("git-resource", + pipelineResource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "git@github.com:test/test.git"), tb.PipelineResourceSpecParam("Refspec", "refs/changes/22/222134"), ), ), want: &git.Resource{ - Name: "git-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeGit, URL: "git@github.com:test/test.git", Revision: "master", @@ -108,13 +108,13 @@ func TestNewGitResource_Valid(t *testing.T) { }, }, { desc: "Without Refspec", - pipelineResource: tb.PipelineResource("git-resource", + pipelineResource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "git@github.com:test/test.git"), ), ), want: &git.Resource{ - Name: "git-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeGit, URL: "git@github.com:test/test.git", Revision: "master", @@ -129,14 +129,14 @@ func TestNewGitResource_Valid(t *testing.T) { }, }, { desc: "With Submodules", - pipelineResource: tb.PipelineResource("git-resource", + pipelineResource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "git@github.com:test/test.git"), tb.PipelineResourceSpecParam("Revision", "test"), ), ), want: &git.Resource{ - Name: "git-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeGit, URL: "git@github.com:test/test.git", Revision: "test", @@ -151,7 +151,7 @@ func TestNewGitResource_Valid(t *testing.T) { }, }, { desc: "Without Submodules", - pipelineResource: tb.PipelineResource("git-resource", + pipelineResource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "git@github.com:test/test.git"), tb.PipelineResourceSpecParam("Revision", "test"), @@ -159,7 +159,7 @@ func TestNewGitResource_Valid(t *testing.T) { ), ), want: &git.Resource{ - Name: "git-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeGit, URL: "git@github.com:test/test.git", Revision: "test", @@ -174,7 +174,7 @@ func TestNewGitResource_Valid(t *testing.T) { }, }, { desc: "With positive depth", - pipelineResource: tb.PipelineResource("git-resource", + pipelineResource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "git@github.com:test/test.git"), tb.PipelineResourceSpecParam("Revision", "test"), @@ -182,7 +182,7 @@ func TestNewGitResource_Valid(t *testing.T) { ), ), want: &git.Resource{ - Name: "git-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeGit, URL: "git@github.com:test/test.git", Revision: "test", @@ -197,7 +197,7 @@ func TestNewGitResource_Valid(t *testing.T) { }, }, { desc: "With zero depth", - pipelineResource: tb.PipelineResource("git-resource", + pipelineResource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "git@github.com:test/test.git"), tb.PipelineResourceSpecParam("Revision", "test"), @@ -205,7 +205,7 @@ func TestNewGitResource_Valid(t *testing.T) { ), ), want: &git.Resource{ - Name: "git-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeGit, URL: "git@github.com:test/test.git", Revision: "test", @@ -220,7 +220,7 @@ func TestNewGitResource_Valid(t *testing.T) { }, }, { desc: "Without SSLVerify", - pipelineResource: tb.PipelineResource("git-resource", + pipelineResource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "git@github.com:test/test.git"), tb.PipelineResourceSpecParam("Revision", "test"), @@ -229,7 +229,7 @@ func TestNewGitResource_Valid(t *testing.T) { ), ), want: &git.Resource{ - Name: "git-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeGit, URL: "git@github.com:test/test.git", Revision: "test", @@ -244,7 +244,7 @@ func TestNewGitResource_Valid(t *testing.T) { }, }, { desc: "With HTTPProxy", - pipelineResource: tb.PipelineResource("git-resource", + pipelineResource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "git@github.com:test/test.git"), tb.PipelineResourceSpecParam("Revision", "test"), @@ -253,7 +253,7 @@ func TestNewGitResource_Valid(t *testing.T) { ), ), want: &git.Resource{ - Name: "git-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeGit, URL: "git@github.com:test/test.git", Revision: "test", @@ -268,7 +268,7 @@ func TestNewGitResource_Valid(t *testing.T) { }, }, { desc: "With HTTPSProxy", - pipelineResource: tb.PipelineResource("git-resource", + pipelineResource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "git@github.com:test/test.git"), tb.PipelineResourceSpecParam("Revision", "test"), @@ -277,7 +277,7 @@ func TestNewGitResource_Valid(t *testing.T) { ), ), want: &git.Resource{ - Name: "git-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeGit, URL: "git@github.com:test/test.git", Revision: "test", @@ -292,7 +292,7 @@ func TestNewGitResource_Valid(t *testing.T) { }, }, { desc: "With NOProxy", - pipelineResource: tb.PipelineResource("git-resource", + pipelineResource: tb.PipelineResource("test-resource", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "git@github.com:test/test.git"), tb.PipelineResourceSpecParam("Revision", "test"), @@ -301,7 +301,7 @@ func TestNewGitResource_Valid(t *testing.T) { ), ), want: &git.Resource{ - Name: "git-resource", + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypeGit, URL: "git@github.com:test/test.git", Revision: "test", @@ -316,7 +316,7 @@ func TestNewGitResource_Valid(t *testing.T) { }, }} { t.Run(tc.desc, func(t *testing.T) { - got, err := git.NewResource("override-with-git:latest", tc.pipelineResource) + got, err := git.NewResource("test-resource", "override-with-git:latest", tc.pipelineResource) if err != nil { t.Fatalf("Unexpected error creating Git resource: %s", err) } diff --git a/pkg/apis/resource/v1alpha1/image/image_resource.go b/pkg/apis/resource/v1alpha1/image/image_resource.go index 955928b7a8c..028edfb2b3e 100644 --- a/pkg/apis/resource/v1alpha1/image/image_resource.go +++ b/pkg/apis/resource/v1alpha1/image/image_resource.go @@ -35,12 +35,12 @@ type Resource struct { } // NewResource creates a new ImageResource from a PipelineResourcev1alpha1. -func NewResource(r *resourcev1alpha1.PipelineResource) (*Resource, error) { +func NewResource(name string, r *resourcev1alpha1.PipelineResource) (*Resource, error) { if r.Spec.Type != resourcev1alpha1.PipelineResourceTypeImage { return nil, fmt.Errorf("ImageResource: Cannot create an Image resource from a %s Pipeline Resource", r.Spec.Type) } ir := &Resource{ - Name: r.Name, + Name: name, Type: resourcev1alpha1.PipelineResourceTypeImage, } diff --git a/pkg/apis/resource/v1alpha1/image/image_resource_test.go b/pkg/apis/resource/v1alpha1/image/image_resource_test.go index 502af70110c..2b8be922d45 100644 --- a/pkg/apis/resource/v1alpha1/image/image_resource_test.go +++ b/pkg/apis/resource/v1alpha1/image/image_resource_test.go @@ -28,9 +28,9 @@ import ( ) func TestNewImageResource_Invalid(t *testing.T) { - r := tb.PipelineResource("git-resource", tb.PipelineResourceSpec(v1alpha1.PipelineResourceTypeGit)) + r := tb.PipelineResource("test-resource", tb.PipelineResourceSpec(v1alpha1.PipelineResourceTypeGit)) - _, err := image.NewResource(r) + _, err := image.NewResource("test-resource", r) if err == nil { t.Error("Expected error creating Image resource") } @@ -53,7 +53,7 @@ func TestNewImageResource_Valid(t *testing.T) { ), ) - got, err := image.NewResource(r) + got, err := image.NewResource("image-resource", r) if err != nil { t.Fatalf("Unexpected error creating Image resource: %s", err) } diff --git a/pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource.go b/pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource.go index 12a58767b89..7a045cf0c4d 100644 --- a/pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource.go +++ b/pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource.go @@ -54,12 +54,12 @@ type Resource struct { } // NewResource create a new git resource to pass to a Task -func NewResource(prImage string, r *resourcev1alpha1.PipelineResource) (*Resource, error) { +func NewResource(name, prImage string, r *resourcev1alpha1.PipelineResource) (*Resource, error) { if r.Spec.Type != resourcev1alpha1.PipelineResourceTypePullRequest { return nil, fmt.Errorf("cannot create a PR resource from a %s Pipeline Resource", r.Spec.Type) } prResource := Resource{ - Name: r.Name, + Name: name, Type: r.Spec.Type, Secrets: r.Spec.SecretParams, PRImage: prImage, diff --git a/pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource_test.go b/pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource_test.go index 456558d88ef..1250bf60fd5 100644 --- a/pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource_test.go +++ b/pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource_test.go @@ -38,13 +38,13 @@ func TestPullRequest_NewResource(t *testing.T) { tb.PipelineResourceSpecParam("provider", "github"), tb.PipelineResourceSpecSecretParam("authToken", "test-secret-key", "test-secret-name"), )) - got, err := pullrequest.NewResource("override-with-pr:latest", pr) + got, err := pullrequest.NewResource("test-resource", "override-with-pr:latest", pr) if err != nil { t.Fatalf("Error creating storage resource: %s", err.Error()) } want := &pullrequest.Resource{ - Name: pr.Name, + Name: "test-resource", Type: resourcev1alpha1.PipelineResourceTypePullRequest, URL: url, Provider: "github", @@ -59,7 +59,7 @@ func TestPullRequest_NewResource(t *testing.T) { func TestPullRequest_NewResource_error(t *testing.T) { pr := tb.PipelineResource("foo", tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGit)) - if _, err := pullrequest.NewResource("override-with-pr:latest", pr); err == nil { + if _, err := pullrequest.NewResource("test-resource", "override-with-pr:latest", pr); err == nil { t.Error("NewPullRequestResource() want error, got nil") } } diff --git a/pkg/apis/resource/v1alpha1/storage/build_gcs.go b/pkg/apis/resource/v1alpha1/storage/build_gcs.go index dc540230346..f3132d20613 100644 --- a/pkg/apis/resource/v1alpha1/storage/build_gcs.go +++ b/pkg/apis/resource/v1alpha1/storage/build_gcs.go @@ -71,7 +71,7 @@ type BuildGCSResource struct { } // NewBuildGCSResource creates a new BuildGCS resource to pass to a Task. -func NewBuildGCSResource(images pipeline.Images, r *resource.PipelineResource) (*BuildGCSResource, error) { +func NewBuildGCSResource(name string, images pipeline.Images, r *resource.PipelineResource) (*BuildGCSResource, error) { if r.Spec.Type != resource.PipelineResourceTypeStorage { return nil, fmt.Errorf("BuildGCSResource: Cannot create a BuildGCS resource from a %s Pipeline Resource", r.Spec.Type) } @@ -99,7 +99,7 @@ func NewBuildGCSResource(images pipeline.Images, r *resource.PipelineResource) ( return nil, fmt.Errorf("BuildGCSResource: Need ArtifactType to be specified to create BuildGCS resource %s", r.Name) } return &BuildGCSResource{ - Name: r.Name, + Name: name, Type: r.Spec.Type, Location: location, ArtifactType: aType, diff --git a/pkg/apis/resource/v1alpha1/storage/build_gcs_test.go b/pkg/apis/resource/v1alpha1/storage/build_gcs_test.go index 71c90a35e40..fde0185a9d4 100644 --- a/pkg/apis/resource/v1alpha1/storage/build_gcs_test.go +++ b/pkg/apis/resource/v1alpha1/storage/build_gcs_test.go @@ -95,7 +95,7 @@ func TestBuildGCSResource_Invalid(t *testing.T) { )), }} { t.Run(tc.name, func(t *testing.T) { - _, err := storage.NewResource(images, tc.pipelineResource) + _, err := storage.NewResource("test-resource", images, tc.pipelineResource) if err == nil { t.Error("Expected error creating BuildGCS resource") } @@ -111,7 +111,7 @@ func TestNewBuildGCSResource_Valid(t *testing.T) { tb.PipelineResourceSpecParam("ArtifactType", "Manifest"), )) expectedGCSResource := &storage.BuildGCSResource{ - Name: "build-gcs-resource", + Name: "test-resource", Location: "gs://fake-bucket", Type: resourcev1alpha1.PipelineResourceTypeStorage, ArtifactType: "Manifest", @@ -119,7 +119,7 @@ func TestNewBuildGCSResource_Valid(t *testing.T) { BuildGCSFetcherImage: "gcr.io/cloud-builders/gcs-fetcher:latest", } - r, err := storage.NewBuildGCSResource(images, pr) + r, err := storage.NewBuildGCSResource("test-resource", images, pr) if err != nil { t.Fatalf("Unexpected error creating BuildGCS resource: %s", err) } @@ -190,7 +190,7 @@ func TestBuildGCS_InvalidArtifactType(t *testing.T) { tb.PipelineResourceSpecParam("type", "build-gcs"), tb.PipelineResourceSpecParam("ArtifactType", "InVaLiD"), )) - if _, err := storage.NewBuildGCSResource(images, pr); err == nil { + if _, err := storage.NewBuildGCSResource("test-resource", images, pr); err == nil { t.Error("NewBuildGCSResource: expected error") } } diff --git a/pkg/apis/resource/v1alpha1/storage/gcs.go b/pkg/apis/resource/v1alpha1/storage/gcs.go index 4851c8857e4..21e2d1b1cbc 100644 --- a/pkg/apis/resource/v1alpha1/storage/gcs.go +++ b/pkg/apis/resource/v1alpha1/storage/gcs.go @@ -53,7 +53,7 @@ type GCSResource struct { } // NewGCSResource creates a new GCS resource to pass to a Task -func NewGCSResource(images pipeline.Images, r *resourcev1alpha1.PipelineResource) (*GCSResource, error) { +func NewGCSResource(name string, images pipeline.Images, r *resourcev1alpha1.PipelineResource) (*GCSResource, error) { if r.Spec.Type != resourcev1alpha1.PipelineResourceTypeStorage { return nil, fmt.Errorf("GCSResource: Cannot create a GCS resource from a %s Pipeline Resource", r.Spec.Type) } @@ -76,7 +76,7 @@ func NewGCSResource(images pipeline.Images, r *resourcev1alpha1.PipelineResource return nil, fmt.Errorf("GCSResource: Need Location to be specified in order to create GCS resource %s", r.Name) } return &GCSResource{ - Name: r.Name, + Name: name, Type: r.Spec.Type, Location: location, TypeDir: dir, diff --git a/pkg/apis/resource/v1alpha1/storage/gcs_test.go b/pkg/apis/resource/v1alpha1/storage/gcs_test.go index e9c14e6f500..8843d61ee3b 100644 --- a/pkg/apis/resource/v1alpha1/storage/gcs_test.go +++ b/pkg/apis/resource/v1alpha1/storage/gcs_test.go @@ -71,7 +71,7 @@ func TestInvalidNewStorageResource(t *testing.T) { ), }} { t.Run(tc.name, func(t *testing.T) { - _, err := storage.NewResource(images, tc.pipelineResource) + _, err := storage.NewResource("test-resource", images, tc.pipelineResource) if err == nil { t.Error("Expected error creating GCS resource") } @@ -88,7 +88,7 @@ func TestValidNewGCSResource(t *testing.T) { tb.PipelineResourceSpecSecretParam("GOOGLE_APPLICATION_CREDENTIALS", "secretName", "secretKey"), )) expectedGCSResource := &storage.GCSResource{ - Name: "gcs-resource", + Name: "test-resource", Location: "gs://fake-bucket", Type: resourcev1alpha1.PipelineResourceTypeStorage, TypeDir: true, @@ -101,7 +101,7 @@ func TestValidNewGCSResource(t *testing.T) { GsutilImage: "google/cloud-sdk", } - gcsRes, err := storage.NewGCSResource(images, pr) + gcsRes, err := storage.NewGCSResource("test-resource", images, pr) if err != nil { t.Fatalf("Unexpected error creating GCS resource: %s", err) } @@ -133,7 +133,7 @@ func TestGetParams(t *testing.T) { tb.PipelineResourceSpecParam("type", "gcs"), tb.PipelineResourceSpecSecretParam("test-field-name", "test-secret-name", "test-secret-key"), )) - gcsResource, err := storage.NewResource(images, pr) + gcsResource, err := storage.NewResource("test-resource", images, pr) if err != nil { t.Fatalf("Error creating storage resource: %s", err.Error()) } diff --git a/pkg/apis/resource/v1alpha1/storage/storage.go b/pkg/apis/resource/v1alpha1/storage/storage.go index 7a9149ada88..e3c0f445ca6 100644 --- a/pkg/apis/resource/v1alpha1/storage/storage.go +++ b/pkg/apis/resource/v1alpha1/storage/storage.go @@ -44,7 +44,7 @@ type PipelineStorageResourceInterface interface { // NewResource returns an instance of the requested storage subtype, which can be used // to add input and output steps and volumes to an executing pod. -func NewResource(images pipeline.Images, r *resource.PipelineResource) (PipelineStorageResourceInterface, error) { +func NewResource(name string, images pipeline.Images, r *resource.PipelineResource) (PipelineStorageResourceInterface, error) { if r.Spec.Type != v1beta1.PipelineResourceTypeStorage { return nil, fmt.Errorf("StoreResource: Cannot create a storage resource from a %s Pipeline Resource", r.Spec.Type) } @@ -53,9 +53,9 @@ func NewResource(images pipeline.Images, r *resource.PipelineResource) (Pipeline if strings.EqualFold(param.Name, "type") { switch { case strings.EqualFold(param.Value, string(resource.PipelineResourceTypeGCS)): - return NewGCSResource(images, r) + return NewGCSResource(name, images, r) case strings.EqualFold(param.Value, string(resource.PipelineResourceTypeBuildGCS)): - return NewBuildGCSResource(images, r) + return NewBuildGCSResource(name, images, r) default: return nil, fmt.Errorf("%s is an invalid or unimplemented PipelineStorageResource", param.Value) } diff --git a/pkg/reconciler/events/cloudevent/cloud_event_controller.go b/pkg/reconciler/events/cloudevent/cloud_event_controller.go index 2bb69dd20fc..523520273b5 100644 --- a/pkg/reconciler/events/cloudevent/cloud_event_controller.go +++ b/pkg/reconciler/events/cloudevent/cloud_event_controller.go @@ -31,13 +31,13 @@ import ( // InitializeCloudEvents initializes the CloudEvents part of the // TaskRunStatus from a slice of PipelineResources -func InitializeCloudEvents(tr *v1beta1.TaskRun, prs []*resource.PipelineResource) { +func InitializeCloudEvents(tr *v1beta1.TaskRun, prs map[string]*resource.PipelineResource) { // If there are no cloud event resources, this check will run on every reconcile if len(tr.Status.CloudEvents) == 0 { var targets []string - for _, output := range prs { + for name, output := range prs { if output.Spec.Type == resource.PipelineResourceTypeCloudEvent { - cer, _ := cloudevent.NewResource(output) + cer, _ := cloudevent.NewResource(name, output) targets = append(targets, cer.TargetURI) } } diff --git a/pkg/reconciler/events/cloudevent/cloud_event_controller_test.go b/pkg/reconciler/events/cloudevent/cloud_event_controller_test.go index 669d68e43f8..df462fa8488 100644 --- a/pkg/reconciler/events/cloudevent/cloud_event_controller_test.go +++ b/pkg/reconciler/events/cloudevent/cloud_event_controller_test.go @@ -271,7 +271,11 @@ func TestInitializeCloudEvents(t *testing.T) { }} for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - InitializeCloudEvents(tc.taskRun, tc.pipelineResources) + prMap := map[string]*resourcev1alpha1.PipelineResource{} + for _, pr := range tc.pipelineResources { + prMap[pr.Name] = pr + } + InitializeCloudEvents(tc.taskRun, prMap) opts := GetCloudEventDeliveryCompareOptions() if d := cmp.Diff(tc.wantTaskRun.Status, tc.taskRun.Status, opts...); d != "" { t.Errorf("Wrong Cloud Events Status %s", diff.PrintWantGot(d)) diff --git a/pkg/reconciler/pipelinerun/resources/conditionresolution.go b/pkg/reconciler/pipelinerun/resources/conditionresolution.go index fe319985e1b..973988b1d07 100644 --- a/pkg/reconciler/pipelinerun/resources/conditionresolution.go +++ b/pkg/reconciler/pipelinerun/resources/conditionresolution.go @@ -140,7 +140,7 @@ func ApplyResourceSubstitution(step *v1beta1.Step, resolvedResources map[string] replacements := make(map[string]string) for _, cr := range conditionResources { if rSpec, ok := resolvedResources[cr.Name]; ok { - r, err := resource.FromType(rSpec, images) + r, err := resource.FromType(cr.Name, rSpec, images) if err != nil { return fmt.Errorf("error trying to create resource: %w", err) } diff --git a/pkg/reconciler/taskrun/resources/apply_test.go b/pkg/reconciler/taskrun/resources/apply_test.go index b51ecbbdb54..2f0d238e49e 100644 --- a/pkg/reconciler/taskrun/resources/apply_test.go +++ b/pkg/reconciler/taskrun/resources/apply_test.go @@ -345,7 +345,7 @@ var ( "bucket": gcsResource, } - gitResource, _ = resource.FromType(&resourcev1alpha1.PipelineResource{ + gitResource, _ = resource.FromType("git-resource", &resourcev1alpha1.PipelineResource{ ObjectMeta: metav1.ObjectMeta{ Name: "git-resource", }, @@ -358,7 +358,7 @@ var ( }, }, images) - imageResource, _ = resource.FromType(&resourcev1alpha1.PipelineResource{ + imageResource, _ = resource.FromType("image-resource", &resourcev1alpha1.PipelineResource{ ObjectMeta: metav1.ObjectMeta{ Name: "image-resource", }, @@ -371,7 +371,7 @@ var ( }, }, images) - gcsResource, _ = resource.FromType(&resourcev1alpha1.PipelineResource{ + gcsResource, _ = resource.FromType("gcs-resource", &resourcev1alpha1.PipelineResource{ ObjectMeta: metav1.ObjectMeta{ Name: "gcs-resource", }, diff --git a/pkg/reconciler/taskrun/resources/image_exporter.go b/pkg/reconciler/taskrun/resources/image_exporter.go index c2c3a3a1b9e..f9b19a9568f 100644 --- a/pkg/reconciler/taskrun/resources/image_exporter.go +++ b/pkg/reconciler/taskrun/resources/image_exporter.go @@ -50,7 +50,7 @@ func AddOutputImageDigestExporter( return fmt.Errorf("failed to get output pipeline Resource for taskRun %q resource %v; error: %w while adding output image digest exporter", tr.Name, boundResource, err) } if resource.Spec.Type == v1beta1.PipelineResourceTypeImage { - imageResource, err := image.NewResource(resource) + imageResource, err := image.NewResource(trb.Name, resource) if err != nil { return fmt.Errorf("invalid Image Resource for taskRun %q resource %v; error: %w", tr.Name, boundResource, err) } diff --git a/pkg/reconciler/taskrun/resources/image_exporter_test.go b/pkg/reconciler/taskrun/resources/image_exporter_test.go index 98eb9baac1d..f90cea50988 100644 --- a/pkg/reconciler/taskrun/resources/image_exporter_test.go +++ b/pkg/reconciler/taskrun/resources/image_exporter_test.go @@ -93,7 +93,7 @@ func TestAddOutputImageDigestExporter(t *testing.T) { Name: "image-digest-exporter-9l9zj", Image: "override-with-imagedigest-exporter-image:latest", Command: []string{"/ko-app/imagedigestexporter"}, - Args: []string{"-images", "[{\"name\":\"source-image-1\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"/workspace/output/source-image\"}]"}, + Args: []string{"-images", "[{\"name\":\"source-image\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"/workspace/output/source-image\"}]"}, }}}, }, { desc: "image resource in task with multiple steps", @@ -158,7 +158,7 @@ func TestAddOutputImageDigestExporter(t *testing.T) { Name: "image-digest-exporter-9l9zj", Image: "override-with-imagedigest-exporter-image:latest", Command: []string{"/ko-app/imagedigestexporter"}, - Args: []string{"-images", "[{\"name\":\"source-image-1\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"/workspace/output/source-image\"}]"}, + Args: []string{"-images", "[{\"name\":\"source-image\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"/workspace/output/source-image\"}]"}, }}}, }} { t.Run(c.desc, func(t *testing.T) { diff --git a/pkg/reconciler/taskrun/resources/input_resource_test.go b/pkg/reconciler/taskrun/resources/input_resource_test.go index 49e2baac206..a200e936d09 100644 --- a/pkg/reconciler/taskrun/resources/input_resource_test.go +++ b/pkg/reconciler/taskrun/resources/input_resource_test.go @@ -279,7 +279,7 @@ func setUp() { }} inputResourceInterfaces = make(map[string]v1beta1.PipelineResourceInterface) for _, r := range rs { - ri, _ := resource.FromType(r, images) + ri, _ := resource.FromType(r.Name, r, images) inputResourceInterfaces[r.Name] = ri } } @@ -840,14 +840,25 @@ gsutil cp gs://fake-bucket/rules.zip /workspace/gcs-dir }, wantErr: false, want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{Container: corev1.Container{ - Name: "kubeconfig-9l9zj", - Image: "override-with-kubeconfig-writer:latest", - Command: []string{"/ko-app/kubeconfigwriter"}, - Args: []string{ - "-clusterConfig", `{"name":"cluster3","type":"cluster","url":"http://10.10.10.10","revision":"","username":"","password":"","namespace":"namespace1","token":"","Insecure":false,"cadata":"bXktY2EtY2VydAo=","clientKeyData":"Y2xpZW50LWtleS1kYXRh","clientCertificateData":"Y2xpZW50LWNlcnRpZmljYXRlLWRhdGE=","secrets":null}`, + Steps: []v1beta1.Step{ + { + Container: corev1.Container{ + Name: "kubeconfig-9l9zj", + Image: "override-with-kubeconfig-writer:latest", + Command: []string{"/ko-app/kubeconfigwriter"}, + Args: []string{ + "-clusterConfig", `{"name":"cluster3","type":"cluster","url":"http://10.10.10.10","revision":"","username":"","password":"","namespace":"namespace1","token":"","Insecure":false,"cadata":"bXktY2EtY2VydAo=","clientKeyData":"Y2xpZW50LWtleS1kYXRh","clientCertificateData":"Y2xpZW50LWNlcnRpZmljYXRlLWRhdGE=","secrets":null}`, + }, + }, }, - }}}, + { + Container: corev1.Container{ + Name: "ln-dir-cluster3-mz4c7", + Image: "busybox", + Command: []string{"ln", "-s", "/workspace/cluster3", "/workspace/cluster3"}, + }, + }, + }, Resources: &v1beta1.TaskResources{ Inputs: clusterInputs, }, @@ -888,25 +899,36 @@ gsutil cp gs://fake-bucket/rules.zip /workspace/gcs-dir }, wantErr: false, want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{Container: corev1.Container{ - Name: "kubeconfig-9l9zj", - Image: "override-with-kubeconfig-writer:latest", - Command: []string{"/ko-app/kubeconfigwriter"}, - Args: []string{ - "-clusterConfig", `{"name":"cluster2","type":"cluster","url":"http://10.10.10.10","revision":"","username":"","password":"","namespace":"","token":"","Insecure":false,"cadata":null,"clientKeyData":null,"clientCertificateData":null,"secrets":[{"fieldName":"cadata","secretKey":"cadatakey","secretName":"secret1"}]}`, - }, - Env: []corev1.EnvVar{{ - ValueFrom: &corev1.EnvVarSource{ - SecretKeyRef: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret1", - }, - Key: "cadatakey", + Steps: []v1beta1.Step{ + { + Container: corev1.Container{ + Name: "kubeconfig-9l9zj", + Image: "override-with-kubeconfig-writer:latest", + Command: []string{"/ko-app/kubeconfigwriter"}, + Args: []string{ + "-clusterConfig", `{"name":"cluster2","type":"cluster","url":"http://10.10.10.10","revision":"","username":"","password":"","namespace":"","token":"","Insecure":false,"cadata":null,"clientKeyData":null,"clientCertificateData":null,"secrets":[{"fieldName":"cadata","secretKey":"cadatakey","secretName":"secret1"}]}`, }, + Env: []corev1.EnvVar{{ + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: "secret1", + }, + Key: "cadatakey", + }, + }, + Name: "CADATA", + }}, }, - Name: "CADATA", - }}, - }}}, + }, + { + Container: corev1.Container{ + Name: "ln-dir-cluster2-mz4c7", + Image: "busybox", + Command: []string{"ln", "-s", "/workspace/cluster2", "/workspace/cluster2"}, + }, + }, + }, Resources: &v1beta1.TaskResources{ Inputs: clusterInputs, }, @@ -1452,7 +1474,7 @@ func mockResolveTaskResources(taskRun *v1beta1.TaskRun) map[string]v1beta1.Pipel i = inputResourceInterfaces[r.ResourceRef.Name] resolved[r.Name] = i case r.ResourceSpec != nil: - i, _ = resource.FromType(&resourcev1alpha1.PipelineResource{ + i, _ = resource.FromType(r.Name, &resourcev1alpha1.PipelineResource{ ObjectMeta: metav1.ObjectMeta{ Name: r.Name, }, diff --git a/pkg/reconciler/taskrun/resources/output_resource_test.go b/pkg/reconciler/taskrun/resources/output_resource_test.go index b6a0632aea4..7e112f0ef99 100644 --- a/pkg/reconciler/taskrun/resources/output_resource_test.go +++ b/pkg/reconciler/taskrun/resources/output_resource_test.go @@ -151,7 +151,7 @@ func outputTestResourceSetup() { outputTestResources = make(map[string]v1beta1.PipelineResourceInterface) for _, r := range rs { - ri, _ := resource.FromType(r, images) + ri, _ := resource.FromType(r.Name, r, images) outputTestResources[r.Name] = ri } } @@ -1335,7 +1335,7 @@ func resolveInputResources(taskRun *v1beta1.TaskRun) map[string]v1beta1.Pipeline i = outputTestResources[name] resolved[r.Name] = i } else if r.ResourceSpec != nil { - i, _ = resource.FromType(&resourcev1alpha1.PipelineResource{ + i, _ = resource.FromType(name, &resourcev1alpha1.PipelineResource{ ObjectMeta: metav1.ObjectMeta{ Name: r.Name, }, @@ -1358,7 +1358,7 @@ func resolveOutputResources(taskRun *v1beta1.TaskRun) map[string]v1beta1.Pipelin i = outputTestResources[name] resolved[r.Name] = i } else if r.ResourceSpec != nil { - i, _ = resource.FromType(&resourcev1alpha1.PipelineResource{ + i, _ = resource.FromType(r.Name, &resourcev1alpha1.PipelineResource{ ObjectMeta: metav1.ObjectMeta{ Name: r.Name, }, diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index e1fa4c79472..94ae7f285de 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -323,11 +323,7 @@ func (c *Reconciler) prepare(ctx context.Context, tr *v1beta1.TaskRun) (*v1beta1 // FIXME(afrittoli) This resource specific logic will have to be replaced // once we have a custom PipelineResource framework in place. c.Logger.Infof("Cloud Events: %s", tr.Status.CloudEvents) - prs := make([]*resourcev1alpha1.PipelineResource, 0, len(rtr.Outputs)) - for _, pr := range rtr.Outputs { - prs = append(prs, pr) - } - cloudevent.InitializeCloudEvents(tr, prs) + cloudevent.InitializeCloudEvents(tr, rtr.Outputs) return taskSpec, rtr, nil } @@ -675,7 +671,7 @@ func isExceededResourceQuotaError(err error) bool { func resourceImplBinding(resources map[string]*resourcev1alpha1.PipelineResource, images pipeline.Images) (map[string]v1beta1.PipelineResourceInterface, error) { p := make(map[string]v1beta1.PipelineResourceInterface) for rName, r := range resources { - i, err := resource.FromType(r, images) + i, err := resource.FromType(rName, r, images) if err != nil { return nil, fmt.Errorf("failed to create resource %s : %v with error: %w", rName, r, err) } diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index 7f7cc95f281..b5edf7f8d13 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -948,14 +948,14 @@ func TestReconcile(t *testing.T) { tb.PodRestartPolicy(corev1.RestartPolicyNever), getPlaceToolsInitContainer(), getMkdirResourceContainer("myimage", "/workspace/output/myimage", "mssqb"), - tb.PodContainer("step-git-source-git-resource-mz4c7", "override-with-git:latest", + tb.PodContainer("step-git-source-workspace-mz4c7", "override-with-git:latest", tb.Command(entrypointLocation), tb.Args("-wait_file", "/tekton/tools/0", "-post_file", "/tekton/tools/1", "-termination_path", "/tekton/termination", "-entrypoint", "/ko-app/git-init", "--", "-url", "https://foo.git", "-revision", "master", "-path", "/workspace/workspace"), tb.WorkingDir(workspaceDir), tb.EnvVar("HOME", "/tekton/home"), - tb.EnvVar("TEKTON_RESOURCE_NAME", "git-resource"), + tb.EnvVar("TEKTON_RESOURCE_NAME", "workspace"), tb.EnvVar("HOME", "/tekton/home"), tb.VolumeMount("tekton-internal-tools", "/tekton/tools"), tb.VolumeMount("tekton-internal-workspace", workspaceDir), @@ -992,7 +992,7 @@ func TestReconcile(t *testing.T) { tb.Command(entrypointLocation), tb.Args("-wait_file", "/tekton/tools/3", "-post_file", "/tekton/tools/4", "-termination_path", "/tekton/termination", "-entrypoint", "/ko-app/imagedigestexporter", "--", - "-images", "[{\"name\":\"image-resource\",\"type\":\"image\",\"url\":\"gcr.io/kristoff/sven\",\"digest\":\"\",\"OutputImageDir\":\"/workspace/output/myimage\"}]"), + "-images", "[{\"name\":\"myimage\",\"type\":\"image\",\"url\":\"gcr.io/kristoff/sven\",\"digest\":\"\",\"OutputImageDir\":\"/workspace/output/myimage\"}]"), tb.WorkingDir(workspaceDir), tb.EnvVar("HOME", "/tekton/home"), tb.VolumeMount("tekton-internal-tools", "/tekton/tools"), @@ -1021,7 +1021,7 @@ func TestReconcile(t *testing.T) { tb.PodVolumes(workspaceVolume, homeVolume, resultsVolume, toolsVolume, downwardVolume), tb.PodRestartPolicy(corev1.RestartPolicyNever), getPlaceToolsInitContainer(), - tb.PodContainer("step-git-source-git-resource-9l9zj", "override-with-git:latest", + tb.PodContainer("step-git-source-workspace-9l9zj", "override-with-git:latest", tb.Command(entrypointLocation), tb.Args("-wait_file", "/tekton/downward/ready", @@ -1045,7 +1045,7 @@ func TestReconcile(t *testing.T) { // adds it first and the git pipelineresource adds its own to ensure that HOME // is set even when disable-home-env-overwrite feature flag is "true". tb.EnvVar("HOME", "/tekton/home"), - tb.EnvVar("TEKTON_RESOURCE_NAME", "git-resource"), + tb.EnvVar("TEKTON_RESOURCE_NAME", "workspace"), tb.EnvVar("HOME", "/tekton/home"), tb.VolumeMount("tekton-internal-tools", "/tekton/tools"), tb.VolumeMount("tekton-internal-downward", "/tekton/downward"), diff --git a/test/cluster_resource_test.go b/test/cluster_resource_test.go index d121e8c5e37..f14db10c763 100644 --- a/test/cluster_resource_test.go +++ b/test/cluster_resource_test.go @@ -123,7 +123,7 @@ func getClusterResourceTask(namespace, name, configName string) *v1beta1.Task { Name: "check-file-existence", Image: "ubuntu", Command: []string{"cat"}, - Args: []string{"/workspace/helloworld-cluster/kubeconfig"}, + Args: []string{"$(resources.inputs.target-cluster.path)/kubeconfig"}, }}, {Container: corev1.Container{ Name: "check-config-data", Image: "ubuntu", @@ -137,12 +137,23 @@ func getClusterResourceTask(namespace, name, configName string) *v1beta1.Task { Name: "check-contents", Image: "ubuntu", Command: []string{"bash"}, + Args: []string{"-c", "cmp -b $(resources.inputs.target-cluster.path)/kubeconfig /config/test.data"}, + VolumeMounts: []corev1.VolumeMount{{ + Name: "config-vol", + MountPath: "/config", + }}, + }}, {Container: corev1.Container{ + // See #2694 + Name: "check-legacy-contents", + Image: "ubuntu", + Command: []string{"bash"}, Args: []string{"-c", "cmp -b /workspace/helloworld-cluster/kubeconfig /config/test.data"}, VolumeMounts: []corev1.VolumeMount{{ Name: "config-vol", MountPath: "/config", }}, - }}}, + }}, + }, }, } } @@ -176,13 +187,13 @@ clusters: - cluster: certificate-authority-data: WTJFdFkyVnlkQW89 server: https://1.1.1.1 - name: helloworld-cluster + name: target-cluster contexts: - context: - cluster: helloworld-cluster + cluster: target-cluster user: test-user - name: helloworld-cluster -current-context: helloworld-cluster + name: target-cluster +current-context: target-cluster kind: Config preferences: {} users: diff --git a/test/v1alpha1/cluster_resource_test.go b/test/v1alpha1/cluster_resource_test.go index 1f6fe479799..bf5a6a9de97 100644 --- a/test/v1alpha1/cluster_resource_test.go +++ b/test/v1alpha1/cluster_resource_test.go @@ -108,14 +108,14 @@ func getClusterResourceTask(name, configName string) *v1alpha1.Task { }, })), tb.Step("ubuntu", tb.StepName("check-file-existence"), - tb.StepCommand("cat"), tb.StepArgs("/workspace/helloworld-cluster/kubeconfig"), + tb.StepCommand("cat"), tb.StepArgs("/workspace/target-cluster/kubeconfig"), ), tb.Step("ubuntu", tb.StepName("check-config-data"), tb.StepCommand("cat"), tb.StepArgs("/config/test.data"), tb.StepVolumeMount("config-vol", "/config"), ), tb.Step("ubuntu", tb.StepName("check-contents"), - tb.StepCommand("bash"), tb.StepArgs("-c", "cmp -b /workspace/helloworld-cluster/kubeconfig /config/test.data"), + tb.StepCommand("bash"), tb.StepArgs("-c", "cmp -b /workspace/target-cluster/kubeconfig /config/test.data"), tb.StepVolumeMount("config-vol", "/config"), ), )) @@ -140,13 +140,13 @@ clusters: - cluster: certificate-authority-data: WTJFdFkyVnlkQW89 server: https://1.1.1.1 - name: helloworld-cluster + name: target-cluster contexts: - context: - cluster: helloworld-cluster + cluster: target-cluster user: test-user - name: helloworld-cluster -current-context: helloworld-cluster + name: target-cluster +current-context: target-cluster kind: Config preferences: {} users: