forked from kiali/kiali
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-testing-demos.sh
executable file
·206 lines (186 loc) · 6.06 KB
/
install-testing-demos.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
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
#!/bin/bash
##############################################################################
# install-testing-demos.sh
#
# Installs all the demo applications needed for cypress testing.
# Works on both openshift and non-openshift environments.
##############################################################################
set -eu
HACK_SCRIPT_DIR="$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)"
source ${HACK_SCRIPT_DIR}/functions.sh
SCRIPT_DIR="$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)"
# install the Istio release that was last downloaded (that's the -t option to ls)
ISTIO_DIR=$(ls -dt1 ${SCRIPT_DIR}/../../_output/istio-* | head -n1)
# only used when cluster is minikube
MINIKUBE_PROFILE="minikube"
: ${CLIENT_EXE:=oc}
: ${ARCH:=amd64}
: ${DELETE_DEMOS:=false}
: ${ENABLE_INJECTION:=true}
: ${GATEWAY_HOST:="")}
ISTIO_NAMESPACE="istio-system"
while [ $# -gt 0 ]; do
key="$1"
case $key in
-a|--arch)
ARCH="$2"
shift;shift
;;
-c|--client)
CLIENT_EXE="$2"
shift;shift
;;
-d|--delete)
DELETE_DEMOS="$2"
shift;shift
;;
-g|--gateway-host)
GATEWAY_HOST="$2"
shift;shift
;;
-mp|--minikube-profile)
MINIKUBE_PROFILE="$2"
shift;shift
;;
-in|--istio-namespace)
ISTIO_NAMESPACE="$2"
shift;shift
;;
-h|--help)
cat <<HELPMSG
Valid command line arguments:
-a|--arch <amd64|ppc64le|s390x>: Images for given arch will be used (default: amd64).
-c|--client: either 'oc' or 'kubectl'
-d|--delete: if 'true' demos will be deleted; otherwise, they will be installed
-g|--gateway-host: host to use for the ingress gateway
-mp|--minikube-profile <name>: If using minikube, this is the minikube profile name (default: minikube).
-in|--istio-namespace <name>: Where the Istio control plane is installed (default: istio-system).
-h|--help: this text
HELPMSG
exit 1
;;
*)
echo "Unknown argument [$key]. Aborting."
exit 1
;;
esac
done
# check arch values
if [ "${ARCH}" != "ppc64le" ] && [ "${ARCH}" != "s390x" ] && [ "${ARCH}" != "amd64" ]; then
echo "${ARCH} is not supported. Exiting."
exit 1
fi
IS_OPENSHIFT="false"
IS_MAISTRA="false"
if [[ "${CLIENT_EXE}" = *"oc" ]]; then
IS_OPENSHIFT="true"
IS_MAISTRA=$([ "$(${CLIENT_EXE} get crd | grep servicemesh | wc -l)" -gt "0" ] && echo "true" || echo "false")
fi
echo "CLIENT_EXE=${CLIENT_EXE}"
echo "ARCH=${ARCH}"
echo "IS_OPENSHIFT=${IS_OPENSHIFT}"
echo "IS_MAISTRA=${IS_MAISTRA}"
# Waits for workloads in the specified namespace to be ready
wait_for_workloads () {
local namespace=$1
local workloads=$(${CLIENT_EXE} get deployments -n $namespace -o jsonpath='{.items[*].metadata.name}')
for workload in ${workloads}
do
echo "Waiting for workload: '${workload}' to be ready"
${CLIENT_EXE} rollout status deployment "${workload}" -n "${namespace}"
done
}
if [ "${DELETE_DEMOS}" != "true" ]; then
# Installed demos should be the exact same for both environments.
# Only the args passed to the scripts differ from each other.
if [ "${IS_OPENSHIFT}" == "true" ]; then
echo "Deploying bookinfo demo ..."
"${SCRIPT_DIR}/install-bookinfo-demo.sh" -tg -in ${ISTIO_NAMESPACE} -a ${ARCH}
echo "Deploying error rates demo ..."
"${SCRIPT_DIR}/install-error-rates-demo.sh" -in ${ISTIO_NAMESPACE} -a ${ARCH}
echo "Deploying sleep demo ..."
"${SCRIPT_DIR}/install-sleep-demo.sh"
else
gateway_yaml=""
if [ -v GATEWAY_HOST ]; then
gateway_yaml=$(mktemp)
cat << EOF > "${gateway_yaml}"
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 8080
name: http
protocol: HTTP
hosts:
- "${GATEWAY_HOST}"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo
spec:
hosts:
- "${GATEWAY_HOST}"
gateways:
- bookinfo-gateway
http:
- match:
- uri:
exact: /productpage
- uri:
prefix: /static
- uri:
exact: /login
- uri:
exact: /logout
- uri:
prefix: /api/v1/products
route:
- destination:
host: productpage
port:
number: 9080
EOF
fi
echo "Deploying bookinfo demo..."
"${SCRIPT_DIR}/install-bookinfo-demo.sh" -c kubectl -mp ${MINIKUBE_PROFILE} -tg -in ${ISTIO_NAMESPACE} -a ${ARCH} ${gateway_yaml:+-g ${gateway_yaml}}
echo "Deploying error rates demo..."
"${SCRIPT_DIR}/install-error-rates-demo.sh" -c kubectl -in ${ISTIO_NAMESPACE} -a ${ARCH}
echo "Deploying sleep demo ..."
"${SCRIPT_DIR}/install-sleep-demo.sh" -c kubectl
fi
if [ -v "${GATEWAY_HOST}" ]; then
# Assume that the '*' is used for hosts if the gateway host is not specified.
# Some front-end tests have conflicts with the wildcard host in the bookinfo-gateway. Patch it with the host resolved for the traffic generator.
ISTIO_INGRESS_HOST=$(${CLIENT_EXE} get cm -n bookinfo traffic-generator-config -o jsonpath='{.data.route}' | sed 's|.*//\([^\:]*\).*/.*|\1|')
${CLIENT_EXE} patch VirtualService bookinfo -n bookinfo --type json -p "[{\"op\": \"replace\", \"path\": \"/spec/hosts/0\", \"value\": \"${ISTIO_INGRESS_HOST}\"}]"
fi
for namespace in bookinfo alpha beta
do
wait_for_workloads "${namespace}"
done
else
# Delete everything - don't abort on error, just keep going and try to delete everything
set +e
if [ "${IS_OPENSHIFT}" == "true" ]; then
echo "Deleting sleep demo ..."
"${SCRIPT_DIR}/install-sleep-demo.sh" --delete-sleep true
echo "Deleting bookinfo demo ..."
"${SCRIPT_DIR}/install-bookinfo-demo.sh" --delete-bookinfo true
echo "Deleting error rates demo ..."
"${SCRIPT_DIR}/install-error-rates-demo.sh" --delete true
else
echo "Deleting sleep demo ..."
"${SCRIPT_DIR}/install-sleep-demo.sh" --delete-sleep true -c kubectl
echo "Deleting bookinfo demo..."
"${SCRIPT_DIR}/install-bookinfo-demo.sh" --delete-bookinfo true -c kubectl
echo "Deleting error rates demo..."
"${SCRIPT_DIR}/install-error-rates-demo.sh" --delete true -c kubectl
fi
fi