forked from openshift/release
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcluster-launch-installer-libvirt-e2e.yaml
376 lines (355 loc) · 13.5 KB
/
cluster-launch-installer-libvirt-e2e.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
kind: Template
apiVersion: template.openshift.io/v1
# image-family openshift4-libvirt must exist in ${GOOGLE_PROJECT_ID} for this template
# for more info see here: https://github.com/ironcladlou/openshift4-libvirt-gcp/blob/rhel8/IMAGES.md
parameters:
- name: JOB_NAME
required: true
- name: JOB_NAME_SAFE
required: true
- name: JOB_NAME_HASH
required: true
- name: NAMESPACE
required: true
- name: IMAGE_LIBVIRT_INSTALLER
required: true
- name: IMAGE_TESTS
required: true
- name: CLUSTER_TYPE
value: "libvirt"
- name: TEST_COMMAND
required: true
- name: RELEASE_IMAGE_LATEST
required: true
- name: BUILD_ID
required: false
objects:
# We want the cluster to be able to access these images
- kind: RoleBinding
apiVersion: authorization.openshift.io/v1
metadata:
name: ${JOB_NAME_SAFE}-image-puller
namespace: ${NAMESPACE}
roleRef:
name: system:image-puller
subjects:
- kind: SystemGroup
name: system:unauthenticated
- kind: SystemGroup
name: system:authenticated
# Give admin access to a known bot
- kind: RoleBinding
apiVersion: authorization.openshift.io/v1
metadata:
name: ${JOB_NAME_SAFE}-namespace-admins
namespace: ${NAMESPACE}
roleRef:
name: admin
subjects:
- kind: ServiceAccount
namespace: ci
name: ci-chat-bot
# The e2e pod spins up a cluster, runs e2e tests, and then cleans up the cluster.
- kind: Pod
apiVersion: v1
metadata:
name: ${JOB_NAME_SAFE}
namespace: ${NAMESPACE}
annotations:
# we want to gather the teardown logs no matter what
ci-operator.openshift.io/wait-for-container-artifacts: teardown
ci-operator.openshift.io/save-container-logs: "true"
ci-operator.openshift.io/container-sub-tests: "setup,test,teardown"
spec:
restartPolicy: Never
activeDeadlineSeconds: 21600
terminationGracePeriodSeconds: 900
volumes:
- name: artifacts
emptyDir: {}
- name: shared-tmp
emptyDir: {}
- name: cluster-profile
secret:
secretName: ${JOB_NAME_SAFE}-cluster-profile
initContainers:
- name: openshift-tests
image: ${IMAGE_TESTS}
volumeMounts:
- name: shared-tmp
mountPath: /tmp/shared
command:
- cp
- /usr/bin/openshift-tests
- /tmp/shared/openshift-tests
containers:
# Once the cluster is up, executes shared tests
- name: test
image: ${IMAGE_LIBVIRT_INSTALLER}
terminationMessagePolicy: FallbackToLogsOnError
resources:
requests:
cpu: 1
memory: 300Mi
limits:
memory: 3Gi
volumeMounts:
- name: shared-tmp
mountPath: /home/packer
- name: cluster-profile
mountPath: /tmp/cluster
- name: artifacts
mountPath: /tmp/artifacts
env:
- name: HOME
value: /home/packer
- name: NSS_WRAPPER_PASSWD
value: /home/packer/passwd
- name: NSS_WRAPPER_GROUP
value: /home/packer/group
- name: NSS_USERNAME
value: packer
- name: NSS_GROUPNAME
value: packer
- name: GOOGLE_PROJECT_ID
value: openshift-gce-devel-ci
- name: GOOGLE_COMPUTE_ZONE
value: us-east1-c
- name: INSTANCE_PREFIX
value: ${NAMESPACE}-${JOB_NAME_HASH}
command:
- /bin/bash
- -c
- |
#!/bin/bash
set -euo pipefail
trap 'touch "${HOME}"/exit' EXIT
trap 'jobs -p | xargs -r kill || true; exit 0' TERM
mock-nss.sh
gcloud auth activate-service-account \
--quiet --key-file /tmp/cluster/gce.json
gcloud --quiet config set project "${GOOGLE_PROJECT_ID}"
gcloud --quiet config set compute/zone "${GOOGLE_COMPUTE_ZONE}"
# wait for install
while true; do
if [[ -f "${HOME}"/setup-failed ]]; then
echo "Setup reported a failure, do not report test failure" 2>&1
exit 0
fi
if [[ -f "${HOME}"/exit ]]; then
echo "Another process exited" 2>&1
exit 1
fi
if [[ ! -f "${HOME}"/setup-success ]]; then
sleep 15 & wait
continue
fi
break
done
set -x
LD_PRELOAD=/usr/lib64/libnss_wrapper.so gcloud compute --project "${GOOGLE_PROJECT_ID}" ssh \
--zone "${GOOGLE_COMPUTE_ZONE}" \
packer@"${INSTANCE_PREFIX}" \
--command 'export KUBECONFIG=/home/packer/clusters/installer/auth/kubeconfig && /home/packer/run-tests.sh'
# Runs an install
- name: setup
image: ${IMAGE_LIBVIRT_INSTALLER}
volumeMounts:
- name: shared-tmp
mountPath: /home/packer
- name: cluster-profile
mountPath: /tmp/cluster
- name: artifacts
mountPath: /tmp/artifacts
env:
- name: HOME
value: /home/packer
- name: NSS_WRAPPER_PASSWD
value: /home/packer/passwd
- name: NSS_WRAPPER_GROUP
value: /home/packer/group
- name: NSS_USERNAME
value: packer
- name: NSS_GROUPNAME
value: packer
- name: GOOGLE_PROJECT_ID
value: openshift-gce-devel-ci
- name: GOOGLE_COMPUTE_ZONE
value: us-east1-c
- name: GOOGLE_COMPUTE_REGION
value: us-east1
- name: INSTANCE_PREFIX
value: ${NAMESPACE}-${JOB_NAME_HASH}
command:
- /bin/sh
- -c
- |
#!/bin/bash
set -euo pipefail
trap 'rc=$?; if test "${rc}" -eq 0; then touch "${HOME}"/setup-success; else touch "${HOME}"/exit "${HOME}"/setup-failed; fi; exit "${rc}"' EXIT
trap 'CHILDREN=$(jobs -p); if test -n "${CHILDREN}"; then kill ${CHILDREN} && wait; fi' TERM
cat > "${HOME}"/run-tests.sh << 'EOF'
#!/bin/bash
set -euo pipefail
export PATH=/home/packer:$PATH
mkdir -p /tmp/artifacts/junit
function run-tests() {
openshift-tests run "${TEST_SUITE}" \
-o /tmp/artifacts/e2e.log --junit-dir /tmp/artifacts/junit
return 0
}
set -eu
${TEST_COMMAND}
EOF
chmod +x "${HOME}"/run-tests.sh
mock-nss.sh
mkdir "${HOME}"/.ssh
# gcloud compute will use this key rather than create a new one
cp -a /tmp/cluster/ssh-privatekey ~/.ssh/google_compute_engine
cp -a /tmp/cluster/ssh-publickey ~/.ssh/google_compute_engine.pub
gcloud auth activate-service-account \
--quiet --key-file /tmp/cluster/gce.json
gcloud --quiet config set project "${GOOGLE_PROJECT_ID}"
gcloud --quiet config set compute/zone "${GOOGLE_COMPUTE_ZONE}"
gcloud --quiet config set compute/region "${GOOGLE_COMPUTE_REGION}"
set -x
# Create the network and firewall rules to attach it to VM
gcloud compute networks create "${INSTANCE_PREFIX}" \
--subnet-mode=custom \
--bgp-routing-mode=regional
gcloud compute networks subnets create "${INSTANCE_PREFIX}" \
--network "${INSTANCE_PREFIX}" \
--range=10.0.0.0/9
gcloud compute firewall-rules create "${INSTANCE_PREFIX}" \
--network "${INSTANCE_PREFIX}" \
--allow tcp:22,icmp
# image-family openshift4-libvirt must exist in ${GOOGLE_PROJECT_ID} for this template
# for more info see here: https://github.com/ironcladlou/openshift4-libvirt-gcp/blob/rhel8/IMAGES.md
gcloud compute instances create "${INSTANCE_PREFIX}" \
--image-family openshift4-libvirt \
--zone "${GOOGLE_COMPUTE_ZONE}" \
--machine-type n1-standard-16 \
--min-cpu-platform "Intel Haswell" \
--boot-disk-type pd-ssd \
--boot-disk-size 256GB \
--subnet "${INSTANCE_PREFIX}" \
--network "${INSTANCE_PREFIX}"
LD_PRELOAD=/usr/lib64/libnss_wrapper.so gcloud compute scp \
--quiet \
--project "${GOOGLE_PROJECT_ID}" \
--zone "${GOOGLE_COMPUTE_ZONE}" \
--recurse "${HOME}"/run-tests.sh packer@"${INSTANCE_PREFIX}":~/run-tests.sh
LD_PRELOAD=/usr/lib64/libnss_wrapper.so gcloud compute scp \
--quiet \
--project "${GOOGLE_PROJECT_ID}" \
--zone "${GOOGLE_COMPUTE_ZONE}" \
--recurse "${HOME}"/openshift-tests packer@"${INSTANCE_PREFIX}":~/openshift-tests
LD_PRELOAD=/usr/lib64/libnss_wrapper.so gcloud compute scp \
--quiet \
--project "${GOOGLE_PROJECT_ID}" \
--zone "${GOOGLE_COMPUTE_ZONE}" \
--recurse /bin/openshift-install packer@"${INSTANCE_PREFIX}":/home/packer/openshift-install
LD_PRELOAD=/usr/lib64/libnss_wrapper.so gcloud compute scp \
--quiet \
--project "${GOOGLE_PROJECT_ID}" \
--zone "${GOOGLE_COMPUTE_ZONE}" \
/tmp/cluster/pull-secret packer@"${INSTANCE_PREFIX}":/home/packer/pull-secret
LD_PRELOAD=/usr/lib64/libnss_wrapper.so gcloud compute --project "${GOOGLE_PROJECT_ID}" ssh \
--zone "${GOOGLE_COMPUTE_ZONE}" \
packer@"${INSTANCE_PREFIX}" \
--command 'sudo mv /home/packer/openshift-install /usr/local/bin/openshift-install'
set +x
echo 'Will now launch libvirt cluster in the gce instance with "${RELEASE_IMAGE_LATEST}"'
# Install allows up to 30min beyond than what installer allows by default. In the create-cluster script
# see the `wait-for install-complete` added here: https://github.com/ironcladlou/openshift4-libvirt-gcp/blob/rhel8/tools/create-cluster
# https://github.com/openshift/installer/issues/3043
LD_PRELOAD=/usr/lib64/libnss_wrapper.so gcloud compute --project "${GOOGLE_PROJECT_ID}" ssh \
--zone "${GOOGLE_COMPUTE_ZONE}" \
packer@"${INSTANCE_PREFIX}" \
--command 'export OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE="${RELEASE_IMAGE_LATEST}" OPENSHIFT_INSTALL_INVOKER=openshift-internal-ci/${JOB_NAME}/${BUILD_ID} && timeout 150m bash -ce "create-cluster installer"'
# Performs cleanup of all created resources and upload the artifacts
- name: teardown
image: ${IMAGE_LIBVIRT_INSTALLER}
volumeMounts:
- name: shared-tmp
mountPath: /home/packer
- name: cluster-profile
mountPath: /tmp/cluster
- name: artifacts
mountPath: /tmp/artifacts
env:
- name: HOME
value: /home/packer
- name: NSS_WRAPPER_PASSWD
value: /home/packer/passwd
- name: NSS_WRAPPER_GROUP
value: /home/packer/group
- name: NSS_USERNAME
value: packer
- name: NSS_GROUPNAME
value: packer
- name: GOOGLE_PROJECT_ID
value: openshift-gce-devel-ci
- name: GOOGLE_COMPUTE_ZONE
value: us-east1-c
- name: INSTANCE_PREFIX
value: ${NAMESPACE}-${JOB_NAME_HASH}
command:
- /bin/bash
- -c
- |
#!/bin/bash
set -eo pipefail
function teardown() {
# This is for running the gcloud commands
mock-nss.sh
gcloud auth activate-service-account \
--quiet --key-file /tmp/cluster/gce.json
gcloud --quiet config set project "${GOOGLE_PROJECT_ID}"
gcloud --quiet config set compute/zone "${GOOGLE_COMPUTE_ZONE}"
set -x
set +e
echo 'Collect all the info about clusteroperators'
LD_PRELOAD=/usr/lib64/libnss_wrapper.so gcloud compute --project "${GOOGLE_PROJECT_ID}" ssh \
--zone "${GOOGLE_COMPUTE_ZONE}" \
packer@"${INSTANCE_PREFIX}" \
--command 'export KUBECONFIG=/home/$USER/clusters/installer/auth/kubeconfig && bash -ce "oc get co"' | tee /tmp/artifacts/output-co-libvirt
echo 'Run must gather on the cluster'
LD_PRELOAD=/usr/lib64/libnss_wrapper.so gcloud compute --project "${GOOGLE_PROJECT_ID}" ssh \
--zone "${GOOGLE_COMPUTE_ZONE}" \
packer@"${INSTANCE_PREFIX}" \
--command 'mkdir -p $HOME/must-gather && export KUBECONFIG=$HOME/clusters/installer/auth/kubeconfig && bash -ce "oc adm must-gather --dest-dir $HOME/must-gather || true && tar -czC "$HOME/must-gather -f $HOME/must-gather.tar.gz"'
echo "scp everything related to installer back to pod"
LD_PRELOAD=/usr/lib64/libnss_wrapper.so gcloud compute scp \
--quiet \
--project "${GOOGLE_PROJECT_ID}" \
--zone "${GOOGLE_COMPUTE_ZONE}" \
--recurse packer@"${INSTANCE_PREFIX}":$HOME/clusters/installer /tmp/artifacts
echo "scp must-gather logs back to pod"
LD_PRELOAD=/usr/lib64/libnss_wrapper.so gcloud compute scp \
--quiet \
--project "${GOOGLE_PROJECT_ID}" \
--zone "${GOOGLE_COMPUTE_ZONE}" \
--recurse packer@"${INSTANCE_PREFIX}":$HOME/must-gather.tar.gz /tmp/artifacts
echo "scp junit logs back to test pod"
LD_PRELOAD=/usr/lib64/libnss_wrapper.so gcloud compute scp \
--quiet \
--project "${GOOGLE_PROJECT_ID}" \
--zone "${GOOGLE_COMPUTE_ZONE}" \
--recurse packer@"${INSTANCE_PREFIX}":/tmp/artifacts/junit /tmp/artifacts
touch /home/packer/exit
echo "Deprovisioning cluster ..."
gcloud compute instances delete "${INSTANCE_PREFIX}" --quiet
gcloud compute firewall-rules delete "${INSTANCE_PREFIX}" --quiet
gcloud compute networks subnets delete "${INSTANCE_PREFIX}" --quiet
gcloud compute networks delete "${INSTANCE_PREFIX}" --quiet
}
trap 'teardown' EXIT
trap 'jobs -p | xargs -r kill || true; exit 0' TERM
set +x
for i in $(seq 1 220); do
if [[ -f /home/packer/exit ]]; then
exit 0
fi
sleep 60 & wait
done