-
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 EventListener Selector For TriggerCRD
EventListener have NamespaceSelector field which gives us namespaces from where EventListener fetches Trigger object to process events.
- Loading branch information
1 parent
713da5a
commit 7702dc4
Showing
30 changed files
with
912 additions
and
401 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,10 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: foo | ||
--- | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: bar |
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,74 @@ | ||
--- | ||
kind: ClusterRole | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: el-sel-clusterrole | ||
rules: | ||
# Permissions for every EventListener deployment to function | ||
- apiGroups: ["triggers.tekton.dev"] | ||
resources: ["eventlisteners", "clustertriggerbindings", "triggerbindings", "triggertemplates", "triggers"] | ||
verbs: ["get", "list", "watch"] | ||
- apiGroups: [""] | ||
resources: ["configmaps", "secrets"] | ||
verbs: ["get", "list", "watch"] | ||
- apiGroups: [""] | ||
resources: ["serviceaccounts"] | ||
verbs: ["impersonate"] | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: foo-el-sa | ||
namespace: foo | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: el-sel-clusterrolebinding | ||
subjects: | ||
- kind: ServiceAccount | ||
name: foo-el-sa | ||
namespace: foo | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: el-sel-clusterrole | ||
--- | ||
kind: Role | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: triggercr-role | ||
namespace: bar | ||
rules: | ||
- apiGroups: ["tekton.dev"] | ||
resources: ["pipelineruns", "pipelineresources", "taskruns"] | ||
verbs: ["create"] | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: bar-trigger-sa | ||
namespace: bar | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: triggercr-rolebinding | ||
namespace: bar | ||
subjects: | ||
- kind: ServiceAccount | ||
name: bar-trigger-sa | ||
namespace: bar | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: triggercr-role | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: github-secret | ||
namespace: bar | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: triggers.tekton.dev/v1alpha1 | ||
kind: EventListener | ||
metadata: | ||
name: listener-sel | ||
namespace: foo | ||
spec: | ||
serviceAccountName: foo-el-sa | ||
namespaceSelector: | ||
matchNames: | ||
- foo | ||
- bar |
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,77 @@ | ||
--- | ||
apiVersion: triggers.tekton.dev/v1alpha1 | ||
kind: Trigger | ||
metadata: | ||
name: trigger | ||
namespace: bar | ||
spec: | ||
serviceAccountName: bar-trigger-sa | ||
interceptors: | ||
- github: | ||
secretRef: | ||
secretName: github-secret | ||
secretKey: secretToken | ||
eventTypes: | ||
- pull_request | ||
bindings: | ||
- ref: pipeline-binding | ||
template: | ||
ref: pipeline-template | ||
--- | ||
apiVersion: triggers.tekton.dev/v1alpha1 | ||
kind: TriggerBinding | ||
metadata: | ||
name: pipeline-binding | ||
namespace: bar | ||
spec: | ||
params: | ||
- name: gitrevision | ||
value: $(body.head_commit.id) | ||
- name: gitrepositoryurl | ||
value: $(body.repository.url) | ||
- name: contenttype | ||
value: $(header.Content-Type) | ||
--- | ||
apiVersion: triggers.tekton.dev/v1alpha1 | ||
kind: TriggerTemplate | ||
metadata: | ||
name: pipeline-template | ||
namespace: bar | ||
spec: | ||
params: | ||
- name: gitrevision | ||
description: The git revision | ||
default: master | ||
- name: gitrepositoryurl | ||
description: The git repository url | ||
- name: message | ||
description: The message to print | ||
default: This is the default message | ||
- name: contenttype | ||
description: The Content-Type of the event | ||
resourcetemplates: | ||
- apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
generateName: simple-pipeline-run- | ||
spec: | ||
pipelineRef: | ||
name: simple-pipeline | ||
podTemplate: | ||
securityContext: | ||
runAsNonRoot: true | ||
runAsUser: 1001 | ||
params: | ||
- name: message | ||
value: $(tt.params.message) | ||
- name: contenttype | ||
value: $(tt.params.contenttype) | ||
resources: | ||
- name: git-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,46 @@ | ||
## Namespace Selector EventListener | ||
|
||
Creates an EventListener that serve triggers in multiple namespaces. | ||
|
||
### Try it out locally: | ||
|
||
1. To create the namespace selector trigger and all related resources, run: | ||
|
||
```bash | ||
kubectl apply -f examples/selectors/ | ||
``` | ||
|
||
2. Port forward: | ||
|
||
```bash | ||
kubectl config set-context --current --namespace=bar | ||
kubectl apply -f examples/example-pipeline.yaml | ||
``` | ||
|
||
**Note**: Instead of port forwarding, you can set the | ||
[`serviceType`](https://github.com/tektoncd/triggers/blob/master/docs/eventlisteners.md#serviceType) | ||
to `LoadBalancer` to expose the EventListener with a public IP. | ||
|
||
3. Create sample pipelinerun in namespace bar: | ||
```bash | ||
kubectl port-forward \ | ||
-n foo $(kubectl get pod -n foo -o=name \ | ||
-l eventlistener=listener-sel) 8080 | ||
``` | ||
|
||
3. Test by sending the sample payload. | ||
|
||
```bash | ||
curl -k -v \ | ||
-H 'X-GitHub-Event: pull_request' \ | ||
-H 'X-Hub-Signature: sha1=8d7c4d33686fd908394208a07d997b8f5bd70aa6' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{"head_commit":{"id":"28911bbb5a3e2ea034daf1f6be0a822d50e31e73"},"action": "opened", "pull_request":{"head":{"sha": "28911bbb5a3e2ea034daf1f6be0a822d50e31e73"}},"repository":{"clone_url": "https://github.com/tektoncd/triggers.git", "url":"https://github.com/tektoncd/triggers.git"}}' http://localhost:8080 ``` | ||
The response status code should be `201 Created` | ||
4. You should see a new Pipelinerun that got created: | ||
```bash | ||
tkn pr -n bar list | ||
``` |
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
Oops, something went wrong.