Victor Morales | fa9eb9c | 2017-12-18 09:56:13 -0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | source /var/onap/functions |
| 4 | |
| 5 | RANCHER_PORT=8880 |
| 6 | oom_delay=30 |
| 7 | export RANCHER_URL=http://localhost:$RANCHER_PORT |
| 8 | export RANCHER_ACCESS_KEY='access_key' |
| 9 | export RANCHER_SECRET_KEY='secret_key' |
| 10 | |
| 11 | # _install_docker() - Function that installs Docker version for Rancher |
| 12 | function _install_docker { |
| 13 | if ! $(docker version &>/dev/null); then |
| 14 | curl https://releases.rancher.com/install-docker/1.12.sh | sh |
| 15 | _configure_docker_settings 15 |
| 16 | fi |
| 17 | } |
| 18 | |
| 19 | # _pull_rancher_images() - Function that retrieves Rancher images required for k8s |
| 20 | function _pull_rancher_images { |
| 21 | for image in "net:v0.13.5" "k8s:v1.8.5-rancher3" \ |
| 22 | "lb-service-rancher:v0.7.17" "network-manager:v0.7.18" "metadata:v0.9.5" \ |
| 23 | "kubectld:v0.8.5" "kubernetes-agent:v0.6.6" "dns:v0.15.3" \ |
| 24 | "kubernetes-auth:v0.0.8" "healthcheck:v0.3.3" "etcd:v2.3.7-13" \ |
| 25 | "etc-host-updater:v0.0.3" "net:holder"; do |
| 26 | pull_docker_image rancher/$image & |
| 27 | done |
| 28 | } |
| 29 | |
| 30 | # _pull_k8s_images() - Function that retrieves Google k8s images |
| 31 | function _pull_k8s_images { |
| 32 | for image in "kubernetes-dashboard-amd64:v1.7.1" \ |
| 33 | "k8s-dns-sidecar-amd64:1.14.5" "k8s-dns-kube-dns-amd64:1.14.5" \ |
| 34 | "k8s-dns-dnsmasq-nanny-amd64:1.14.5" "heapster-influxdb-amd64:v1.3.3" \ |
| 35 | "heapster-grafana-amd64:v4.4.3" "heapster-amd64:v1.4.0" "pause-amd64:3.0"; do |
| 36 | pull_docker_image gcr.io/google_containers/$image & |
| 37 | done |
| 38 | } |
| 39 | |
| 40 | # _install_rancher() - Function that installs Rancher CLI and container |
| 41 | function _install_rancher { |
| 42 | local rancher_version=v0.6.5 |
| 43 | local rancher_server_version=v1.6.10 |
| 44 | local rancher_server=rancher/server:$rancher_server_version |
| 45 | |
| 46 | if [ ! -d /opt/rancher/current ]; then |
| 47 | mkdir -p /opt/rancher/current |
| 48 | wget https://github.com/rancher/cli/releases/download/$rancher_version/rancher-linux-amd64-$rancher_version.tar.gz |
| 49 | tar -xzf rancher-linux-amd64-$rancher_version.tar.gz -C /tmp |
| 50 | mv /tmp/rancher-$rancher_version/rancher /opt/rancher/current/ |
| 51 | fi |
| 52 | |
| 53 | _install_docker |
| 54 | pull_docker_image $rancher_server |
| 55 | run_docker_image -d --restart=unless-stopped -p $RANCHER_PORT:8080 $rancher_server |
| 56 | while true; do |
| 57 | if curl --fail -X GET $RANCHER_URL; then |
| 58 | break |
| 59 | fi |
| 60 | echo "waiting for racher" |
| 61 | sleep $oom_delay |
| 62 | done |
| 63 | } |
| 64 | |
| 65 | # _install_kubernetes() - Function that deploys kubernetes via RancherOS host registration |
| 66 | function _install_kubernetes { |
| 67 | local rancher_agent_version=v1.2.7 |
| 68 | local rancher_agent=rancher/agent:$rancher_agent_version |
| 69 | |
| 70 | _install_rancher |
| 71 | |
| 72 | _pull_rancher_images |
| 73 | _pull_k8s_images |
| 74 | pull_docker_image $rancher_agent |
| 75 | _wait_docker_pull |
| 76 | |
| 77 | pushd /opt/rancher/current/ |
| 78 | export RANCHER_ENVIRONMENT=`./rancher env create -t kubernetes onap_on_kubernetes` |
| 79 | popd |
| 80 | |
| 81 | install_python_package rancher-agent-registration |
| 82 | export no_proxy=$no_proxy,$IP_ADDRESS |
| 83 | rancher-agent-registration --host-ip $IP_ADDRESS --url http://$IP_ADDRESS:$RANCHER_PORT --environment $RANCHER_ENVIRONMENT --key $RANCHER_ACCESS_KEY --secret $RANCHER_SECRET_KEY |
| 84 | } |
| 85 | |
| 86 | # _install_kubectl() - Function that installs kubectl as client for kubernetes |
| 87 | function _install_kubectl { |
| 88 | if ! $(kubectl version &>/dev/null); then |
| 89 | rm -rf ~/.kube |
| 90 | curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl |
| 91 | chmod +x ./kubectl |
| 92 | mv ./kubectl /usr/local/bin/kubectl |
| 93 | mkdir ~/.kube |
| 94 | pushd ~/.kube |
| 95 | python /var/onap/files/kubectl_config_generator.py |
| 96 | popd |
| 97 | fi |
| 98 | } |
| 99 | |
| 100 | # _install_helm() - Function that install Kubernetes Package Manager |
| 101 | function _install_helm { |
| 102 | local helm_version=v2.3.0 |
| 103 | |
| 104 | if ! $(helm version &>/dev/null); then |
| 105 | wget http://storage.googleapis.com/kubernetes-helm/helm-${helm_version}-linux-amd64.tar.gz |
| 106 | tar -zxvf helm-${helm_version}-linux-amd64.tar.gz -C /tmp |
| 107 | mv /tmp/linux-amd64/helm /usr/local/bin/helm |
| 108 | helm init |
| 109 | fi |
| 110 | } |
| 111 | |
| 112 | # _pull_images_from_yaml() - Function that parses a yaml file and pull their images |
| 113 | function _pull_images_from_yaml_file { |
| 114 | local values_file=$1 |
| 115 | local prefix=$2 |
| 116 | local s='[[:space:]]*' |
| 117 | local w='[a-zA-Z0-9_]*' |
| 118 | fs=`echo @|tr @ '\034'` |
| 119 | |
| 120 | for line in $(sed -ne "s|^\($s\):|\1|" \ |
| 121 | -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ |
| 122 | -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $values_file | |
| 123 | awk -F$fs '{ |
| 124 | indent = length($1)/2; |
| 125 | vname[indent] = $2; |
| 126 | for (i in vname) { |
| 127 | if (i > indent) { |
| 128 | delete vname[i]} |
| 129 | } |
| 130 | if (length($3) > 0) { |
| 131 | vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])(".")} |
| 132 | printf("%s%s%s=%s\n", "'$prefix'",vn, $2, $3); |
| 133 | } |
| 134 | }' | grep image); do |
| 135 | echo $line |
| 136 | if echo $line | grep -q Version ; then |
| 137 | pull_docker_image "$image_name:$(echo $line | awk -F "=" '{print $2}')" & |
| 138 | else |
| 139 | image_name=`echo ${line#*=}` |
| 140 | if [[ ${image_name#*${nexus_docker_repo:-nexus3.onap.org:10001}} == *:* ]]; then |
| 141 | pull_docker_image $image_name & |
| 142 | else |
| 143 | pull_docker_image $image_name:latest |
| 144 | fi |
| 145 | fi |
| 146 | done |
| 147 | } |
| 148 | |
| 149 | # _wait_docker_pull() - Function that waits for all docker pull processes |
| 150 | function _wait_docker_pull { |
| 151 | local counter=150 |
| 152 | |
| 153 | while [ $(ps -ef | grep "docker pull" | wc -l) -gt 1 ]; do |
| 154 | sleep $oom_delay |
| 155 | counter=$((counter - 1)) |
| 156 | if [ "$counter" -eq 0 ]; then |
| 157 | break |
| 158 | fi |
| 159 | done |
| 160 | } |
| 161 | |
| 162 | # get_oom_images() - Function that retrieves ONAP images from official hub |
| 163 | function get_oom_images { |
| 164 | if [[ "$build_image" == "True" ]]; then |
| 165 | # TODO(electrocucaracha): Create a function for calling the build docker function of every ONAP project |
| 166 | echo "Not Implemented" |
| 167 | else |
| 168 | if [[ "$clone_repo" != "True" ]]; then |
| 169 | clone_repos "oom" |
| 170 | fi |
| 171 | |
| 172 | docker_openecomp_login |
| 173 | for values_file in `find ${src_folders[oom]}/kubernetes -name values.yaml -type f`; do |
| 174 | _pull_images_from_yaml_file $values_file |
| 175 | done |
| 176 | docker logout |
| 177 | _wait_docker_pull |
| 178 | fi |
| 179 | } |
| 180 | |
| 181 | # _install_oom() - Function that clones OOM and deploys ONAP |
| 182 | function install_oom { |
| 183 | if [[ "$clone_repo" != "True" ]]; then |
| 184 | clone_repos "oom" |
| 185 | fi |
| 186 | pushd ${src_folders[oom]}/kubernetes/oneclick |
| 187 | source setenv.bash |
| 188 | |
| 189 | pushd ${src_folders[oom]}/kubernetes/config |
| 190 | cp onap-parameters-sample.yaml onap-parameters.yaml |
| 191 | ./createConfig.sh -n onap |
| 192 | popd |
| 193 | |
| 194 | for app in consul msb mso message-router sdnc vid robot portal policy appc aai sdc dcaegen2 log cli multicloud clamp vnfsdk uui aaf vfc kube2msb; do |
| 195 | ./createAll.bash -n onap -a $app |
| 196 | done |
| 197 | popd |
| 198 | } |
| 199 | |
| 200 | # init_oom() - Function that deploys ONAP using OOM |
| 201 | function init_oom { |
| 202 | mount_external_partition sda /var/lib/docker/ |
| 203 | _install_kubernetes |
| 204 | _install_kubectl |
| 205 | _install_helm |
| 206 | if [[ "$clone_repo" == "True" ]]; then |
| 207 | clone_repos "oom" |
| 208 | fi |
| 209 | |
| 210 | if [[ "$skip_get_images" == "False" ]]; then |
| 211 | get_oom_images |
| 212 | if [[ "$skip_install" == "False" ]]; then |
| 213 | until kubectl cluster-info; do |
| 214 | echo "waiting for kubernetes host" |
| 215 | sleep $oom_delay |
| 216 | done |
| 217 | install_oom |
| 218 | fi |
| 219 | fi |
| 220 | } |