forked from MatousJobanek/che-e2e-tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_tenant.sh
executable file
·77 lines (71 loc) · 2.95 KB
/
update_tenant.sh
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
#!/bin/bash
yum install -y centos-release-openshift-origin epel-release
yum install -y origin-clients jq
source config
set +x
OSO_TOKEN=$(curl -X GET -H "Authorization: Bearer ${KEYCLOAK_TOKEN}" \
https://sso.openshift.io/auth/realms/fabric8/broker/openshift-v3/token | jq .access_token | cut -d\" -f2)
if [[ "null" == "${OSO_TOKEN}" ]]; then
set -x
echo "OSO token is empty, cannot proceed with verification. Something went wrong when obtaining it via keycloak."
exit 1
fi
set -x
OSIO_VERSION=$(curl -sSL http://central.maven.org/maven2/io/fabric8/online/apps/che/maven-metadata.xml | grep latest | sed -e 's,.*<latest>\([^<]*\)</latest>.*,\1,g')
echo "Logging in to OpenShift ${OSO_MASTER_URL}"
set +x
oc login ${OSO_MASTER_URL} --token=${OSO_TOKEN}
set -x
oc project ${OSO_NAMESPACE}
CURRENT_DC_REVISION=$(oc get dc/che -o=custom-columns=NAME:.status.latestVersion --no-headers)
NEXT_DC_REVISION=$((CURRENT_DC_REVISION+1))
DOCKER_HUB_NAMESPACE_SANITIZED=${DOCKER_HUB_NAMESPACE/\//\\\/}
current_tag=$(oc get dc/che -o yaml | grep 'image:' | cut -d: -f 3)
if [[ "${current_tag}" != "${CHE_SERVER_DOCKER_IMAGE_TAG}" ]]; then
echo "Updating Che server"
echo "Getting version of OSIO and applying template"
curl -sSL http://central.maven.org/maven2/io/fabric8/online/apps/che/${OSIO_VERSION}/che-${OSIO_VERSION}-openshift.yml | \
sed "s/ hostname-http:.*/ hostname-http: ${OSO_HOSTNAME}/" | \
sed "s/ image:.*/ image: ${DOCKER_HUB_NAMESPACE_SANITIZED}:${CHE_SERVER_DOCKER_IMAGE_TAG}/" | \
oc apply --force=true -f -
sleep 10
## Check status of deployment
che_server_status=$(oc get pods | grep che-${NEXT_DC_REVISION} | grep -v che-${NEXT_DC_REVISION}-deploy | awk '{print $3}')
counter=0
timeout=360
echo "Checking state of Che server pod for ${timeout} seconds"
# Wait up to 6 minutes for running Che pod
set +x
while [ "${che_server_status}" != "Running" ]; do
che_server_status=$(oc get pods | grep che-${NEXT_DC_REVISION} | grep -v che-${NEXT_DC_REVISION}-deploy | awk '{print $3}')
counter=$((counter+1))
if [ $counter -gt $timeout ]; then
set -x
echo "Che server is not running after ${timeout} seconds"
exit 1
fi
sleep 1
done
set -x
echo "Che pod is running."
server_log=$(oc -n ${OSO_NAMESPACE} logs dc/che)
counter=0
timeout=180
echo "Checking whether a Che server in Che pod has already started."
set +x
# Wait up to 3 minute for running Che server in pod
while [[ $(echo "${server_log}" | grep "Server startup in" | wc -l) -ne 1 ]]; do
server_log=$(oc -n ${OSO_NAMESPACE} logs dc/che)
counter=$((counter+1))
if [ $counter -gt $timeout ]; then
set -x
echo "Server log does not contain information about server startup. Timeouted after ${timeout} seconds."
exit 1
fi
sleep 1
done
set -x
echo "Che server is running."
else
echo "Che server already has specified tag, skipping Che server update"
fi