This repository has been archived by the owner on Oct 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
deploy_utils.sh
executable file
·75 lines (62 loc) · 2.25 KB
/
deploy_utils.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
################################################################
# This is shared library for the installation #
################################################################
function timestamp() {
date +"[%Y-%m-%d %H:%M:%S]"
}
function print_info() {
echo "[keptn|INFO] $(timestamp) $1"
}
function print_debug() {
echo "[keptn|DEBUG] $(timestamp) $1"
}
function print_error() {
echo "[keptn|ERROR] $(timestamp) $1"
}
function verify_install_step() {
if [[ $1 != '0' ]]; then
print_error "$2"
print_error "Stopping keptn installation. Already created resources are not deleted; execute the uninstallKeptn.sh script to clean-up."
exit 1
fi
}
function verify_kubectl() {
if [[ $1 != '0' ]]; then
print_error "$2"
print_error "Stopping keptn installation. Already created resources are not deleted; execute the uninstallKeptn.sh script to clean-up."
exit 1
fi
}
function verify_variable() {
if [[ -z "$1" ]]; then
print_error "$2"
print_error "Stopping keptn installation. Already created resources are not deleted; execute the uninstallKeptn.sh script to clean-up."
exit 1
fi
}
# Waits for a deployment in a given namespace to be available.
function wait_for_deployment_in_namespace() {
DEPL=$1; NAMESPACE=$2;
RETRY=0; RETRY_MAX=12;
DEPLOYMENT_LIST=$(eval "kubectl get deployments -n $NAMESPACE | awk '/$DEPL/'" | awk '{print $1}') # list of multiple deployments when starting with the same name, e.g.: event-broker, event-broker-ext
verify_variable "$DEPLOYMENT_LIST" "DEPLOYMENT_LIST could not be derived from deployments list of namespace $NAMESPACE."
array=(${DEPLOYMENT_LIST// / })
for DEPLOYMENT in "${array[@]}"
do
while [[ $RETRY -lt $RETRY_MAX ]]; do
kubectl rollout status deployment $DEPLOYMENT -n $NAMESPACE
if [[ $? == '0' ]]
then
print_debug "Deployment ${DEPLOYMENT} in ${NAMESPACE} namespace available."
break
fi
RETRY=$[$RETRY+1]
print_debug "Retry: ${RETRY}/${RETRY_MAX} - Wait 10s for deployment ${DEPLOYMENT} in namespace ${NAMESPACE} ..."
sleep 10
done
if [[ $RETRY == $RETRY_MAX ]]; then
print_error "Deployment ${DEPLOYMENT} in namespace ${NAMESPACE} is not available"
exit 1
fi
done
}