diff --git a/docs/eventlisteners.md b/docs/eventlisteners.md index 579a2b47a3..3b8d523b0b 100644 --- a/docs/eventlisteners.md +++ b/docs/eventlisteners.md @@ -591,7 +591,7 @@ accept to the `eventTypes` field. Valid values can be found in Bitbucket The body/header of the incoming request will be preserved in this Interceptor's response. - + ```YAML --- apiVersion: triggers.tekton.dev/v1alpha1 diff --git a/examples/bitbucket/bitbucket-eventlistener-interceptor.yaml b/examples/bitbucket/bitbucket-eventlistener-interceptor.yaml deleted file mode 100644 index f0a12adb31..0000000000 --- a/examples/bitbucket/bitbucket-eventlistener-interceptor.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -apiVersion: triggers.tekton.dev/v1alpha1 -kind: EventListener -metadata: - name: bitbucket-listener -spec: - serviceAccountName: tekton-triggers-bitbucket-sa - triggers: - - name: bitbucket-triggers - interceptors: - - bitbucket: - secretRef: - secretName: bitbucket-secret - secretKey: secretToken - eventTypes: - - repo:refs_changed - bindings: - - ref: bitbucket-binding - template: - ref: bitbucket-template diff --git a/examples/bitbucket/bitbucket-listener.yaml b/examples/bitbucket/bitbucket-listener.yaml new file mode 100644 index 0000000000..feec4a4bac --- /dev/null +++ b/examples/bitbucket/bitbucket-listener.yaml @@ -0,0 +1,24 @@ +--- +apiVersion: triggers.tekton.dev/v1alpha1 +kind: EventListener +metadata: + name: bitbucket-listener +spec: + serviceAccountName: tekton-triggers-example-sa + triggers: + - name: bitbucket-triggers + interceptors: + - ref: + name: "bitbucket" + params: + - name: secretRef + value: + secretName: bitbucket-secret + secretKey: secretToken + - name: eventTypes + value: + - repo:refs_changed + bindings: + - ref: bitbucket-binding + template: + ref: bitbucket-template diff --git a/examples/custom-resource/github-knative-listener-customresource.yaml b/examples/custom-resource/github-knative-listener-customresource.yaml index 1db7be1b94..db8dffc794 100644 --- a/examples/custom-resource/github-knative-listener-customresource.yaml +++ b/examples/custom-resource/github-knative-listener-customresource.yaml @@ -7,14 +7,21 @@ spec: triggers: - name: github-listener interceptors: - - github: - secretRef: - secretName: github-secret - secretKey: secretToken - eventTypes: - - pull_request - - cel: - filter: "body.action in ['opened', 'synchronize', 'reopened']" + - ref: + name: "github" + params: + - name: "secretRef" + value: + secretName: github-secret + secretKey: secretToken + - name: "eventTypes" + value: ["pull_request"] + - name: "only when PRs are opened" + ref: + name: "cel" + params: + - name: "filter" + value: "body.action in ['opened', 'synchronize', 'reopened']" bindings: - ref: github-pr-binding template: diff --git a/examples/eventlistener-tls-connection/tls-eventlistener-interceptor.yaml b/examples/eventlistener-tls-connection/tls-eventlistener-interceptor.yaml index de4d98a8c4..affc241bbd 100644 --- a/examples/eventlistener-tls-connection/tls-eventlistener-interceptor.yaml +++ b/examples/eventlistener-tls-connection/tls-eventlistener-interceptor.yaml @@ -7,14 +7,21 @@ spec: triggers: - name: tls-listener interceptors: - - github: - secretRef: - secretName: github-secret - secretKey: secretToken - eventTypes: - - pull_request - - cel: - filter: "body.action in ['opened', 'synchronize', 'reopened']" + - ref: + name: "github" + params: + - name: "secretRef" + value: + secretName: github-secret + secretKey: secretToken + - name: "eventTypes" + value: ["pull_request"] + - name: "only when PRs are opened" + ref: + name: "cel" + params: + - name: "filter" + value: "body.action in ['opened', 'synchronize', 'reopened']" bindings: - ref: tls-pr-binding template: diff --git a/examples/eventlisteners/cel-eventlistener-interceptor-with-secret.yaml b/examples/eventlisteners/cel-eventlistener-interceptor-with-secret.yaml index a1c8a289ee..b983217939 100644 --- a/examples/eventlisteners/cel-eventlistener-interceptor-with-secret.yaml +++ b/examples/eventlisteners/cel-eventlistener-interceptor-with-secret.yaml @@ -15,8 +15,11 @@ spec: triggers: - name: cel-trig-with-matches interceptors: - - cel: - filter: "'test-secret'.compareSecret('token', 'mysecret')" + - - ref: + name: "cel" + params: + - name: "filter" + value: "'test-secret'.compareSecret('token', 'mysecret')" bindings: - ref: pipeline-binding template: diff --git a/examples/eventlisteners/cel-eventlistener-interceptor.yaml b/examples/eventlisteners/cel-eventlistener-interceptor.yaml index 8f20ed0321..3d7c552c23 100644 --- a/examples/eventlisteners/cel-eventlistener-interceptor.yaml +++ b/examples/eventlisteners/cel-eventlistener-interceptor.yaml @@ -7,11 +7,15 @@ spec: triggers: - name: cel-trig-with-matches interceptors: - - cel: - filter: "header.match('X-GitHub-Event', 'pull_request')" - overlays: - - key: truncated_sha - expression: "body.pull_request.head.sha.truncate(7)" + - ref: + name: "cel" + params: + - name: "filter" + value: "header.match('X-GitHub-Event', 'pull_request')" + - name: "overlays" + value: + - key: truncated_sha + expression: "body.pull_request.head.sha.truncate(7)" bindings: - name: sha value: $(extensions.truncated_sha) diff --git a/examples/eventlisteners/cel-eventlistener-multiple-overlays.yaml b/examples/eventlisteners/cel-eventlistener-multiple-overlays.yaml index 380b0378b6..23b4f4a071 100644 --- a/examples/eventlisteners/cel-eventlistener-multiple-overlays.yaml +++ b/examples/eventlisteners/cel-eventlistener-multiple-overlays.yaml @@ -7,12 +7,15 @@ spec: triggers: - name: cel-trig interceptors: - - cel: - overlays: - - key: truncated_sha - expression: "body.pull_request.head.sha.truncate(7)" - - key: branch_name - expression: "body.ref.split('/')[2]" + - ref: + name: "cel" + params: + - name: "overlays" + value: + - key: truncated_sha + expression: "body.pull_request.head.sha.truncate(7)" + - key: branch_name + expression: "body.ref.split('/')[2]" bindings: - name: sha value: $(extensions.truncated_sha) diff --git a/examples/eventlisteners/cel-eventlistener-no-filter.yaml b/examples/eventlisteners/cel-eventlistener-no-filter.yaml index 1b4672b2b3..63ab6ce559 100644 --- a/examples/eventlisteners/cel-eventlistener-no-filter.yaml +++ b/examples/eventlisteners/cel-eventlistener-no-filter.yaml @@ -7,10 +7,13 @@ spec: triggers: - name: cel-trig interceptors: - - cel: - overlays: - - key: truncated_sha - expression: "body.pull_request.head.sha.truncate(7)" + - ref: + name: "cel" + params: + - name: "overlays" + value: + - key: extensions.truncated_sha + expression: "body.pull_request.head.sha.truncate(7)" bindings: - ref: pipeline-binding template: diff --git a/examples/eventlisteners/eventlistener-multiinterceptor.yaml b/examples/eventlisteners/eventlistener-multiinterceptor.yaml index 1b1ea66945..6188d9e27a 100644 --- a/examples/eventlisteners/eventlistener-multiinterceptor.yaml +++ b/examples/eventlisteners/eventlistener-multiinterceptor.yaml @@ -9,11 +9,15 @@ spec: - name: foo-trig interceptors: - github: - secretRef: - secretName: foo - secretKey: bar - eventTypes: - - pull_request + ref: + name: "github" + params: + - name: "secretRef" + value: + secretName: foo + secretKey: bar + - name: "eventTypes" + value: ["pull_request"] - webhook: header: - name: Foo-Trig-Header1 diff --git a/examples/github/github-eventlistener-interceptor.yaml b/examples/github/github-eventlistener-interceptor.yaml index 828341af70..d6f624a4a8 100644 --- a/examples/github/github-eventlistener-interceptor.yaml +++ b/examples/github/github-eventlistener-interceptor.yaml @@ -7,14 +7,21 @@ spec: triggers: - name: github-listener interceptors: - - github: - secretRef: - secretName: github-secret - secretKey: secretToken - eventTypes: - - pull_request - - cel: - filter: "body.action in ['opened', 'synchronize', 'reopened']" + - ref: + name: "github" + params: + - name: "secretRef" + value: + secretName: github-secret + secretKey: secretToken + - name: "eventTypes" + value: ["pull_request"] + - name: "only when PRs are opened" + ref: + name: "cel" + params: + - name: "filter" + value: "body.action in ['opened', 'synchronize', 'reopened']" bindings: - ref: github-pr-binding template: diff --git a/examples/gitlab/gitlab-push-listener.yaml b/examples/gitlab/gitlab-push-listener.yaml index 4a0d9408dc..439b57db8c 100644 --- a/examples/gitlab/gitlab-push-listener.yaml +++ b/examples/gitlab/gitlab-push-listener.yaml @@ -7,12 +7,18 @@ spec: triggers: - name: gitlab-push-events-trigger interceptors: - - gitlab: - secretRef: - secretName: gitlab-secret - secretKey: secretToken - eventTypes: - - Push Hook # Only push events + - name: "verify-gitlab-payload" + ref: + name: "gitlab" + kind: ClusterInterceptor + params: + - name: secretRef + value: + secretName: "gitlab-secret" + secretKey: "secretToken" + - name: eventTypes + value: + - "Push Hook" bindings: - name: gitrevision value: $(body.checkout_sha) diff --git a/examples/triggers/trigger.yaml b/examples/triggers/trigger.yaml index 748fa45cb8..9558bd2761 100644 --- a/examples/triggers/trigger.yaml +++ b/examples/triggers/trigger.yaml @@ -4,11 +4,15 @@ metadata: name: trigger spec: interceptors: - - cel: - filter: "header.match('X-GitHub-Event', 'pull_request')" - overlays: - - key: extensions.truncated_sha - expression: "body.pull_request.head.sha.truncate(7)" + - ref: + name: "cel" + params: + - name: "filter" + value: "header.match('X-GitHub-Event', 'pull_request')" + - name: "overlays" + value: + - key: extensions.truncated_sha + expression: "body.pull_request.head.sha.truncate(7)" bindings: - ref: pipeline-binding template: diff --git a/examples/event-interceptors/github-validate.yaml b/examples/webhook-interceptors/github-validate.yaml similarity index 100% rename from examples/event-interceptors/github-validate.yaml rename to examples/webhook-interceptors/github-validate.yaml diff --git a/examples/event-interceptors/main.go b/examples/webhook-interceptors/main.go similarity index 100% rename from examples/event-interceptors/main.go rename to examples/webhook-interceptors/main.go diff --git a/go.mod b/go.mod index e895252c39..d1bc022f9e 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,7 @@ require ( google.golang.org/grpc v1.34.0 google.golang.org/protobuf v1.25.0 k8s.io/api v0.19.7 + k8s.io/apiextensions-apiserver v0.19.7 k8s.io/apimachinery v0.19.7 k8s.io/client-go v0.19.7 k8s.io/code-generator v0.19.7 diff --git a/go.sum b/go.sum index 2006c8abc6..dcf1c27a71 100644 --- a/go.sum +++ b/go.sum @@ -222,7 +222,6 @@ github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful v2.15.0+incompatible h1:8KpYO/Xl/ZudZs5RNOEhWMBY4hmzlZhhRd9cu+jrZP4= github.com/emicklei/go-restful v2.15.0+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= -github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -331,7 +330,6 @@ github.com/gogo/protobuf v1.2.2-0.20190730201129-28a6bbf47e48/go.mod h1:SlYgWuQ5 github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -401,7 +399,6 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/ github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/licenseclassifier v0.0.0-20190926221455-842c0d70d702 h1:nVgx26pAe6l/02mYomOuZssv28XkacGw/0WeiTVorqw= github.com/google/licenseclassifier v0.0.0-20190926221455-842c0d70d702/go.mod h1:qsqn2hxC+vURpyBRygGUuinTO42MFRLcsmQ/P8v94+M= github.com/google/mako v0.0.0-20190821191249-122f8dcef9e3/go.mod h1:YzLcVlL+NqWnmUEPuhS1LxDDwGO9WNbVlEXaF4IH35g= github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no= @@ -492,7 +489,6 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= github.com/influxdata/tdigest v0.0.0-20180711151920-a7d76c6f093a/go.mod h1:9GkyshztGufsdPQWjH+ifgnIr3xNUL5syI70g2dzU1o= github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0= -github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o= github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o= @@ -525,7 +521,6 @@ github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= -github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY= github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= @@ -572,7 +567,6 @@ github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3N github.com/miekg/dns v1.1.17/go.mod h1:WgzbA6oji13JREwiNsRDNfl7jYdPnmz+VEuLrA+/48M= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= @@ -640,7 +634,6 @@ github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnh github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/openzipkin/zipkin-go v0.2.5 h1:UwtQQx2pyPIgWYHRg+epgdx1/HnBQTgN3/oIYEJTQzU= github.com/openzipkin/zipkin-go v0.2.5/go.mod h1:KpXfKdgRDnnhsxw4pNIH9Md5lyFqKUa4YDFlwRYAMyE= -github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k= github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw= github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs= @@ -723,7 +716,6 @@ github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0 github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sclevine/spec v1.2.0/go.mod h1:W4J29eT/Kzv7/b9IWLB055Z+qvVC9vt0Arko24q7p+U= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shurcooL/githubv4 v0.0.0-20190718010115-4ba037080260/go.mod h1:hAF0iLZy4td2EX+/8Tw+4nodhlMrwN3HupfaXj3zkGo= github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f/go.mod h1:AuYgA5Kyo4c7HfUmvRGs/6rGlMMV/6B1bVnB9JxJEEg= @@ -754,7 +746,6 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= -github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= @@ -795,7 +786,6 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC github.com/vdemeester/k8s-pkg-credentialprovider v1.19.7/go.mod h1:K2nMO14cgZitdwBqdQps9tInJgcaXcU/7q5F59lpbNI= github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= github.com/vmware/govmomi v0.20.3/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59bHWk6aFU= -github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= @@ -1268,15 +1258,12 @@ gopkg.in/jcmturner/rpc.v1 v1.1.0/go.mod h1:YIdkC4XfD6GXbzje11McwsDuOlZQSb9W4vfLv gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= -gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg= 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 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE= 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 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/pkg/apis/triggers/v1alpha1/event_listener_defaults.go b/pkg/apis/triggers/v1alpha1/event_listener_defaults.go index 83be074d3a..238eb4d634 100644 --- a/pkg/apis/triggers/v1alpha1/event_listener_defaults.go +++ b/pkg/apis/triggers/v1alpha1/event_listener_defaults.go @@ -27,9 +27,11 @@ func (el *EventListener) SetDefaults(ctx context.Context) { if el.Spec.Replicas != nil && *el.Spec.Replicas == 0 { *el.Spec.Replicas = 1 } - for i := range el.Spec.Triggers { - triggerSpecBindingArray(el.Spec.Triggers[i].Bindings). - defaultBindings() + for i, t := range el.Spec.Triggers { + triggerSpecBindingArray(el.Spec.Triggers[i].Bindings).defaultBindings() + for _, ti := range t.Interceptors { + ti.defaultInterceptorKind() + } } // Remove Deprecated Resource Fields // To be removed in a later release #904 diff --git a/pkg/apis/triggers/v1alpha1/event_listener_defaults_test.go b/pkg/apis/triggers/v1alpha1/event_listener_defaults_test.go index 0d9d5581df..8af155abdd 100644 --- a/pkg/apis/triggers/v1alpha1/event_listener_defaults_test.go +++ b/pkg/apis/triggers/v1alpha1/event_listener_defaults_test.go @@ -162,6 +162,32 @@ func TestEventListenerSetDefaults(t *testing.T) { Replicas: ptr.Int32(2), }, }, + }, { + name: "adds interceptorkind when not specified", + in: &v1alpha1.EventListener{ + Spec: v1alpha1.EventListenerSpec{ + Triggers: []v1alpha1.EventListenerTrigger{{ + Interceptors: []*v1alpha1.EventInterceptor{{ + Ref: v1alpha1.InterceptorRef{ + Name: "cel", + }, + }}, + }}, + }, + }, + wc: v1alpha1.WithUpgradeViaDefaulting, + want: &v1alpha1.EventListener{ + Spec: v1alpha1.EventListenerSpec{ + Triggers: []v1alpha1.EventListenerTrigger{{ + Interceptors: []*v1alpha1.EventInterceptor{{ + Ref: v1alpha1.InterceptorRef{ + Name: "cel", + Kind: v1alpha1.ClusterInterceptorKind, + }, + }}, + }}, + }, + }, }} for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { diff --git a/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go b/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go index 87cb3983cb..37a810c18d 100644 --- a/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go +++ b/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go @@ -435,9 +435,9 @@ func TestEventListenerValidate_error(t *testing.T) { Bindings: []*v1alpha1.EventListenerBinding{{Kind: v1alpha1.NamespacedTriggerBindingKind, Ref: "tb"}}, Template: &v1alpha1.EventListenerTemplate{Ref: ptr.String("tt")}, Interceptors: []*v1alpha1.EventInterceptor{{ - GitHub: &v1alpha1.GitHubInterceptor{}, - GitLab: &v1alpha1.GitLabInterceptor{}, - Bitbucket: &v1alpha1.BitbucketInterceptor{}, + DeprecatedGitHub: &v1alpha1.GitHubInterceptor{}, + DeprecatedGitLab: &v1alpha1.GitLabInterceptor{}, + DeprecatedBitbucket: &v1alpha1.BitbucketInterceptor{}, }}, }}, }, @@ -454,7 +454,7 @@ func TestEventListenerValidate_error(t *testing.T) { Bindings: []*v1alpha1.EventListenerBinding{{Kind: v1alpha1.NamespacedTriggerBindingKind, Ref: "tb"}}, Template: &v1alpha1.EventListenerTemplate{Ref: ptr.String("tt")}, Interceptors: []*v1alpha1.EventInterceptor{{ - CEL: &v1alpha1.CELInterceptor{}, + DeprecatedCEL: &v1alpha1.CELInterceptor{}, }}, }}, }, diff --git a/pkg/apis/triggers/v1alpha1/trigger_defaults.go b/pkg/apis/triggers/v1alpha1/trigger_defaults.go index 3a144cda4e..4e3ee75806 100644 --- a/pkg/apis/triggers/v1alpha1/trigger_defaults.go +++ b/pkg/apis/triggers/v1alpha1/trigger_defaults.go @@ -28,6 +28,9 @@ func (t *Trigger) SetDefaults(ctx context.Context) { return } triggerSpecBindingArray(t.Spec.Bindings).defaultBindings() + for _, ti := range t.Spec.Interceptors { + ti.defaultInterceptorKind() + } } // set default TriggerBinding kind for Bindings in TriggerSpec diff --git a/pkg/apis/triggers/v1alpha1/trigger_defaults_test.go b/pkg/apis/triggers/v1alpha1/trigger_defaults_test.go index 5c7a26fe4e..c93761da8d 100644 --- a/pkg/apis/triggers/v1alpha1/trigger_defaults_test.go +++ b/pkg/apis/triggers/v1alpha1/trigger_defaults_test.go @@ -76,6 +76,28 @@ func TestTriggerSetDefaults(t *testing.T) { }}, }, }, + }, { + name: "defaults interceptor ref", + in: &v1alpha1.Trigger{ + Spec: v1alpha1.TriggerSpec{ + Interceptors: []*v1alpha1.TriggerInterceptor{{ + Ref: v1alpha1.InterceptorRef{ + Name: "cel", + }, + }}, + }, + }, + wc: v1alpha1.WithUpgradeViaDefaulting, + want: &v1alpha1.Trigger{ + Spec: v1alpha1.TriggerSpec{ + Interceptors: []*v1alpha1.TriggerInterceptor{{ + Ref: v1alpha1.InterceptorRef{ + Name: "cel", + Kind: v1alpha1.ClusterInterceptorKind, + }, + }}, + }, + }, }} for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { diff --git a/pkg/apis/triggers/v1alpha1/trigger_types.go b/pkg/apis/triggers/v1alpha1/trigger_types.go index 579d7a9f42..e6860af43f 100644 --- a/pkg/apis/triggers/v1alpha1/trigger_types.go +++ b/pkg/apis/triggers/v1alpha1/trigger_types.go @@ -19,6 +19,7 @@ package v1alpha1 import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -82,11 +83,51 @@ type Trigger struct { // TriggerInterceptor provides a hook to intercept and pre-process events type TriggerInterceptor struct { - Webhook *WebhookInterceptor `json:"webhook,omitempty"` - GitHub *GitHubInterceptor `json:"github,omitempty"` - GitLab *GitLabInterceptor `json:"gitlab,omitempty"` - CEL *CELInterceptor `json:"cel,omitempty"` - Bitbucket *BitbucketInterceptor `json:"bitbucket,omitempty"` + // Optional name to identify the current interceptor configuration + Name *string `json:"name,omitempty"` + // Ref refers to the Interceptor to use + Ref InterceptorRef `json:"ref"` + // Params are the params to send to the interceptor + Params []InterceptorParams `json:"params,omitempty"` + + // Deprecated old fields below + Webhook *WebhookInterceptor `json:"webhook,omitempty"` + DeprecatedGitHub *GitHubInterceptor `json:"github,omitempty"` + DeprecatedGitLab *GitLabInterceptor `json:"gitlab,omitempty"` + DeprecatedCEL *CELInterceptor `json:"cel,omitempty"` + DeprecatedBitbucket *BitbucketInterceptor `json:"bitbucket,omitempty"` +} + +type InterceptorParams struct { + Name string `json:"name"` + Value apiextensionsv1.JSON `json:"value"` +} + +type InterceptorRef struct { + // Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names + Name string `json:"name,omitempty"` + // TaskKind indicates the kind of the Interceptor, namespaced or cluster scoped. + // Currently only InterceptorKind is ClusterInterceptor, so the only valid value + // is the default one + // +optional + Kind InterceptorKind `json:"kind,omitempty"` + // API version of the referent + // +optional + APIVersion string `json:"apiVersion,omitempty"` +} + +// InterceptorKind defines the type of Interceptor used by the Trigger. +type InterceptorKind string + +const ( + // ClusterTaskKind indicates that task type has a cluster scope. + ClusterInterceptorKind InterceptorKind = "ClusterInterceptor" +) + +func (ti *TriggerInterceptor) defaultInterceptorKind() { + if ti.Ref.Kind == "" { + ti.Ref.Kind = ClusterInterceptorKind + } } // WebhookInterceptor provides a webhook to intercept and pre-process events @@ -125,7 +166,7 @@ type CELInterceptor struct { Overlays []CELOverlay `json:"overlays,omitempty"` } -// CELOverlay provides a way to modify the request body using CEL expressions +// CELOverlay provides a way to modify the request body using DeprecatedCEL expressions type CELOverlay struct { Key string `json:"key,omitempty"` Expression string `json:"expression,omitempty"` diff --git a/pkg/apis/triggers/v1alpha1/trigger_validation.go b/pkg/apis/triggers/v1alpha1/trigger_validation.go index 4aaaf917a1..b6b82fe26a 100644 --- a/pkg/apis/triggers/v1alpha1/trigger_validation.go +++ b/pkg/apis/triggers/v1alpha1/trigger_validation.go @@ -90,8 +90,10 @@ func (t triggerSpecBindingArray) validate(ctx context.Context) (errs *apis.Field } func (i *TriggerInterceptor) validate(ctx context.Context) (errs *apis.FieldError) { - if i.Webhook == nil && i.GitHub == nil && i.GitLab == nil && i.CEL == nil && i.Bitbucket == nil { - errs = errs.Also(apis.ErrMissingField("interceptor")) + if i.Webhook == nil && i.DeprecatedGitHub == nil && i.DeprecatedGitLab == nil && i.DeprecatedCEL == nil && i.DeprecatedBitbucket == nil { + if i.Ref.Name == "" { // Check to see if Interceptor referenced using Ref + errs = errs.Also(apis.ErrMissingField("interceptor")) + } } // Enforce oneof @@ -99,13 +101,13 @@ func (i *TriggerInterceptor) validate(ctx context.Context) (errs *apis.FieldErro if i.Webhook != nil { numSet++ } - if i.GitHub != nil { + if i.DeprecatedGitHub != nil { numSet++ } - if i.GitLab != nil { + if i.DeprecatedGitLab != nil { numSet++ } - if i.Bitbucket != nil { + if i.DeprecatedBitbucket != nil { numSet++ } @@ -143,32 +145,22 @@ func (i *TriggerInterceptor) validate(ctx context.Context) (errs *apis.FieldErro } } - // No github validation required yet. - // if i.GitHub != nil { - // - // } - - // No gitlab validation required yet. - // if i.GitLab != nil { - // - // } - - if i.CEL != nil { - if i.CEL.Filter == "" && len(i.CEL.Overlays) == 0 { + if i.DeprecatedCEL != nil { + if i.DeprecatedCEL.Filter == "" && len(i.DeprecatedCEL.Overlays) == 0 { errs = errs.Also(apis.ErrMultipleOneOf("cel.filter", "cel.overlays")) } env, err := cel.NewEnv() if err != nil { - errs = errs.Also(apis.ErrInvalidValue(fmt.Errorf("failed to create a CEL env: %s", err), "cel.filter")) + errs = errs.Also(apis.ErrInvalidValue(fmt.Errorf("failed to create a DeprecatedCEL env: %s", err), "cel.filter")) } - if i.CEL.Filter != "" { - if _, issues := env.Parse(i.CEL.Filter); issues != nil && issues.Err() != nil { - errs = errs.Also(apis.ErrInvalidValue(fmt.Errorf("failed to parse the CEL filter: %s", issues.Err()), "cel.filter")) + if i.DeprecatedCEL.Filter != "" { + if _, issues := env.Parse(i.DeprecatedCEL.Filter); issues != nil && issues.Err() != nil { + errs = errs.Also(apis.ErrInvalidValue(fmt.Errorf("failed to parse the DeprecatedCEL filter: %s", issues.Err()), "cel.filter")) } } - for _, v := range i.CEL.Overlays { + for _, v := range i.DeprecatedCEL.Overlays { if _, issues := env.Parse(v.Expression); issues != nil && issues.Err() != nil { - errs = errs.Also(apis.ErrInvalidValue(fmt.Errorf("failed to parse the CEL overlay: %s", issues.Err()), "cel.overlay")) + errs = errs.Also(apis.ErrInvalidValue(fmt.Errorf("failed to parse the DeprecatedCEL overlay: %s", issues.Err()), "cel.overlay")) } } } diff --git a/pkg/apis/triggers/v1alpha1/trigger_validation_test.go b/pkg/apis/triggers/v1alpha1/trigger_validation_test.go index 2c76d991ed..fc86990679 100644 --- a/pkg/apis/triggers/v1alpha1/trigger_validation_test.go +++ b/pkg/apis/triggers/v1alpha1/trigger_validation_test.go @@ -379,9 +379,9 @@ func TestTriggerValidate_error(t *testing.T) { Bindings: []*v1alpha1.TriggerSpecBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind, Ref: "tb"}}, Template: v1alpha1.TriggerSpecTemplate{Ref: ptr.String("tt")}, Interceptors: []*v1alpha1.TriggerInterceptor{{ - GitHub: &v1alpha1.GitHubInterceptor{}, - GitLab: &v1alpha1.GitLabInterceptor{}, - Bitbucket: &v1alpha1.BitbucketInterceptor{}, + DeprecatedGitHub: &v1alpha1.GitHubInterceptor{}, + DeprecatedGitLab: &v1alpha1.GitLabInterceptor{}, + DeprecatedBitbucket: &v1alpha1.BitbucketInterceptor{}, }}, }, }, @@ -396,7 +396,7 @@ func TestTriggerValidate_error(t *testing.T) { Bindings: []*v1alpha1.TriggerSpecBinding{{Name: "tb", Kind: v1alpha1.NamespacedTriggerBindingKind, Ref: "tb"}}, Template: v1alpha1.TriggerSpecTemplate{Ref: ptr.String("tt")}, Interceptors: []*v1alpha1.TriggerInterceptor{{ - CEL: &v1alpha1.CELInterceptor{}, + DeprecatedCEL: &v1alpha1.CELInterceptor{}, }}, }, }, diff --git a/pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go index d1a75ff38e..5f7008f100 100644 --- a/pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go @@ -512,6 +512,39 @@ func (in *GitLabInterceptor) DeepCopy() *GitLabInterceptor { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *InterceptorParams) DeepCopyInto(out *InterceptorParams) { + *out = *in + in.Value.DeepCopyInto(&out.Value) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InterceptorParams. +func (in *InterceptorParams) DeepCopy() *InterceptorParams { + if in == nil { + return nil + } + out := new(InterceptorParams) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *InterceptorRef) DeepCopyInto(out *InterceptorRef) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InterceptorRef. +func (in *InterceptorRef) DeepCopy() *InterceptorRef { + if in == nil { + return nil + } + out := new(InterceptorRef) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *KubernetesResource) DeepCopyInto(out *KubernetesResource) { *out = *in @@ -857,28 +890,41 @@ func (in *TriggerContext) DeepCopy() *TriggerContext { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TriggerInterceptor) DeepCopyInto(out *TriggerInterceptor) { *out = *in + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } + out.Ref = in.Ref + if in.Params != nil { + in, out := &in.Params, &out.Params + *out = make([]InterceptorParams, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } if in.Webhook != nil { in, out := &in.Webhook, &out.Webhook *out = new(WebhookInterceptor) (*in).DeepCopyInto(*out) } - if in.GitHub != nil { - in, out := &in.GitHub, &out.GitHub + if in.DeprecatedGitHub != nil { + in, out := &in.DeprecatedGitHub, &out.DeprecatedGitHub *out = new(GitHubInterceptor) (*in).DeepCopyInto(*out) } - if in.GitLab != nil { - in, out := &in.GitLab, &out.GitLab + if in.DeprecatedGitLab != nil { + in, out := &in.DeprecatedGitLab, &out.DeprecatedGitLab *out = new(GitLabInterceptor) (*in).DeepCopyInto(*out) } - if in.CEL != nil { - in, out := &in.CEL, &out.CEL + if in.DeprecatedCEL != nil { + in, out := &in.DeprecatedCEL, &out.DeprecatedCEL *out = new(CELInterceptor) (*in).DeepCopyInto(*out) } - if in.Bitbucket != nil { - in, out := &in.Bitbucket, &out.Bitbucket + if in.DeprecatedBitbucket != nil { + in, out := &in.DeprecatedBitbucket, &out.DeprecatedBitbucket *out = new(BitbucketInterceptor) (*in).DeepCopyInto(*out) } diff --git a/pkg/interceptors/interceptors.go b/pkg/interceptors/interceptors.go index 6dc449a625..d211b84fc5 100644 --- a/pkg/interceptors/interceptors.go +++ b/pkg/interceptors/interceptors.go @@ -96,38 +96,40 @@ func GetInterceptorParams(i *triggersv1.EventInterceptor) map[string]interface{} ip["objectRef"] = i.Webhook.ObjectRef ip["header"] = i.Webhook.Header } - case i.GitHub != nil: - if i.GitHub.EventTypes != nil { - ip["eventTypes"] = i.GitHub.EventTypes + case i.DeprecatedGitHub != nil: + if i.DeprecatedGitHub.EventTypes != nil { + ip["eventTypes"] = i.DeprecatedGitHub.EventTypes } - if i.GitHub.SecretRef != nil { - ip["secretRef"] = i.GitHub.SecretRef + if i.DeprecatedGitHub.SecretRef != nil { + ip["secretRef"] = i.DeprecatedGitHub.SecretRef } - case i.GitLab != nil: - if i.GitLab.EventTypes != nil { - ip["eventTypes"] = i.GitLab.EventTypes + case i.DeprecatedGitLab != nil: + if i.DeprecatedGitLab.EventTypes != nil { + ip["eventTypes"] = i.DeprecatedGitLab.EventTypes } - if i.GitLab.SecretRef != nil { - ip["secretRef"] = i.GitLab.SecretRef + if i.DeprecatedGitLab.SecretRef != nil { + ip["secretRef"] = i.DeprecatedGitLab.SecretRef } - case i.CEL != nil: - if i.CEL.Filter != "" { - ip["filter"] = i.CEL.Filter + case i.DeprecatedCEL != nil: + if i.DeprecatedCEL.Filter != "" { + ip["filter"] = i.DeprecatedCEL.Filter } - if i.CEL.Overlays != nil { - ip["overlays"] = i.CEL.Overlays + if i.DeprecatedCEL.Overlays != nil { + ip["overlays"] = i.DeprecatedCEL.Overlays } - - case i.Bitbucket != nil: - if i.Bitbucket.EventTypes != nil { - ip["eventTypes"] = i.Bitbucket.EventTypes + case i.DeprecatedBitbucket != nil: + if i.DeprecatedBitbucket.EventTypes != nil { + ip["eventTypes"] = i.DeprecatedBitbucket.EventTypes + } + if i.DeprecatedBitbucket.SecretRef != nil { + ip["secretRef"] = i.DeprecatedBitbucket.SecretRef } - if i.Bitbucket.SecretRef != nil { - ip["secretRef"] = i.Bitbucket.SecretRef + case i.Params != nil: + for _, p := range i.Params { + ip[p.Name] = p.Value } } - return ip } @@ -175,13 +177,15 @@ func GetName(i *triggersv1.TriggerInterceptor) string { // This is temporary until we implement #868 name := "" switch { - case i.Bitbucket != nil: + case i.Ref.Name != "": + name = i.Ref.Name + case i.DeprecatedBitbucket != nil: name = "bitbucket" - case i.CEL != nil: + case i.DeprecatedCEL != nil: name = "cel" - case i.GitHub != nil: + case i.DeprecatedGitHub != nil: name = "github" - case i.GitLab != nil: + case i.DeprecatedGitLab != nil: name = "gitlab" } return name diff --git a/pkg/interceptors/interceptors_test.go b/pkg/interceptors/interceptors_test.go index 1e65f38ed4..f15f1faa94 100644 --- a/pkg/interceptors/interceptors_test.go +++ b/pkg/interceptors/interceptors_test.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "github.com/tektoncd/triggers/test" "net/http" "net/http/httptest" "net/url" @@ -52,7 +53,7 @@ func TestGetInterceptorParams(t *testing.T) { }{{ name: "cel", in: triggersv1.EventInterceptor{ - CEL: &triggersv1.CELInterceptor{ + DeprecatedCEL: &triggersv1.CELInterceptor{ Filter: `header.match("foo", "bar")`, Overlays: []triggersv1.CELOverlay{{ Key: "short_sha", @@ -70,7 +71,7 @@ func TestGetInterceptorParams(t *testing.T) { }, { name: "gitlab", in: triggersv1.EventInterceptor{ - GitLab: &triggersv1.GitLabInterceptor{ + DeprecatedGitLab: &triggersv1.GitLabInterceptor{ SecretRef: &triggersv1.SecretRef{ SecretKey: "test-secret", SecretName: "token", @@ -88,7 +89,7 @@ func TestGetInterceptorParams(t *testing.T) { }, { name: "github", in: triggersv1.EventInterceptor{ - GitHub: &triggersv1.GitHubInterceptor{ + DeprecatedGitHub: &triggersv1.GitHubInterceptor{ SecretRef: &triggersv1.SecretRef{ SecretKey: "test-secret", SecretName: "token", @@ -106,7 +107,7 @@ func TestGetInterceptorParams(t *testing.T) { }, { name: "bitbucket", in: triggersv1.EventInterceptor{ - Bitbucket: &triggersv1.BitbucketInterceptor{ + DeprecatedBitbucket: &triggersv1.BitbucketInterceptor{ SecretRef: &triggersv1.SecretRef{ SecretKey: "test-secret", SecretName: "token", @@ -155,6 +156,30 @@ func TestGetInterceptorParams(t *testing.T) { }, }}, }, + }, { + name: "interceptor using ref", + in: triggersv1.EventInterceptor{ + Ref: triggersv1.InterceptorRef{ + Name: "gitlab", + }, + Params: []triggersv1.InterceptorParams{{ + Name: "eventTypes", + Value: test.ToV1JSON(t, []string{"push"}), + }, { + Name: "secretRef", + Value: test.ToV1JSON(t, triggersv1.SecretRef{ + SecretKey: "test-secret", + SecretName: "token", + }), + }}, + }, + want: map[string]interface{}{ + "eventTypes": test.ToV1JSON(t, []string{"push"}), + "secretRef": test.ToV1JSON(t, triggersv1.SecretRef{ + SecretKey: "test-secret", + SecretName: "token", + }), + }, }} { t.Run(tc.name, func(t *testing.T) { got := interceptors.GetInterceptorParams(&tc.in) @@ -300,28 +325,28 @@ func makeSecret(secretText string) *corev1.Secret { } } -func TestResolvePath(t *testing.T) { +func TestGetName(t *testing.T) { for _, tc := range []struct { in triggersv1.EventInterceptor want string }{{ in: triggersv1.EventInterceptor{ - CEL: &triggersv1.CELInterceptor{}, + DeprecatedCEL: &triggersv1.CELInterceptor{}, }, want: "cel", }, { in: triggersv1.EventInterceptor{ - GitLab: &triggersv1.GitLabInterceptor{}, + DeprecatedGitLab: &triggersv1.GitLabInterceptor{}, }, want: "gitlab", }, { in: triggersv1.EventInterceptor{ - GitHub: &triggersv1.GitHubInterceptor{}, + DeprecatedGitHub: &triggersv1.GitHubInterceptor{}, }, want: "github", }, { in: triggersv1.EventInterceptor{ - Bitbucket: &triggersv1.BitbucketInterceptor{}, + DeprecatedBitbucket: &triggersv1.BitbucketInterceptor{}, }, want: "bitbucket", }, { @@ -329,6 +354,13 @@ func TestResolvePath(t *testing.T) { Webhook: &triggersv1.WebhookInterceptor{}, }, want: "", + }, { + in: triggersv1.EventInterceptor{ + Ref: triggersv1.InterceptorRef{ + Name: "pluggable-interceptor", + }, + }, + want: "pluggable-interceptor", }} { t.Run(tc.want, func(t *testing.T) { got := interceptors.GetName(&tc.in) diff --git a/pkg/interceptors/server/server.go b/pkg/interceptors/server/server.go index 59d26ec681..5e1383219b 100644 --- a/pkg/interceptors/server/server.go +++ b/pkg/interceptors/server/server.go @@ -118,7 +118,7 @@ func (is *Server) ExecuteInterceptor(r *http.Request) ([]byte, error) { if err := json.Unmarshal(body.Bytes(), &ireq); err != nil { return nil, badRequest(fmt.Errorf("failed to parse body as InterceptorRequest: %w", err)) } - // Decorate ctx with eventID + is.Logger.Debugf("Interceptor Request is: %+v", ireq) iresp := ii.Process(ctx, &ireq) respBytes, err := json.Marshal(iresp) if err != nil { diff --git a/pkg/sink/sink.go b/pkg/sink/sink.go index 4b48369998..55d8db6dff 100644 --- a/pkg/sink/sink.go +++ b/pkg/sink/sink.go @@ -22,9 +22,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" - "net/http" - triggersv1 "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1" triggersclientset "github.com/tektoncd/triggers/pkg/client/clientset/versioned" listers "github.com/tektoncd/triggers/pkg/client/listers/triggers/v1alpha1" @@ -34,12 +31,14 @@ import ( "github.com/tektoncd/triggers/pkg/template" "github.com/tidwall/sjson" "go.uber.org/zap" + "io/ioutil" kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" discoveryclient "k8s.io/client-go/discovery" "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" + "net/http" ) // Sink defines the sink resource for processing incoming events for the diff --git a/pkg/sink/sink_test.go b/pkg/sink/sink_test.go index 4373313b2c..3c06dc2466 100644 --- a/pkg/sink/sink_test.go +++ b/pkg/sink/sink_test.go @@ -536,15 +536,19 @@ func TestHandleEvent(t *testing.T) { }, Spec: triggersv1.TriggerSpec{ Interceptors: []*triggersv1.EventInterceptor{{ - GitHub: &triggersv1.GitHubInterceptor{ - SecretRef: &triggersv1.SecretRef{ + Ref: triggersv1.InterceptorRef{Name: "github"}, + Params: []triggersv1.InterceptorParams{{ + Name: "secretRef", + Value: test.ToV1JSON(t, &triggersv1.SecretRef{ SecretKey: "secretKey", SecretName: "secret", - }, - EventTypes: []string{"pull_request"}, - }, + }), + }, { + Name: "eventTypes", + Value: test.ToV1JSON(t, []string{"pull_request"}), + }}, }, { - CEL: &triggersv1.CELInterceptor{ + DeprecatedCEL: &triggersv1.CELInterceptor{ Overlays: []triggersv1.CELOverlay{ // FIXME: We aren't really testing that this value can be used in a binding tho {Key: "new", Expression: "body.repository.url"}, @@ -593,13 +597,17 @@ func TestHandleEvent(t *testing.T) { }, Spec: triggersv1.TriggerSpec{ Interceptors: []*triggersv1.EventInterceptor{{ - Bitbucket: &triggersv1.BitbucketInterceptor{ - SecretRef: &triggersv1.SecretRef{ + Ref: triggersv1.InterceptorRef{Name: "bitbucket"}, + Params: []triggersv1.InterceptorParams{{ + Name: "secretRef", + Value: test.ToV1JSON(t, &triggersv1.SecretRef{ SecretKey: "secretKey", SecretName: "secret", - }, - EventTypes: []string{"repo:refs_changed"}, - }, + }), + }, { + Name: "eventTypes", + Value: test.ToV1JSON(t, []string{"repo:refs_changed"}), + }}, }}, Bindings: gitCloneTBSpec, Template: triggersv1.TriggerSpecTemplate{Spec: &gitCloneTTSpec}, @@ -819,13 +827,17 @@ func TestHandleEvent_AuthOverride(t *testing.T) { Spec: triggersv1.TriggerSpec{ ServiceAccountName: testCase.userVal, Interceptors: []*triggersv1.EventInterceptor{{ - GitHub: &triggersv1.GitHubInterceptor{ - SecretRef: &triggersv1.SecretRef{ + Ref: triggersv1.InterceptorRef{Name: "github"}, + Params: []triggersv1.InterceptorParams{{ + Name: "secretRef", + Value: test.ToV1JSON(t, &triggersv1.SecretRef{ SecretKey: "secretKey", SecretName: "secret", - }, - EventTypes: []string{"pull_request"}, - }, + }), + }, { + Name: "eventTypes", + Value: test.ToV1JSON(t, []string{"pull_request"}), + }}, }}, Bindings: []*triggersv1.TriggerSpecBinding{{ Name: "url", @@ -1162,9 +1174,11 @@ func TestExecuteInterceptor_NotContinue(t *testing.T) { trigger := triggersv1.Trigger{ Spec: triggersv1.TriggerSpec{ Interceptors: []*triggersv1.EventInterceptor{{ - CEL: &triggersv1.CELInterceptor{ - Filter: `body.head == "abcde"`, - }, + Ref: triggersv1.InterceptorRef{Name: "cel"}, + Params: []triggersv1.InterceptorParams{{ + Name: "filter", + Value: test.ToV1JSON(t, `body.head == "abcde"`), + }}, }}}, } url, _ := url.Parse("http://example.com") @@ -1214,12 +1228,14 @@ func TestExecuteInterceptor_ExtensionChaining(t *testing.T) { trigger := triggersv1.Trigger{ Spec: triggersv1.TriggerSpec{ Interceptors: []*triggersv1.EventInterceptor{{ - CEL: &triggersv1.CELInterceptor{ - Overlays: []triggersv1.CELOverlay{{ + Ref: triggersv1.InterceptorRef{Name: "cel"}, + Params: []triggersv1.InterceptorParams{{ + Name: "overlays", + Value: test.ToV1JSON(t, []triggersv1.CELOverlay{{ Key: "truncated_sha", Expression: "body.sha.truncate(5)", - }}, - }, + }}), + }}, }, { Webhook: &triggersv1.WebhookInterceptor{ ObjectRef: &corev1.ObjectReference{ @@ -1229,9 +1245,11 @@ func TestExecuteInterceptor_ExtensionChaining(t *testing.T) { }, }, }, { - CEL: &triggersv1.CELInterceptor{ - Filter: "body.extensions.truncated_sha == \"abcde\" && extensions.truncated_sha == \"abcde\"", - }, + Ref: triggersv1.InterceptorRef{Name: "cel"}, + Params: []triggersv1.InterceptorParams{{ + Name: "filter", + Value: test.ToV1JSON(t, "body.extensions.truncated_sha == \"abcde\" && extensions.truncated_sha == \"abcde\""), + }}, }}, }, } diff --git a/test/builder/eventlistener.go b/test/builder/eventlistener.go index c2da12e885..2cc8067a25 100644 --- a/test/builder/eventlistener.go +++ b/test/builder/eventlistener.go @@ -292,7 +292,7 @@ func EventInterceptorParam(name, value string) EventInterceptorOp { func EventListenerCELInterceptor(filter string, ops ...EventInterceptorOp) EventListenerTriggerOp { return func(t *v1alpha1.EventListenerTrigger) { i := &v1alpha1.EventInterceptor{ - CEL: &v1alpha1.CELInterceptor{ + DeprecatedCEL: &v1alpha1.CELInterceptor{ Filter: filter, }, } @@ -305,8 +305,8 @@ func EventListenerCELInterceptor(filter string, ops ...EventInterceptorOp) Event func EventListenerCELOverlay(key, expression string) EventInterceptorOp { return func(i *v1alpha1.EventInterceptor) { - if i.CEL != nil { - i.CEL.Overlays = append(i.CEL.Overlays, v1alpha1.CELOverlay{ + if i.DeprecatedCEL != nil { + i.DeprecatedCEL.Overlays = append(i.DeprecatedCEL.Overlays, v1alpha1.CELOverlay{ Key: key, Expression: expression, }) diff --git a/test/builder/eventlistener_test.go b/test/builder/eventlistener_test.go index 6a0d0293b2..9d8c60c87e 100644 --- a/test/builder/eventlistener_test.go +++ b/test/builder/eventlistener_test.go @@ -468,7 +468,7 @@ func TestEventListenerBuilder(t *testing.T) { ), ), }, { - name: "One Trigger with CEL Interceptor", + name: "One Trigger with DeprecatedCEL Interceptor", normal: &v1alpha1.EventListener{ ObjectMeta: metav1.ObjectMeta{ Name: "name", @@ -479,7 +479,7 @@ func TestEventListenerBuilder(t *testing.T) { Triggers: []v1alpha1.EventListenerTrigger{{ Name: "foo-trig", Interceptors: []*v1alpha1.EventInterceptor{{ - CEL: &v1alpha1.CELInterceptor{ + DeprecatedCEL: &v1alpha1.CELInterceptor{ Filter: "body.value == 'test'", Overlays: []v1alpha1.CELOverlay{ {Key: "value", Expression: "'testing'"}, diff --git a/test/builder/trigger.go b/test/builder/trigger.go index dafca38234..ab936c06ce 100644 --- a/test/builder/trigger.go +++ b/test/builder/trigger.go @@ -148,11 +148,11 @@ func TriggerSpecInterceptorParam(name, value string) TriggerInterceptorOp { } } -// TriggerSpecCELInterceptor adds a CEL filter to the TriggerSpecTrigger. +// TriggerSpecCELInterceptor adds a DeprecatedCEL filter to the TriggerSpecTrigger. func TriggerSpecCELInterceptor(filter string, ops ...TriggerInterceptorOp) TriggerSpecOp { return func(spec *v1alpha1.TriggerSpec) { i := &v1alpha1.TriggerInterceptor{ - CEL: &v1alpha1.CELInterceptor{ + DeprecatedCEL: &v1alpha1.CELInterceptor{ Filter: filter, }, } @@ -163,11 +163,11 @@ func TriggerSpecCELInterceptor(filter string, ops ...TriggerInterceptorOp) Trigg } } -// TriggerSpecCELOverlay modifies CEL interceptor +// TriggerSpecCELOverlay modifies DeprecatedCEL interceptor func TriggerSpecCELOverlay(key, expression string) TriggerInterceptorOp { return func(i *v1alpha1.TriggerInterceptor) { - if i.CEL != nil { - i.CEL.Overlays = append(i.CEL.Overlays, v1alpha1.CELOverlay{ + if i.DeprecatedCEL != nil { + i.DeprecatedCEL.Overlays = append(i.DeprecatedCEL.Overlays, v1alpha1.CELOverlay{ Key: key, Expression: expression, }) diff --git a/test/builder/trigger_test.go b/test/builder/trigger_test.go index 75f0853edf..a0e66fa750 100644 --- a/test/builder/trigger_test.go +++ b/test/builder/trigger_test.go @@ -244,7 +244,7 @@ func TestTriggerBuilder(t *testing.T) { ServiceAccountName: "serviceAccount", Name: "foo-trig", Interceptors: []*v1alpha1.TriggerInterceptor{{ - CEL: &v1alpha1.CELInterceptor{ + DeprecatedCEL: &v1alpha1.CELInterceptor{ Filter: "body.value == 'test'", Overlays: []v1alpha1.CELOverlay{ {Key: "value", Expression: "'testing'"}, diff --git a/test/eventlistener_test.go b/test/eventlistener_test.go index 74c3be34a0..8ef0445a1b 100644 --- a/test/eventlistener_test.go +++ b/test/eventlistener_test.go @@ -298,9 +298,11 @@ func TestEventListenerCreate(t *testing.T) { Ref: ptr.String(tt.Name), }, Interceptors: []*triggersv1.EventInterceptor{{ - CEL: &triggersv1.CELInterceptor{ - Filter: `body.action == "edited"`, - }, + Ref: triggersv1.InterceptorRef{Name: "cel"}, + Params: []triggersv1.InterceptorParams{{ + Name: "filter", + Value: ToV1JSON(t, `body.action == "edited"`), + }}, }}, }}, Replicas: ptr.Int32(3), diff --git a/test/json.go b/test/json.go new file mode 100644 index 0000000000..8eb4b36768 --- /dev/null +++ b/test/json.go @@ -0,0 +1,20 @@ +package test + +import ( + "encoding/json" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + "testing" +) + + +// ToV1JSON is a wrapper around json.Marshal to easily convert to the Kubernetes apiextensionsv1.JSON type +func ToV1JSON(t testing.TB, v interface{}) apiextensionsv1.JSON { + t.Helper() + b, err := json.Marshal(v) + if err != nil { + t.Fatalf("json.Marshal() failed: %s", err) + } + return apiextensionsv1.JSON{ + Raw: b, + } +} \ No newline at end of file diff --git a/vendor/modules.txt b/vendor/modules.txt index 3d9d28f980..ee5e293e56 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -635,6 +635,7 @@ k8s.io/api/storage/v1 k8s.io/api/storage/v1alpha1 k8s.io/api/storage/v1beta1 # k8s.io/apiextensions-apiserver v0.19.7 +## explicit k8s.io/apiextensions-apiserver/pkg/apis/apiextensions k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1 # k8s.io/apimachinery v0.19.7