Merge "[CONSUL] Add limits to consul chart."
[oom.git] / kubernetes / pnda / charts / dcae-pnda-bootstrap / resources / scripts / bootstrap.sh
1 #!/bin/sh
2 {{/*
3 # ================================================================================
4 # Copyright (c) 2018 Cisco Systems. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
18 */}}
19
20 # Install PNDA in Openstack with Heat templates
21 # Expects:
22 #   Input files for components to be installed in /inputs
23
24 if [ "z{{ .Values.enabled }}" != "ztrue" ]
25 then
26    echo
27    echo "PNDA bootstrap is disabled - skipping pnda-cli launch"
28    echo
29    exit 0
30 fi
31
32 set -ex
33
34 CLUSTER_PREFIX="{{ include "common.release" . }}-{{ include "common.namespace" . }}-pnda"
35 DATANODES="{{ .Values.pnda.dataNodes }}"
36 KAFKANODES="{{ .Values.pnda.kafkaNodes }}"
37 VERSION="{{ .Values.pnda.version }}"
38 KEYPAIR_NAME="{{ .Values.pnda_keypair_name }}"
39 KEYFILE="$KEYPAIR_NAME.pem"
40
41 cd /pnda-cli
42
43 cp /inputs/pnda_env.yaml .
44 cp /secrets/pnda.pem $KEYFILE
45 chmod 600 $KEYFILE
46
47 (cd tools && ./gen-certs.py)
48
49 KUBE_API="https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT_HTTPS/api/v1"
50 KUBE_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
51
52 for i in 1 2 3 4 5 6 7 8 9
53 do
54   MIRROR_IP=$(curl -s $KUBE_API/namespaces/{{ include "common.namespace" . }}/pods \
55             --header "Authorization: Bearer $KUBE_TOKEN" \
56             --insecure | jq -r '.items[].status | select(.containerStatuses != null) | select(.containerStatuses[].ready and .containerStatuses[].name=="dcae-pnda-mirror") | .hostIP')
57   MIRROR_PORT=$(curl -s $KUBE_API/namespaces/{{ include "common.namespace" . }}/services/dcae-pnda-mirror \
58               --header "Authorization: Bearer $KUBE_TOKEN" \
59               --insecure | jq -r '.spec.ports[] | select(.name=="dcae-pnda-mirror") | .nodePort')
60
61   if [ "x${MIRROR_IP}" != "xnull" -a "x${MIRROR_PORT}" != "xnull" ]; then
62     PNDA_MIRROR="http://$MIRROR_IP:$MIRROR_PORT"
63     break
64   fi
65   sleep 5
66 done
67
68 [ -z "${PNDA_MIRROR}" ] && { echo "Unable to get PNDA mirror IP:PORT"; exit 1; }
69
70 sed -i -e 's?CLIENT_IP/32?CLIENT_IP?' bootstrap-scripts/package-install.sh
71
72 ./cli/pnda-cli.py create -e $CLUSTER_PREFIX -f pico -n $DATANODES -k $KAFKANODES \
73                   -b $VERSION -s $KEYPAIR_NAME --set "mirrors.PNDA_MIRROR=$PNDA_MIRROR"