3 # Copyright 2018 Huawei Technologies Co., Ltd.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
12 export DEBIAN_FRONTEND=noninteractive
13 HOST_IP=$(hostname -I)
14 echo $HOST_IP `hostname` >> /etc/hosts
18 echo "__rancher_ip_addr__" > /opt/config/rancher_ip_addr.txt
19 echo "__k8s_vm_ips__" > /opt/config/k8s_vm_ips.txt
20 echo "__k8s_private_ips__" > /opt/config/k8s_private_ips.txt
21 echo "__public_net_id__" > /opt/config/public_net_id.txt
22 echo "__oam_network_cidr__" > /opt/config/oam_network_cidr.txt
23 echo "__oam_network_id__" > /opt/config/oam_network_id.txt
24 echo "__oam_subnet_id__" > /opt/config/oam_subnet_id.txt
25 echo "__sec_group__" > /opt/config/sec_group.txt
26 echo "__integration_gerrit_branch__" > /opt/config/integration_gerrit_branch.txt
27 echo "__integration_gerrit_refspec__" > /opt/config/integration_gerrit_refspec.txt
28 echo "__oom_gerrit_branch__" > /opt/config/oom_gerrit_branch.txt
29 echo "__oom_gerrit_refspec__" > /opt/config/oom_gerrit_refspec.txt
30 echo "__docker_manifest__" > /opt/config/docker_manifest.txt
31 echo "__docker_proxy__" > /opt/config/docker_proxy.txt
32 echo "__docker_version__" > /opt/config/docker_version.txt
33 echo "__rancher_version__" > /opt/config/rancher_version.txt
34 echo "__rancher_agent_version__" > /opt/config/rancher_agent_version.txt
35 echo "__kubectl_version__" > /opt/config/kubectl_version.txt
36 echo "__helm_version__" > /opt/config/helm_version.txt
37 echo "__helm_deploy_delay__" > /opt/config/helm_deploy_delay.txt
39 cat <<EOF > /opt/config/integration-override.yaml
40 __integration_override_yaml__
42 sed -i 's/\_\_public_net_id__/__public_net_id__/g' /opt/config/integration-override.yaml
43 sed -i 's|\_\_oam_network_cidr__|__oam_network_cidr__|g' /opt/config/integration-override.yaml
44 sed -i 's/\_\_oam_network_id__/__oam_network_id__/g' /opt/config/integration-override.yaml
45 sed -i 's/\_\_oam_subnet_id__/__oam_subnet_id__/g' /opt/config/integration-override.yaml
46 sed -i 's/\_\_sec_group__/__sec_group__/g' /opt/config/integration-override.yaml
47 sed -i 's/\_\_rancher_ip_addr__/__rancher_ip_addr__/g' /opt/config/integration-override.yaml
48 sed -i 's/\_\_k8s_01_vm_ip__/__k8s_01_vm_ip__/g' /opt/config/integration-override.yaml
49 sed -i 's/\_\_docker_proxy__/__docker_proxy__/g' /opt/config/integration-override.yaml
50 cp /opt/config/integration-override.yaml /root
51 cat /root/integration-override.yaml
53 echo `hostname -I` `hostname` >> /etc/hosts
55 if [ ! -z "__docker_proxy__" ]; then
56 cat > /etc/docker/daemon.json <<EOF
58 "insecure-registries" : ["__docker_proxy__"]
62 if [ ! -z "__apt_proxy__" ]; then
63 cat > /etc/apt/apt.conf.d/30proxy<<EOF
64 Acquire::http { Proxy "http://__apt_proxy__"; };
65 Acquire::https::Proxy "DIRECT";
69 # workaround for OpenStack intermittent failure to change default apt mirrors
70 sed -i 's|http://archive.ubuntu.com|http://nova.clouds.archive.ubuntu.com|g' /etc/apt/sources.list
72 while ! hash jq &> /dev/null; do
74 apt-get -y install linux-image-extra-$(uname -r) apt-transport-https ca-certificates curl software-properties-common jq make nfs-kernel-server moreutils
78 mkdir -p /dockerdata-nfs
80 # use RAM disk for /dockerdata-nfs for testing
81 if [ "__use_ramdisk__" = "true" ]; then
82 echo "tmpfs /dockerdata-nfs tmpfs noatime,size=75% 1 2" >> /etc/fstab
85 # version control the persistence volume to see what's happening
86 chmod 777 /dockerdata-nfs/
87 chown nobody:nogroup /dockerdata-nfs/
90 git config user.email "root@onap"
91 git config user.name "root"
93 git commit -m "initial commit"
96 echo "/dockerdata-nfs *(rw,fsid=1,async,no_root_squash,no_subtree_check)" | tee /etc/exports
100 systemctl restart nfs-kernel-server
104 # install docker __docker_version__
105 while ! hash docker &> /dev/null; do
106 curl -s https://releases.rancher.com/install-docker/__docker_version__.sh | sh
107 usermod -aG docker ubuntu
110 apt-mark hold docker-ce
112 # install rancher __rancher_version__
113 docker run --name rancher-server --restart unless-stopped -d -p 8080:8080 -e CATTLE_BOOTSTRAP_REQUIRED_IMAGE=__docker_proxy__/rancher/agent:v__rancher_agent_version__ __docker_proxy__/rancher/server:v__rancher_version__
115 # install kubectl __kubectl_version__
116 curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v__kubectl_version__/bin/linux/amd64/kubectl
118 sudo mv ./kubectl /usr/local/bin/kubectl
121 # install helm __helm_version__
124 wget -q http://storage.googleapis.com/kubernetes-helm/helm-v__helm_version__-linux-amd64.tar.gz
125 tar -zxvf helm-v__helm_version__-linux-amd64.tar.gz
126 sudo cp linux-amd64/helm /usr/local/bin/helm
131 echo export RANCHER_IP=__rancher_private_ip_addr__ > api-keys-rc
134 until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
137 OLD_PID=$(jq -r '.data[0].id' projects.json)
139 curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json
140 echo export CATTLE_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
141 echo export CATTLE_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
145 curl -u "${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}" -X PUT -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"id":"registry.default","type":"activeSetting","baseType":"setting","name":"registry.default","activeValue":"__docker_proxy__","inDb":true,"source":"Database","value":"__docker_proxy__"}' http://$RANCHER_IP:8080/v2-beta/settings/registry.default
147 curl -s -u "${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
149 until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
151 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json
152 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
156 curl -s -u "${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}" \
158 -H 'Accept: application/json' \
159 -H 'Content-Type: application/json' \
160 -d '{"stacks":[{"type":"catalogTemplate", "answers":{"CONSTRAINT_TYPE":"required"}, "name":"kubernetes", "templateVersionId":"library:infra*k8s:52"}, {"type":"catalogTemplate", "name":"network-services", "templateId":"library:infra*network-services"}, {"type":"catalogTemplate", "name":"ipsec", "templateId":"library:infra*ipsec"}, {"type":"catalogTemplate", "name":"healthcheck", "templateId":"library:infra*healthcheck"}]}' \
161 "http://$RANCHER_IP:8080/v2-beta/projecttemplates/$TEMPLATE_ID"
163 curl -s -u "${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}" -X POST -H 'Content-Type: application/json' -d '{ "name":"oom", "projectTemplateId":"'$TEMPLATE_ID'" }' "http://$RANCHER_IP:8080/v2-beta/projects" > project.json
164 PID=`jq -r '.id' project.json`
165 echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
168 until [ $(jq -r '.state' project.json) == "active" ]; do
170 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json
174 curl -s -u $CATTLE_ACCESS_KEY:$CATTLE_SECRET_KEY -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"name":"docker-proxy", "serverAddress":"__docker_proxy__"}' $RANCHER_URL/registries > registry.json
175 RID=$(jq -r '.id' registry.json)
178 curl -u "${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}" -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"publicValue":"docker", "registryId":"'$RID'", "secretValue":"docker", "type":"registryCredential"}' "http://$RANCHER_IP:8080/v2-beta/projects/$PID/registrycredential"
182 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')
184 while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
186 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json
188 jq -r .command token.json > rancher_agent_cmd.sh
189 chmod +x rancher_agent_cmd.sh
190 cp rancher_agent_cmd.sh /dockerdata-nfs
195 git commit -a -m "Add rancher agent command file"
199 # Uncomment this section to run orchestration plane on the Rancher VM
201 # cp /dockerdata-nfs/rancher_agent_cmd.sh .
202 # sed -i "s/docker run/docker run -e CATTLE_HOST_LABELS='orchestration=true' -e CATTLE_AGENT_IP=${HOST_IP}/g" rancher_agent_cmd.sh
203 # source rancher_agent_cmd.sh
207 KUBETOKEN=$(echo -n 'Basic '$(echo -n "$CATTLE_ACCESS_KEY:$CATTLE_SECRET_KEY" | base64 -w 0) | base64 -w 0)
211 # create .kube/config
212 cat > ~/.kube/config <<EOF
218 insecure-skip-tls-verify: true
219 server: "https://__rancher_ip_addr__:8080/r/projects/$PID/kubernetes:6443"
224 namespace: "$NAMESPACE"
227 current-context: "oom"
234 export KUBECONFIG=/root/.kube/config
239 # Enable auto-completion for kubectl
240 echo "source <(kubectl completion bash)" >> ~/.bashrc
243 # wait for kubernetes to initialze
245 until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
253 cp ~ubuntu/.ssh/authorized_keys ~/.ssh
256 # update and initialize git
257 apt-get -y install git
258 git config --global user.email root@rancher
259 git config --global user.name root@rancher
260 git config --global log.decorate auto
264 git clone -b __oom_gerrit_branch__ https://gerrit.onap.org/r/oom
266 git fetch https://gerrit.onap.org/r/oom __oom_gerrit_refspec__
267 git checkout FETCH_HEAD
268 git checkout -b workarounds
273 git clone -b __integration_gerrit_branch__ https://gerrit.onap.org/r/integration
275 git fetch https://gerrit.onap.org/r/integration __integration_gerrit_refspec__
276 git checkout FETCH_HEAD
279 if [ ! -z "__docker_manifest__" ]; then
280 cd version-manifest/src/main/scripts
281 ./update-oom-image-versions.sh ../resources/__docker_manifest__ ~/oom/
286 git commit -a -m "apply manifest versions"
287 git tag -a "deploy0" -m "initial deployment"
292 helm init --client-only
296 helm repo add local http://127.0.0.1:8879
299 helm search -l | grep local
301 # install helm deploy plugin
302 rsync -avt ~/oom/kubernetes/helm/plugins ~/.helm/
303 # temporary workaround to throttle the helm deploy to alleviate startup disk contention issues
304 if [ ! -z "__helm_deploy_delay__" ]; then
305 sed -i "/\^enabled:/a\ echo sleep __helm_deploy_delay__\n sleep __helm_deploy_delay__" ~/.helm/plugins/deploy/deploy.sh
308 helm deploy dev local/onap -f ~/oom/kubernetes/onap/resources/environments/public-cloud.yaml -f ~/integration-override.yaml --namespace $NAMESPACE --verbose
310 # re-install original helm deploy plugin
311 rsync -avt ~/oom/kubernetes/helm/plugins ~/.helm/
319 kubectl get pods --all-namespaces