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