/
pipeline.yaml
223 lines (214 loc) · 6.4 KB
/
pipeline.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: perfscale-demo-app-pipeline-sa
secrets: []
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: perfscale-demo-app-pipeline-role
rules:
- apiGroups: ["extensions", "apps", ""]
resources: ["services", "deployments", "pods", "pvc", "job", "secrets"]
verbs: ["get", "create", "update", "patch", "list", "delete"]
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: perfscale-demo-app-pipeline-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: perfscale-demo-app-pipeline-role
subjects:
- kind: ServiceAccount
name: perfscale-demo-app-pipeline-sa
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: get-run-id
spec:
results:
- name: run-id
steps:
- name: get-run-id
image: quay.io/jhutar/opl
script: |
#!/usr/bin/env bash
date --utc -Ins | sed -e 's/[^a-zA-Z0-9_-]/_/g' -e 's/_00_00$//' | tr -d '\n' > $(results.run-id.path)
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: opl-cli
spec:
workspaces:
- name: main-dir
description: Volume with data you want to work with.
params:
- name: script
description: The OPL CLI script to run
type: string
default: "status_data.py -h"
steps:
- name: opl-cli
image: quay.io/jhutar/opl
workingDir: $(workspaces.main-dir.path)
script: $(params.script)
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: perfscale-demo-app-pipeline
spec:
params: []
workspaces:
- name: linked-workspace
- name: results-ssh-credentials
tasks:
- name: get-run-id
taskRef:
name: get-run-id
- name: fetch-repository-tools
taskRef:
name: git-clone
workspaces:
- name: output
workspace: linked-workspace
params:
- name: url
value: https://github.com/jhutar/my-tekton-perfscale-experiment
- name: subdirectory
value: "my-tekton-perfscale-experiment"
- name: deleteExisting
value: "true"
- name: fetch-repository-app
taskRef:
name: git-clone
workspaces:
- name: output
workspace: linked-workspace
params:
- name: url
value: https://github.com/jhutar/perfscale-demo-app
- name: subdirectory
value: "perfscale-demo-app"
- name: deleteExisting
value: "true"
- name: fetch-repository-results
taskRef:
name: git-cli
params:
- name: GIT_USER_EMAIL
value: jhutar@redhat.com
- name: GIT_USER_NAME
value: Jan Hutar
- name: GIT_SCRIPT
value: |
git clone git@github.com:jhutar/my-tekton-perfscale-experiment-results.git
workspaces:
- name: ssh-directory
workspace: results-ssh-credentials
- name: source
workspace: linked-workspace
- name: create-deployment
taskRef:
name: kubernetes-actions
runAfter:
- fetch-repository-tools
params:
- name: script
value: |
kubectl apply --filename my-tekton-perfscale-experiment/perfscale-demo-app-deploy.yaml
kubectl rollout status deployment/postgresql
kubectl rollout status deployment/perfscale-demo-app
workspaces:
- name: manifest-dir
workspace: linked-workspace
- name: create-test-data
taskRef:
name: kubernetes-actions
runAfter:
- create-deployment
params:
- name: script
value: |
set -x
pod=$( kubectl get pods --no-headers -l app=perfscale-demo-app -o custom-columns=":metadata.name" )
kubectl exec "pod/$pod" -- bash -c "export FLASK_APP=myapp.py; flask test-data"
- name: run-test
taskRef:
name: opl-cli
runAfter:
- create-test-data
- fetch-repository-app
params:
- name: script
value: |
set -x
export PYTHONPATH=$( pwd )/perfscale-demo-app/
export STATUS_DATA_FILE=status-data.json
my-tekton-perfscale-experiment/test-with-opl.py --locust-local-runner --locust-num-clients 10 --locust-hatch-rate 10 --locust-host http://perfscale-demo-service:80 --test-duration 100 || true
workspaces:
- name: main-dir
workspace: linked-workspace
- name: determine-results
taskRef:
name: opl-cli
runAfter:
- run-test
- fetch-repository-results
params:
- name: script
value: |
set -x
status_data.py --status-data-file status-data.json --set id=$(tasks.get-run-id.results.run-id)
pass_or_fail.py --config my-tekton-perfscale-experiment/investigator_config.yaml --current-file status-data.json -d || true
workspaces:
- name: main-dir
workspace: linked-workspace
- name: push-results
taskRef:
name: git-cli
runAfter:
- determine-results
params:
- name: GIT_USER_EMAIL
value: jhutar@redhat.com
- name: GIT_USER_NAME
value: Jan Hutar
- name: GIT_SCRIPT
value: |
mv status-data.json my-tekton-perfscale-experiment-results/status-data-$(tasks.get-run-id.results.run-id).json
cd my-tekton-perfscale-experiment-results/
git add status-data-$(tasks.get-run-id.results.run-id).json
git add decisions.csv || true
git commit -m "Adding result $(tasks.get-run-id.results.run-id)"
git pull --rebase
git push
workspaces:
- name: ssh-directory
workspace: results-ssh-credentials
- name: source
workspace: linked-workspace
- name: delete-deployment
taskRef:
name: kubernetes-actions
runAfter:
- push-results
params:
- name: script
value: |
kubectl delete --filename my-tekton-perfscale-experiment/perfscale-demo-app-deploy.yaml
# Old kubectl in kubernetes-actions? https://github.com/kubernetes/kubernetes/issues/96676
kubectl wait --for=delete deployment/postgresql || true
kubectl wait --for=delete deployment/perfscale-demo-app || true
workspaces:
- name: manifest-dir
workspace: linked-workspace