Update vCPE doc in regard of customer service
[integration.git] / deployment / aks / post-install / 000_bootstrap_onap.sh
1 #!/bin/bash
2 # Copyright 2019 AT&T Intellectual Property. All rights reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
17
18 CONF=$1
19
20 if [ -z "$CONF" ]; then
21   echo "Configuration file required, exiting..."
22   exit 1
23 fi
24
25 . $CONF
26
27 kubectl create configmap onap-bootstrap --from-file=$DIR/bootstrap/ --from-file=kubeconfig=$KUBECONFIG --from-file=onap.conf=$CONF
28
29 cat  <<EOF | kubectl apply -f -
30 apiVersion: v1
31 kind: Pod
32 metadata:
33   name: onap-bootstrap
34 spec:
35   containers:
36   - name: onap-bootstrap
37     image: alpine
38     env:
39     - name: BUILD_DIR
40       value: "/tmp/onap-bootstrap-files"
41     volumeMounts:
42     - name: onap-bootstrap
43       mountPath: /onap-bootstrap
44     command: ["/bin/sh"]
45     args:
46       - -c
47       - apk update && \
48         apk add bash && \
49         apk add git && \
50         apk add jq && \
51         apk add curl && \
52         apk add openjdk8 && \
53         apk add openjdk8-jre && \
54         export PATH=$PATH:/usr/lib/jvm/java-1.8-openjdk/bin && \
55         curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl && \
56         chmod +x ./kubectl && \
57         mv ./kubectl /usr/local/bin/kubectl && \
58         cd /onap-bootstrap && \
59         . onap.conf && \
60         export KUBECONFIG=kubeconfig && \
61         sh -c "/onap-bootstrap/bootstrap.sh"
62   restartPolicy: Never
63   volumes:
64     - name: onap-bootstrap
65       configMap:
66         name: onap-bootstrap
67         defaultMode: 0777
68 EOF
69
70 echo "Creating pod to Bootstrap ONAP with OpenStack details."
71 echo "This might take a while if OpenStack is still launching..."
72
73 podstatus=""
74 COUNTER=0
75
76 while [ "$podstatus" != "Error" ] && [ "$podstatus" != "Completed" ] && [ $COUNTER -lt 60 ]; do
77   podstatus=`kubectl get pods | grep onap-bootstrap | head -1 | awk '{print $3}'`
78   echo "onap-bootstrap is $podstatus"
79   COUNTER=$((COUNTER +1))
80   sleep 30
81 done
82
83 echo "onap-bootstrap pod logs available at /tmp/onap-bootstrap-log"
84 kubectl logs onap-bootstrap > /tmp/onap-bootstrap-log
85
86 kubectl delete pod onap-bootstrap
87 kubectl delete configmap onap-bootstrap
88
89 if [ "$podstatus" = "Error" ]; then
90   echo "ONAP bootstrap failed!"
91 fi