Enable Istio on IEC type2
[iec.git] / src / use_cases / service_mesh / bookinfo / install / install.sh
1 #!/bin/bash -ex
2 # shellcheck disable=SC2016
3 # shellcheck source=/dev/null
4
5 NODE_IP=${1:-10.169.36.152}
6
7 function wait_for {
8   # Execute in a subshell to prevent local variable override during recursion
9   (
10     local total_attempts=$1; shift
11     local cmdstr=$*
12     local sleep_time=2
13     echo -e "\n[wait_for] Waiting for cmd to return success: ${cmdstr}"
14     # shellcheck disable=SC2034
15     for attempt in $(seq "${total_attempts}"); do
16       echo "[wait_for] Attempt ${attempt}/${total_attempts%.*} for: ${cmdstr}"
17       # shellcheck disable=SC2015
18       eval "${cmdstr}" && echo "[wait_for] OK: ${cmdstr}" && return 0 || true
19       sleep "${sleep_time}"
20     done
21     echo "[wait_for] ERROR: Failed after max attempts: ${cmdstr}"
22     return 1
23   )
24 }
25
26 # Enable default namespace as auto-inject mode
27 # kubectl label namespace default istio-injection=enabled
28
29 basepath=$(cd "$(dirname "$0")"; pwd)
30 INFO_YAML=${INFO_YAML:-${basepath}/../config}
31
32 # TODO(alav): Make each step re-entrant
33
34 # shellcheck source=/dev/null
35 # Waiting for Istio ready
36 wait_for 100 'test $(kubectl get pods -n istio-system | grep -ce "Running") -eq 12'
37
38 # Start bookinfo pods
39 kubectl apply -f $INFO_YAML/bookinfo.yaml
40
41 # Waiting for sample case ready
42 wait_for 100 'test $(kubectl get pods | grep -ce "Running") -eq 6'
43
44 # Start gateway
45 kubectl apply -f $INFO_YAML/bookinfo-gateway.yaml
46
47 # Configure gate way
48 INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
49 # SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')
50 export GATEWAY_URL=$NODE_IP:$INGRESS_PORT
51
52 # Confirm the result
53 curl -s http://${GATEWAY_URL}/productpage | grep -o "<title>.*</title>"