Upgrade helm server-side component
[integration.git] / deployment / heat / onap-oom / k8s_vm_entrypoint.sh
1 #!/bin/bash -x
2 printenv
3
4 mkdir -p /opt/config
5 echo "__rancher_ip_addr__" > /opt/config/rancher_ip_addr.txt
6 echo `hostname -I` `hostname` >> /etc/hosts
7 mkdir -p /etc/docker
8 if [ ! -z "__docker_proxy__" ]; then
9     cat > /etc/docker/daemon.json <<EOF
10 {
11   "insecure-registries" : ["__docker_proxy__"]
12 }
13 EOF
14 fi
15 if [ ! -z "__apt_proxy__" ]; then
16     cat > /etc/apt/apt.conf.d/30proxy<<EOF
17 Acquire::http { Proxy "http://__apt_proxy__"; };
18 Acquire::https::Proxy "DIRECT";
19 EOF
20 fi
21 apt-get -y update
22 apt-get -y install linux-image-extra-$(uname -r) jq make
23
24 cd ~
25
26 # install docker 17.03
27 curl -s https://releases.rancher.com/install-docker/17.03.sh | sh
28 usermod -aG docker ubuntu
29
30 # install kubernetes 1.8.6
31 curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.6/bin/linux/amd64/kubectl
32 chmod +x ./kubectl
33 sudo mv ./kubectl /usr/local/bin/kubectl
34 mkdir ~/.kube
35
36 # install helm
37 wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.7.2-linux-amd64.tar.gz
38 tar -zxvf helm-v2.7.2-linux-amd64.tar.gz
39 sudo mv linux-amd64/helm /usr/local/bin/helm
40
41 # Fix virtual memory allocation for onap-log:elasticsearch:
42 echo "vm.max_map_count=262144" >> /etc/sysctl.conf
43 sysctl -p
44
45 # install rancher agent
46 echo export RANCHER_IP=__rancher_ip_addr__ > api-keys-rc
47 source api-keys-rc
48
49 sleep 50
50 until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
51     sleep 10
52 done
53 OLD_PID=$(jq -r '.data[0].id' projects.json)
54
55 curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json
56 echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
57 echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
58 source api-keys-rc
59
60 curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
61
62 until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
63     sleep 5
64     curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json
65     TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
66 done
67
68 curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X POST -H 'Content-Type: application/json' -d '{ "name":"oom", "projectTemplateId":"'$TEMPLATE_ID'" }' "http://$RANCHER_IP:8080/v2-beta/projects" > project.json
69 PID=`jq -r '.id' project.json`
70 echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
71 source api-keys-rc
72
73 until [ $(jq -r '.state' project.json) == "active" ]; do
74     sleep 5
75     curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json
76 done
77
78 TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
79 touch token.json
80 while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
81     sleep 5
82     curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json
83 done
84 RANCHER_AGENT_CMD=$(jq -r .command token.json)
85 eval $RANCHER_AGENT_CMD
86
87
88 KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
89
90 # create .kube/config
91 cat > ~/.kube/config <<EOF
92 apiVersion: v1
93 kind: Config
94 clusters:
95 - cluster:
96     api-version: v1
97     insecure-skip-tls-verify: true
98     server: "https://$RANCHER_IP:8080/r/projects/$PID/kubernetes:6443"
99   name: "oom"
100 contexts:
101 - context:
102     cluster: "oom"
103     user: "oom"
104   name: "oom"
105 current-context: "oom"
106 users:
107 - name: "oom"
108   user:
109     token: "$KUBETOKEN"
110 EOF
111
112 export KUBECONFIG=/root/.kube/config
113 kubectl config view
114
115 # wait for kubernetes to initialze
116 sleep 100
117 until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
118     sleep 10
119 done
120
121
122 # Install using OOM
123 export HOME=/root
124
125 # Clone OOM:
126 cd ~
127 git clone -b master http://gerrit.onap.org/r/oom
128 git log -1
129
130 # Update values.yaml to point to docker-proxy instead of nexus3:
131 cd ~/oom/kubernetes
132 #perl -p -i -e 's/nexus3.onap.org:10001/__docker_proxy__/g' `find ./ -name values.yaml`
133 sed -i 's/nexus3.onap.org:10001/__docker_proxy__/g' onap/values.yaml
134 sed -i 's/#repository:/repository:/g' onap/values.yaml
135 sed -i 's/#repositorySecret:/repositorySecret:/g' onap/values.yaml
136 git diff
137
138
139 # version control the persistence volume to see what's happening
140 mkdir -p /dockerdata-nfs/
141 cd /dockerdata-nfs/
142 git init
143 git config user.email "root@k8s"
144 git config user.name "root"
145 git add -A
146 git commit -m "initial commit"
147
148 # Run ONAP:
149 cd ~/oom/kubernetes/
150 # verify version
151 helm version
152 helm init --client-only
153 helm init --upgrade
154 helm serve &
155 sleep 3
156 helm repo add local http://127.0.0.1:8879
157 helm repo list
158 make all
159 helm search -l | grep local
160 helm install local/onap -n dev --namespace onap
161
162 # Check ONAP status:
163 sleep 3
164 kubectl get pods --all-namespaces