-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom object to triggers eventlistener
- Loading branch information
1 parent
2a28864
commit 39fb9d7
Showing
29 changed files
with
2,099 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
## GitHub Knative EventListener | ||
|
||
Creates an EventListener that listens for GitHub webhook events. | ||
|
||
### Try it out locally: | ||
|
||
1. To create the custom resource trigger and all related resources, run: | ||
|
||
```bash | ||
kubectl apply -f examples/custom-resource/ | ||
``` | ||
|
||
1. Test by sending the sample payload: | ||
|
||
```bash | ||
curl -v \ | ||
-H 'X-GitHub-Event: pull_request' \ | ||
-H 'X-Hub-Signature: sha1=ba0cdc263b3492a74b601d240c27efe81c4720cb' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{"action": "opened", "pull_request":{"head":{"sha": "28911bbb5a3e2ea034daf1f6be0a822d50e31e73"}},"repository":{"clone_url": "https://github.com/tektoncd/triggers.git"}}' \ | ||
http://localhost:8080 | ||
``` | ||
|
||
The response status code is `201 Created` | ||
|
||
[`HMAC`](https://www.freeformatter.com/hmac-generator.html) tool used to create X-Hub-Signature. | ||
|
||
In [`HMAC`](https://www.freeformatter.com/hmac-generator.html) `string` is the *body payload ex:* `{"action": "opened", "pull_request":{"head":{"sha": "28911bbb5a3e2ea034daf1f6be0a822d50e31e73"}},"repository":{"clone_url": "https://github.com/tektoncd/triggers.git"}}` | ||
and `secretKey` is the *given secretToken ex:* `1234567`. | ||
|
||
1. You will see the newly created TaskRun: | ||
|
||
```bash | ||
kubectl get taskruns | grep github-run- | ||
``` |
84 changes: 84 additions & 0 deletions
84
examples/custom-resource/github-knative-listener-customresource.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- | ||
apiVersion: triggers.tekton.dev/v1alpha1 | ||
kind: EventListener | ||
metadata: | ||
name: github-knative-listener | ||
spec: | ||
triggers: | ||
- name: github-listener | ||
interceptors: | ||
- github: | ||
secretRef: | ||
secretName: github-secret | ||
secretKey: secretToken | ||
eventTypes: | ||
- pull_request | ||
- cel: | ||
filter: "body.action in ['opened', 'synchronize', 'reopened']" | ||
bindings: | ||
- ref: github-pr-binding | ||
template: | ||
ref: github-template | ||
resources: | ||
customResource: | ||
apiVersion: serving.knative.dev/v1 | ||
kind: Service | ||
spec: | ||
template: | ||
spec: | ||
serviceAccountName: tekton-triggers-example-sa | ||
containers: | ||
- resources: | ||
requests: | ||
memory: "64Mi" | ||
cpu: "250m" | ||
limits: | ||
memory: "128Mi" | ||
cpu: "500m" | ||
--- | ||
apiVersion: triggers.tekton.dev/v1alpha1 | ||
kind: TriggerBinding | ||
metadata: | ||
name: github-pr-binding | ||
spec: | ||
params: | ||
- name: gitrevision | ||
value: $(body.pull_request.head.sha) | ||
- name: gitrepositoryurl | ||
value: $(body.repository.clone_url) | ||
|
||
--- | ||
apiVersion: triggers.tekton.dev/v1alpha1 | ||
kind: TriggerTemplate | ||
metadata: | ||
name: github-template | ||
spec: | ||
params: | ||
- name: gitrevision | ||
- name: gitrepositoryurl | ||
resourcetemplates: | ||
- apiVersion: tekton.dev/v1alpha1 | ||
kind: TaskRun | ||
metadata: | ||
generateName: github-run- | ||
spec: | ||
taskSpec: | ||
inputs: | ||
resources: | ||
- name: source | ||
type: git | ||
steps: | ||
- image: ubuntu | ||
script: | | ||
#! /bin/bash | ||
ls -al $(inputs.resources.source.path) | ||
inputs: | ||
resources: | ||
- name: source | ||
resourceSpec: | ||
type: git | ||
params: | ||
- name: revision | ||
value: $(tt.params.gitrevision) | ||
- name: url | ||
value: $(tt.params.gitrepositoryurl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../rbac.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: github-secret | ||
type: Opaque | ||
stringData: | ||
secretToken: "1234567" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.