Skip to content

Commit 6cb7905

Browse files
committed
ci: Add scheduled eventlistener
Signed-off-by: Ferenc Géczi <[email protected]>
1 parent 1997845 commit 6cb7905

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

.tekton/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ Create the service account with the needed role bindings:
133133

134134
In order to authorize the incoming webhooks into our cluster, we need to share
135135
a secret between our webhook listener, and the GitHub repo.
136+
This resource can be shared across multiple tekton Tri
136137
Generate a long, strong and random generated token, put it into `github-interceptor-secret.yaml`.
137138
Create the secret resource:
138139
````bash
@@ -270,3 +271,21 @@ a simple ping event does not trigger any `PipelineRun` unnecessarily.
270271
eventlistener_pod=$(kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | grep el-github-pr-python-eventlistener-)
271272
kubectl logs -f "${eventlistener_pod}" | grep 'event type ping is not allowed'
272273
````
274+
275+
## Setup Scheduled PipelineRuns
276+
277+
PipelineRuns can be scheduled with a Kubernetes `CronJob` resource,
278+
which calls a Tekton `EventListener`, that triggers
279+
an appropriate PipelineRun. The needed resources can be created
280+
with the following command:
281+
282+
````bash
283+
kubectl apply --filename scheduled-eventlistener.yaml
284+
````
285+
286+
The current schedule is `"5 0 * * Mon-Fri`,
287+
whic means every weekday 00:05 in the pod's timezone.
288+
This can be adjusted by editing the `schedule` attribute.
289+
Currently this triggers the `github-pr-python-tracer-ci-pipeline`
290+
on the head of the `master` branch.
291+
These can also be changed on demand.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
apiVersion: triggers.tekton.dev/v1beta1
2+
kind: TriggerTemplate
3+
metadata:
4+
name: python-tracer-scheduled-ci-pipeline-template
5+
spec:
6+
params:
7+
- description: The ISO-8601 date and time converted to RFC 1123 subdomain names
8+
name: date-time-normalized
9+
- description: The full sha of the git commit
10+
name: git-commit-sha
11+
- description: The short 7 digit sha of the git commit
12+
name: git-commit-short-sha
13+
resourcetemplates:
14+
- apiVersion: tekton.dev/v1
15+
kind: PipelineRun
16+
metadata:
17+
# After variable resolution, this has to be maximum 63 character long,
18+
# lower case, RFC 1123 subdomain name. The regex used for validation is
19+
# '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
20+
name: python-tracer-scheduled-ci-pipeline-$(tt.params.date-time-normalized)-$(tt.params.git-commit-short-sha)
21+
spec:
22+
params:
23+
- name: revision
24+
value: master
25+
- name: git-commit-sha
26+
value: $(tt.params.git-commit-sha)
27+
pipelineRef:
28+
name: github-pr-python-tracer-ci-pipeline
29+
workspaces:
30+
- name: python-tracer-ci-pipeline-pvc
31+
volumeClaimTemplate:
32+
spec:
33+
accessModes:
34+
- ReadWriteOnce
35+
resources:
36+
requests:
37+
storage: 100Mi
38+
---
39+
apiVersion: triggers.tekton.dev/v1beta1
40+
kind: TriggerBinding
41+
metadata:
42+
name: python-tracer-scheduled-binding
43+
spec:
44+
params:
45+
- name: date-time-normalized
46+
value: $(extensions.normalized_date_time)
47+
- name: git-commit-sha
48+
value: $(body.git_master_head_commit_sha)
49+
- name: git-commit-short-sha
50+
value: $(extensions.truncated_sha)
51+
---
52+
apiVersion: batch/v1
53+
kind: CronJob
54+
metadata:
55+
name: python-tracer-scheduled-ci-cronjob
56+
spec:
57+
schedule: "5 0 * * Mon-Fri"
58+
jobTemplate:
59+
spec:
60+
template:
61+
spec:
62+
containers:
63+
- name: git
64+
# alpine/git:2.43.0
65+
image: alpine/git@sha256:6ff4de047dcc8f0c7d75d2efff63fbc189e87d2f458305f2cc8f165ff83309cf
66+
command:
67+
- sh
68+
- -c
69+
- |
70+
wget -O- \
71+
--header 'Content-Type: application/json' \
72+
--post-data '{
73+
"git_master_head_commit_sha":"'"$(git ls-remote https://github.com/instana/python-sensor master | cut -f1)"'",
74+
"date_time":"'"$(date -u -Iminutes )"'"
75+
}' \
76+
'http://el-python-tracer-scheduled-pipeline-listener.default.svc.cluster.local:8080'
77+
restartPolicy: OnFailure
78+
---
79+
apiVersion: triggers.tekton.dev/v1beta1
80+
kind: EventListener
81+
metadata:
82+
name: python-tracer-scheduled-pipeline-listener
83+
spec:
84+
serviceAccountName: tekton-triggers-eventlistener-serviceaccount
85+
triggers:
86+
- name: python-tracer-scheduled-pipeline-triggger
87+
interceptors:
88+
- name: add-truncated-sha
89+
ref:
90+
name: "cel"
91+
params:
92+
- name: "overlays"
93+
value:
94+
- key: truncated_sha
95+
expression: "body.git_master_head_commit_sha.truncate(7)"
96+
- name: add-normalized-date-time
97+
ref:
98+
name: "cel"
99+
params:
100+
- name: "overlays"
101+
value:
102+
- key: normalized_date_time
103+
# The date-time converted to RFC 1123 subdomain names
104+
expression: 'body.date_time.split("+")[0].lowerAscii().translate(":", "-")'
105+
bindings:
106+
- ref: python-tracer-scheduled-binding
107+
template:
108+
ref: python-tracer-scheduled-ci-pipeline-template

0 commit comments

Comments
 (0)