aboutsummaryrefslogtreecommitdiffstats
path: root/bootstrap/vagrant-onap/lib/oom
blob: d52c029e407a8f9c7d05f5efaf62398bdaa07c42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash

source /var/onap/functions

RANCHER_PORT=8880
oom_delay=30
export RANCHER_URL=http://localhost:$RANCHER_PORT
export RANCHER_ACCESS_KEY='access_key'
export RANCHER_SECRET_KEY='secret_key'

# _install_docker() - Function that installs Docker version for Rancher
function _install_docker {
    if ! $(docker version &>/dev/null); then
        curl https://releases.rancher.com/install-docker/1.12.sh | sh
        _configure_docker_settings 15
    fi
}

# _pull_rancher_images() - Function that retrieves Rancher images required for k8s
function _pull_rancher_images {
    for image in "net:v0.13.5" "k8s:v1.8.5-rancher3" \
"lb-service-rancher:v0.7.17" "network-manager:v0.7.18" "metadata:v0.9.5" \
"kubectld:v0.8.5" "kubernetes-agent:v0.6.6" "dns:v0.15.3" \
"kubernetes-auth:v0.0.8" "healthcheck:v0.3.3" "etcd:v2.3.7-13" \
"etc-host-updater:v0.0.3" "net:holder"; do
        pull_docker_image rancher/$image &
    done
}

# _pull_k8s_images() - Function that retrieves Google k8s images
function _pull_k8s_images {
    for image in "kubernetes-dashboard-amd64:v1.7.1" \
"k8s-dns-sidecar-amd64:1.14.5" "k8s-dns-kube-dns-amd64:1.14.5" \
"k8s-dns-dnsmasq-nanny-amd64:1.14.5" "heapster-influxdb-amd64:v1.3.3" \
"heapster-grafana-amd64:v4.4.3" "heapster-amd64:v1.4.0" "pause-amd64:3.0"; do
        pull_docker_image gcr.io/google_containers/$image &
    done
}

# _install_rancher() - Function that installs Rancher CLI and container
function _install_rancher {
    local rancher_version=v0.6.5
    local rancher_server_version=v1.6.10
    local rancher_server=rancher/server:$rancher_server_version

    if [ ! -d /opt/rancher/current ]; then
        mkdir -p /opt/rancher/current
        wget https://github.com/rancher/cli/releases/download/$rancher_version/rancher-linux-amd64-$rancher_version.tar.gz
        tar -xzf rancher-linux-amd64-$rancher_version.tar.gz -C /tmp
        mv /tmp/rancher-$rancher_version/rancher /opt/rancher/current/
    fi

    _install_docker
    pull_docker_image $rancher_server
    run_docker_image -d --restart=unless-stopped -p $RANCHER_PORT:8080 $rancher_server
    while true; do
        if curl --fail -X GET $RANCHER_URL; then
            break
        fi
        echo "waiting for racher"
        sleep $oom_delay
    done
}

# _install_kubernetes() - Function that deploys kubernetes via RancherOS host registration
function _install_kubernetes {
    local rancher_agent_version=v1.2.7
    local rancher_agent=rancher/agent:$rancher_agent_version

    _install_rancher

    _pull_rancher_images
    _pull_k8s_images
    pull_docker_image $rancher_agent
    wait_docker_pull

    pushd /opt/rancher/current/
    export RANCHER_ENVIRONMENT=`./rancher env create -t kubernetes onap_on_kubernetes`
    popd

    install_python_package rancher-agent-registration
    export no_proxy=$no_proxy,$IP_ADDRESS
    rancher-agent-registration --host-ip $IP_ADDRESS --url http://$IP_ADDRESS:$RANCHER_PORT --environment $RANCHER_ENVIRONMENT --key $RANCHER_ACCESS_KEY --secret $RANCHER_SECRET_KEY
}

# _install_kubectl() - Function that installs kubectl as client for kubernetes
function _install_kubectl {
    if ! $(kubectl version &>/dev/null); then
        rm -rf ~/.kube
        curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
        chmod +x ./kubectl
        mv ./kubectl /usr/local/bin/kubectl
        mkdir ~/.kube
        pushd ~/.kube
        python /var/onap/files/kubectl_config_generator.py
        popd
    fi
}

# _install_helm() - Function that install Kubernetes Package Manager
function _install_helm {
    local helm_version=v2.3.0

    if ! $(helm version &>/dev/null); then
        wget http://storage.googleapis.com/kubernetes-helm/helm-${helm_version}-linux-amd64.tar.gz
        tar -zxvf helm-${helm_version}-linux-amd64.tar.gz -C /tmp
        mv /tmp/linux-amd64/helm /usr/local/bin/helm
        helm init
    fi
}

# _pull_images_from_yaml() - Function that parses a yaml file and pull their images
function _pull_images_from_yaml_file {
    local values_file=$1
    local prefix=$2
    local s='[[:space:]]*'
    local w='[a-zA-Z0-9_]*'
    fs=`echo @|tr @ '\034'`

    for line in $(sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p"  $values_file |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {
    if (i > indent) {
        delete vname[i]}
    }
    if (length($3) > 0) {
        vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])(".")}
        printf("%s%s%s=%s\n", "'$prefix'",vn, $2, $3);
    }
}' | grep image); do
        echo $line
        if echo $line | grep -q Version ; then
            pull_docker_image "$image_name:$(echo $line | awk -F "=" '{print $2}')" &
        else
            image_name=`echo ${line#*=}`
            if [[ ${image_name#*${nexus_docker_repo:-nexus3.onap.org:10001}} == *:* ]]; then
                pull_docker_image $image_name &
            else
                pull_docker_image $image_name:latest
            fi
        fi
    done
}

# get_oom_images() - Function that retrieves ONAP images from official hub
function get_oom_images {
    if [[ "$build_image" == "True" ]]; then
        # TODO(electrocucaracha): Create a function for calling the build docker function of every ONAP project
        echo "Not Implemented"
    else
        if [[ "$clone_repo" != "True" ]]; then
            clone_repos "oom"
        fi

        docker_openecomp_login
        for values_file in `find ${src_folders[oom]}/kubernetes -name values.yaml -type f`; do
            _pull_images_from_yaml_file $values_file
        done
        docker logout
        wait_docker_pull
    fi
}

# _install_oom() - Function that clones OOM and deploys ONAP
function install_oom {
    if [[ "$clone_repo" != "True" ]]; then
        clone_repos "oom"
    fi
    pushd ${src_folders[oom]}/kubernetes/oneclick
    source setenv.bash

    pushd ${src_folders[oom]}/kubernetes/config
    cp onap-parameters-sample.yaml onap-parameters.yaml
    ./createConfig.sh -n onap
    popd

    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
        ./createAll.bash -n onap -a $app
    done
    popd
}

# init_oom() - Function that deploys ONAP using OOM
function init_oom {
    mount_external_partition sda /var/lib/docker/
    _install_kubernetes
    _install_kubectl
    _install_helm
    if [[ "$clone_repo" == "True" ]]; then
        clone_repos "oom"
    fi

    if [[ "$skip_get_images" == "False" ]]; then
        get_oom_images
        if [[ "$skip_install" == "False" ]]; then
            until kubectl cluster-info; do
                echo "waiting for kubernetes host"
                sleep $oom_delay
            done
            install_oom
        fi
    fi
}