Piotr Perzanowski | a69b4f6 | 2018-12-18 12:12:51 +0100 | [diff] [blame] | 1 | # COPYRIGHT NOTICE STARTS HERE |
| 2 | # |
| 3 | # Copyright 2018 © Samsung Electronics Co., Ltd. |
| 4 | # |
| 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 |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | # COPYRIGHT NOTICE ENDS HERE |
| 18 | # |
| 19 | # this file contains shared variables and functions for the onap installer |
| 20 | # |
| 21 | # any script which needs this file can check this variable |
| 22 | # and it will know immediately if the functions and variables |
| 23 | # are loaded and usable |
| 24 | IS_COMMON_FUNCTIONS_SOURCED=YES |
| 25 | # setting of the path variables |
| 26 | if [ -z "$APROJECT_DIR" ] ; then |
| 27 | INCLUDE_PATH="${LOCAL_PATH}"/"${RELATIVE_PATH}" |
| 28 | APROJECT_DIR=$(readlink -f "$INCLUDE_PATH"/../..) |
| 29 | fi |
| 30 | RESOURCES_DIR="$APROJECT_DIR/resources" |
| 31 | BASH_SCRIPTS_DIR="$APROJECT_DIR/bash" |
| 32 | NEXUS_DATA="$RESOURCES_DIR/nexus_data" |
| 33 | CERTS_TARGET_PATH="$APROJECT_DIR/live/certs" |
| 34 | NGINX_LOG_DIR="$APROJECT_DIR/live/nginx_logs" |
| 35 | GEN_CFG_PATH="$APROJECT_DIR/live/cfg" |
| 36 | GIT_REPOS="$RESOURCES_DIR/git-repo" |
| 37 | NGINX_HTTP_DIR="$RESOURCES_DIR/http" |
| 38 | RHEL_REPO="$RESOURCES_DIR/pkg/rhel" |
| 39 | PATH="${PATH}:/usr/local/bin:/usr/local/sbin" |
| 40 | export PATH |
| 41 | # just self-defense against locale |
| 42 | LANG=C |
| 43 | export LANG |
| 44 | # dns handling |
| 45 | SIMUL_HOSTS="gcr.io \ |
| 46 | git.rancher.io \ |
| 47 | gerrit.onap.org \ |
| 48 | registry-1.docker.io \ |
| 49 | docker.io \ |
| 50 | registry.npmjs.org \ |
| 51 | nexus3.onap.org \ |
| 52 | nexus.onap.org \ |
| 53 | docker.elastic.co \ |
| 54 | www.getcloudify.org \ |
| 55 | www.springframework.org \ |
| 56 | registry.hub.docker.com \ |
| 57 | git.onap.org \ |
| 58 | repo1.maven.org \ |
| 59 | repo.maven.apache.org" |
| 60 | # default credentials to the repository |
| 61 | NEXUS_USERNAME=admin |
| 62 | NEXUS_PASSWORD=admin123 |
| 63 | NEXUS_EMAIL=admin@onap.org |
| 64 | # this function is intended to unify the installer output |
| 65 | message() { |
| 66 | case "$1" in |
| 67 | info) |
| 68 | echo 'INFO:' "$@" |
| 69 | ;; |
| 70 | debug) |
| 71 | echo 'DEBUG:' "$@" >&2 |
| 72 | ;; |
| 73 | warning) |
| 74 | echo 'WARNING [!]:' "$@" >&2 |
| 75 | ;; |
| 76 | error) |
| 77 | echo 'ERROR [!!]:' "$@" >&2 |
| 78 | return 1 |
| 79 | ;; |
| 80 | *) |
| 81 | echo 'UNKNOWN [?!]:' "$@" >&2 |
| 82 | return 2 |
| 83 | ;; |
| 84 | esac |
| 85 | return 0 |
| 86 | } |
| 87 | export message |
| 88 | # if the environment variable DEBUG is set to DEBUG-ONAP -> |
| 89 | # -> this function will print its arguments |
| 90 | # otherwise nothing is done |
| 91 | debug() { |
| 92 | [ "$DEBUG" = DEBUG-ONAP ] && message debug "$@" |
| 93 | } |
| 94 | export debug |
| 95 | fail() { |
| 96 | message error "$@" |
| 97 | exit 1 |
| 98 | } |
| 99 | retry() { |
| 100 | local n=1 |
| 101 | local max=5 |
| 102 | while ! "$@"; do |
| 103 | if [ $n -lt $max ]; then |
| 104 | n=$((n + 1)) |
| 105 | message warning "Command ${@} failed. Attempt: $n/$max" |
| 106 | message info "waiting 10s for another try..." |
| 107 | sleep 10s |
| 108 | else |
| 109 | fail "Command ${@} failed after $n attempts. Better to abort now." |
| 110 | fi |
| 111 | done |
| 112 | } |
| 113 | may_self_extract() { |
| 114 | # extract and untar to the current directory |
| 115 | sed '0,/^# PAYLOAD BELOW #$/d' "$0" | tar -xvpf - ; |
| 116 | } |
| 117 | update_hosts() { |
| 118 | if grep -q "^[^#]\+\s$SIMUL_HOSTS\s*\$" /etc/hosts ; then |
| 119 | message info "simulated domains already in /etc/hosts" |
| 120 | else |
| 121 | echo "$LOCAL_IP $SIMUL_HOSTS" >> /etc/hosts |
| 122 | message info "simulated domains added to /etc/hosts (please check it)" |
| 123 | fi |
| 124 | if grep -q "^[^#]\+\s$NEXUS_FQDN\s*\$" /etc/hosts ; then |
| 125 | message info "nexus FQDN already in /etc/hosts" |
| 126 | else |
| 127 | echo "$LOCAL_IP $NEXUS_FQDN" >> /etc/hosts |
| 128 | message info "Nexus FQDN added to /etc/hosts (please check it)" |
| 129 | fi |
| 130 | if grep -q "^[^#]\+\srepo.install-server\s*\$" /etc/hosts ; then |
| 131 | message info "custom repo FQDN already in /etc/hosts" |
| 132 | else |
| 133 | echo "$LOCAL_IP repo.install-server" >> /etc/hosts |
| 134 | message info "Nexus FQDN added to /etc/hosts (please check it)" |
| 135 | fi |
| 136 | } |
| 137 | get_cfg_val() { |
| 138 | name="$1" |
| 139 | shift |
| 140 | ask="$@" |
| 141 | value=$(eval "echo \$${name}") |
| 142 | if [ -z "$value" ]; then |
| 143 | while [ -z "$value" ] ; do |
| 144 | printf "${ask}" |
| 145 | read -r $name |
| 146 | value=$(eval "echo \$${name}") |
| 147 | done |
| 148 | echo "${name}='${value}'" >> ./local_repo.conf |
| 149 | fi |
| 150 | } |
| 151 | get_configuration() { |
| 152 | if [ -f ./local_repo.conf ]; then |
| 153 | . ./local_repo.conf |
| 154 | fi |
| 155 | if [ -z "${NEXUS_FQDN}" ]; then |
| 156 | NEXUS_FQDN="nexus.$HOSTNAME" |
| 157 | echo "NEXUS_FQDN='${NEXUS_FQDN}'" >> ./local_repo.conf |
| 158 | fi |
| 159 | if [ -z "${ONAP_SCALE}" ]; then |
| 160 | ONAP_SCALE=full |
| 161 | echo "ONAP_SCALE='${ONAP_SCALE}'" >> ./local_repo.conf |
| 162 | fi |
| 163 | # nexus should be configured using those default entries |
| 164 | # if it was not put the correct inputs instead |
| 165 | if [ -z "${NPM_USERNAME}" ]; then |
| 166 | NPM_USERNAME="${NEXUS_USERNAME}" |
| 167 | echo "NPM_USERNAME='${NPM_USERNAME}'" >> ./local_repo.conf |
| 168 | fi |
| 169 | if [ -z "${NPM_PASSWORD}" ]; then |
| 170 | NPM_PASSWORD="${NEXUS_PASSWORD}" |
| 171 | echo "NPM_PASSWORD='${NPM_PASSWORD}'" >> ./local_repo.conf |
| 172 | fi |
| 173 | if [ -z "${NPM_EMAIL}" ]; then |
| 174 | NPM_EMAIL="$NEXUS_EMAIL" |
| 175 | echo "NPM_EMAIL='${NPM_EMAIL}'" >> ./local_repo.conf |
| 176 | fi |
| 177 | export NEXUS_FQDN |
| 178 | export ONAP_SCALE |
| 179 | export NPM_USERNAME |
| 180 | export NPM_PASSWORD |
| 181 | export NPM_EMAIL |
| 182 | NODE_USERNAME="root" |
| 183 | if [ -z "$LOCAL_IP" ] ; then |
| 184 | echo |
| 185 | echo "======= Mandatory configuration =======" |
| 186 | echo |
| 187 | message info "fill in these mandatory configuration values" |
| 188 | get_cfg_val "LOCAL_IP" "Enter the public IPv4 used for this '$HOSTNAME' install machine," \ |
| 189 | "\nDO NOT USE LOOPBACK! (for example: 10.0.0.1): " |
| 190 | fi |
| 191 | } |
| 192 | enable_local_repo() { |
| 193 | sed -r "s%PATH%file://$APROJECT_DIR/resources/pkg/rhel%" "$APROJECT_DIR/resources/pkg/rhel/onap.repo" > /etc/yum.repos.d/onap.repo |
| 194 | } |
| 195 | install_packages() { |
| 196 | os_id="$1" |
| 197 | message info "Installing packages" |
| 198 | case "$os_id" in |
| 199 | centos) |
| 200 | yum -y install "$APROJECT_DIR/resources/pkg/centos/*.rpm" |
| 201 | ;; |
| 202 | rhel) |
| 203 | enable_local_repo |
| 204 | yum -y install docker-ce dnsmasq icewm firefox tigervnc-server |
| 205 | systemctl enable docker |
| 206 | systemctl start docker |
| 207 | ;; |
| 208 | ubuntu) |
| 209 | dpkg -i "$APROJECT_DIR/resources/pkg/ubuntu/*.deb" |
| 210 | ;; |
| 211 | *) |
| 212 | message error "OS release is not supported: $os_id" |
| 213 | message info "ABORTING INSTALLATION" |
| 214 | exit 1 |
| 215 | ;; |
| 216 | esac |
| 217 | } |
| 218 | install_files() { |
| 219 | message info "installation of external binaries" |
| 220 | for binary in kubectl helm rancher jq ; do |
| 221 | cp "$APROJECT_DIR/resources/downloads/${binary}" /usr/local/bin/ |
| 222 | chmod 755 "/usr/local/bin/${binary}" |
| 223 | done |
| 224 | mkdir ~/.kube |
| 225 | } |
| 226 | setup_vnc_server() { |
| 227 | mkdir -p ~/.vnc ~/.icewm |
| 228 | echo "onap" | vncpasswd -f > ~/.vnc/passwd |
| 229 | chmod 0600 ~/.vnc/passwd |
| 230 | cat > ~/.vnc/xstartup <<EOF |
| 231 | #!/bin/sh |
| 232 | unset SESSION_MANAGER |
| 233 | unset DBUS_SESSION_BUS_ADDRESS |
| 234 | exec icewm-session |
| 235 | EOF |
| 236 | chmod +x ~/.vnc/xstartup |
| 237 | cat > ~/.icewm/menu <<EOF |
| 238 | prog Firefox firefox firefox |
| 239 | separator |
| 240 | EOF |
| 241 | vncserver |
| 242 | } |
| 243 | update_docker_cfg() { |
| 244 | if [ -f "/etc/docker/daemon.json" ]; then |
| 245 | jq '.dns += ["172.17.0.1"]' /etc/docker/daemon.json > /tmp/daemon.json |
| 246 | mv /tmp/daemon.json /etc/docker/daemon.json |
| 247 | else |
| 248 | echo '{"dns": ["172.17.0.1"]}' > /etc/docker/daemon.json |
| 249 | fi |
| 250 | } |
| 251 | create_root_CA() { |
| 252 | echo "** Generate certificates **" |
| 253 | openssl genrsa -out $CERTS_TARGET_PATH/rootCA.key 4096 |
| 254 | echo "** Generate self signed ***" |
| 255 | openssl req -config $GEN_CFG_PATH/cacert.cnf -key $CERTS_TARGET_PATH/rootCA.key -new -x509 -days 7300 -sha256 -extensions v3_ca \ |
| 256 | -out $CERTS_TARGET_PATH/rootCAcert.pem |
| 257 | # convert to crt |
| 258 | openssl x509 -in $CERTS_TARGET_PATH/rootCAcert.pem -inform PEM -out $CERTS_TARGET_PATH/rootCAcert.crt |
| 259 | } |
| 260 | install_root_CA() { |
| 261 | os=$1 |
| 262 | echo "** Publishing root CA **" |
| 263 | if [ "$os" == "redhat" ]; then |
| 264 | # for centos |
| 265 | update-ca-trust force-enable |
| 266 | cp $CERTS_TARGET_PATH/rootCAcert.crt /etc/pki/ca-trust/source/anchors/ |
| 267 | update-ca-trust extract |
| 268 | elif [ "$os" == "ubuntu" ]; then |
| 269 | mkdir -p /usr/local/share/ca-certificates/extra |
| 270 | cp $CERTS_TARGET_PATH/rootCAcert.crt /usr/local/share/ca-certificates/extra |
| 271 | update-ca-certificates |
| 272 | else |
| 273 | echo "OS \"$os\" is not supported" |
| 274 | exit -2 |
| 275 | fi |
| 276 | echo "** Restart docker (because of reload new CA) **" |
| 277 | systemctl restart docker |
| 278 | } |
| 279 | create_cert() { |
| 280 | server_name=$1 |
| 281 | openssl genrsa -out $CERTS_TARGET_PATH/${server_name}_server.key 4096 |
| 282 | echo "** Generate sig request ***" |
| 283 | openssl req -new -config $GEN_CFG_PATH/${server_name}_cert.cnf -key $CERTS_TARGET_PATH/${server_name}_server.key -out $CERTS_TARGET_PATH/${server_name}_server.csr |
| 284 | # v3.ext must be in separate file , because of bug in openssl 1.0 |
| 285 | echo "** sign **" |
| 286 | openssl x509 -req -in $CERTS_TARGET_PATH/${server_name}_server.csr\ |
| 287 | -extfile $GEN_CFG_PATH/v3.ext\ |
| 288 | -CA $CERTS_TARGET_PATH/rootCAcert.crt\ |
| 289 | -CAkey $CERTS_TARGET_PATH/rootCA.key\ |
| 290 | -CAcreateserial -out $CERTS_TARGET_PATH/${server_name}_server.crt -days 3650 -sha256 |
| 291 | } |
| 292 | create_all_certs() { |
| 293 | create_cert "nexus" |
| 294 | } |
| 295 | update_firewall() { |
| 296 | #TODO |
| 297 | return 0 |
| 298 | } |
| 299 | distribute_root_CA() { |
| 300 | targetip=$1 |
| 301 | scp $APROJECT_DIR/install_cacert.sh $targetip:. |
| 302 | ssh $targetip ./install_cacert.sh |
| 303 | echo "** Add DNS record to remote host **" |
| 304 | ssh $targetip "echo nameserver $LOCAL_IP > /etc/resolv.conf" |
| 305 | } |
| 306 | remote_setup_nfs_server() { |
| 307 | os=$1 |
| 308 | targetip=$2 |
| 309 | shift 2 |
| 310 | scp $APROJECT_DIR/bash/tools/setup_nfs_server_${os}.sh $targetip:setup_nfs_server.sh |
| 311 | if [[ $os == "ubuntu" ]]; then |
| 312 | scp -r $APROJECT_DIR/resources/pkg/ubuntu/nfs-common-pkg/* $targetip:. |
| 313 | ssh $targetip dpkg -i *.deb |
| 314 | fi |
| 315 | ssh $targetip /bin/bash ./setup_nfs_server.sh "$@" |
| 316 | } |
| 317 | remote_setup_nfs_mount() { |
| 318 | os=$1 |
| 319 | targetip=$2 |
| 320 | nfsip=$3 |
| 321 | scp $APROJECT_DIR/bash/tools/setup_nfs_mount.sh $targetip:. |
| 322 | if [[ $os == "ubuntu" ]]; then |
| 323 | scp -r $APROJECT_DIR/resources/pkg/ubuntu/nfs-common-pkg/* $targetip:. |
| 324 | ssh $targetip dpkg -i *.deb |
| 325 | fi |
| 326 | ssh $targetip /bin/bash ./setup_nfs_mount.sh $nfsip |
| 327 | } |
| 328 | enable_remote_repo() { |
| 329 | targetip=$1 |
| 330 | sed -r "s%PATH%http://repo.install-server%" $APROJECT_DIR/resources/pkg/rhel/onap.repo | ssh $targetip 'cat > /etc/yum.repos.d/onap.repo' |
| 331 | } |
| 332 | install_remote_docker() { |
| 333 | targetip=$1 |
| 334 | os=$2 |
| 335 | if [[ $os == "ubuntu" ]]; then |
| 336 | scp -r $APROJECT_DIR/resources/pkg/ubuntu/{docker-ce_17.03.2~ce-0~ubuntu-xenial_amd64.deb,libltdl7_2.4.6-0.1_amd64.deb} $targetip:. |
| 337 | ssh $targetip dpkg -i *.deb |
| 338 | elif [[ $os == "rhel" ]]; then |
| 339 | ssh $targetip yum -y install docker-ce |
| 340 | fi |
| 341 | ssh $targetip "mkdir -p /etc/docker" |
| 342 | scp "$APROJECT_DIR/resources/downloads/jq" $targetip:/usr/local/bin/ |
| 343 | ssh $targetip "if [[ -f /etc/docker/daemon.json ]]; then |
| 344 | jq '.dns += [\"$LOCAL_IP\"]' /etc/docker/daemon.json > /tmp/daemon.json |
| 345 | mv /tmp/daemon.json /etc/docker/daemon.json |
| 346 | else |
| 347 | echo {'\"'dns'\"': ['\"'$LOCAL_IP'\"']} > /etc/docker/daemon.json |
| 348 | fi" |
| 349 | ssh $targetip 'systemctl enable docker; systemctl restart docker' |
| 350 | } |
| 351 | deploy_rancher() { |
| 352 | docker run -d --entrypoint "/bin/bash" --restart=unless-stopped -p 8080:8080 \ |
| 353 | -v $CERTS_TARGET_PATH:/usr/local/share/ca-certificates/extra:ro \ |
| 354 | --name rancher_server rancher/server:v1.6.14 \ |
| 355 | -c "/usr/sbin/update-ca-certificates;/usr/bin/entry /usr/bin/s6-svscan /service" |
| 356 | echo "** wait until rancher is ready **" |
| 357 | } |
| 358 | deploy_kubernetes() { |
| 359 | os=$1 |
| 360 | set +e |
| 361 | for i in `seq 5 -1 1`; do |
| 362 | API_RESPONSE=`curl -s 'http://127.0.0.1:8080/v2-beta/apikey' \ |
| 363 | -d '{"type":"apikey","accountId":"1a1","name":"autoinstall"\ |
| 364 | ,"description":"autoinstall","created":null,"kind":null,\ |
| 365 | "removeTime":null,"removed":null,"uuid":null}'` |
| 366 | if [[ "$?" -eq 0 ]]; then |
| 367 | KEY_PUBLIC=`echo $API_RESPONSE | jq -r .publicValue` |
| 368 | KEY_SECRET=`echo $API_RESPONSE | jq -r .secretValue` |
| 369 | break |
| 370 | fi |
| 371 | echo "Waiting for rancher server to start" |
| 372 | sleep 60 |
| 373 | done |
| 374 | set -e |
| 375 | export RANCHER_URL=http://${LOCAL_IP}:8080 |
| 376 | export RANCHER_ACCESS_KEY=$KEY_PUBLIC |
| 377 | export RANCHER_SECRET_KEY=$KEY_SECRET |
| 378 | rancher env ls |
| 379 | echo "wait 60 sec for rancher environments can settle before we create the onap kubernetes one" |
| 380 | sleep 60 |
| 381 | rancher env create -t kubernetes onap > kube_env_id.json |
| 382 | PROJECT_ID=$(<kube_env_id.json) |
| 383 | echo "env id: $PROJECT_ID" |
| 384 | export RANCHER_HOST_URL=http://${LOCAL_IP}:8080/v1/projects/$PROJECT_ID |
| 385 | for i in `seq 5`; do |
| 386 | status=$(rancher env ls | grep $PROJECT_ID | awk '{print $4}') |
| 387 | if [[ "$status" == "active" ]]; then |
| 388 | echo "Check on environments again before registering the URL response" |
| 389 | rancher env ls |
| 390 | break |
| 391 | fi |
| 392 | echo "Wait for environment to become active" |
| 393 | sleep 30 |
| 394 | done |
| 395 | REG_URL_RESPONSE=`curl -X POST -u $KEY_PUBLIC:$KEY_SECRET -H 'Accept: application/json' -H 'ContentType: application/json' -d '{"name":"$LOCAL_IP"}' "http://$LOCAL_IP:8080/v1/projects/$PROJECT_ID/registrationtokens"` |
| 396 | echo "wait for server to finish url configuration - 3 min" |
| 397 | sleep 180 |
| 398 | # see registrationUrl in |
| 399 | REGISTRATION_TOKENS=`curl http://127.0.0.1:8080/v2-beta/registrationtokens` |
| 400 | REGISTRATION_DOCKER=`echo $REGISTRATION_TOKENS | jq -r .data[0].image` |
| 401 | REGISTRATION_TOKEN=`echo $REGISTRATION_TOKENS | jq -r .data[0].token` |
| 402 | # base64 encode the kubectl token from the auth pair |
| 403 | # generate this after the host is registered |
| 404 | KUBECTL_TOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0) |
| 405 | echo "KUBECTL_TOKEN base64 encoded: ${KUBECTL_TOKEN}" |
| 406 | cat > ~/.kube/config <<EOF |
| 407 | apiVersion: v1 |
| 408 | kind: Config |
| 409 | clusters: |
| 410 | - cluster: |
| 411 | api-version: v1 |
| 412 | insecure-skip-tls-verify: true |
| 413 | server: "https://$LOCAL_IP:8080/r/projects/$PROJECT_ID/kubernetes:6443" |
| 414 | name: "onap" |
| 415 | contexts: |
| 416 | - context: |
| 417 | cluster: "onap" |
| 418 | user: "onap" |
| 419 | name: "onap" |
| 420 | current-context: "onap" |
| 421 | users: |
| 422 | - name: "onap" |
| 423 | user: |
| 424 | token: "$KUBECTL_TOKEN" |
| 425 | EOF |
| 426 | if [[ $os == "rhel" ]]; then |
| 427 | echo "Upgrade datavolume for RHEL" |
| 428 | KUBELET_ID=`curl http://${LOCAL_IP}:8080/v2-beta/projects/${PROJECT_ID}/services/ | jq -r '.data[] | select(.name=="kubelet")'.id` |
| 429 | OLD_LAUNCH_CONFIG=`curl http://${LOCAL_IP}:8080/v2-beta/projects/${PROJECT_ID}/services/${KUBELET_ID} | jq '.launchConfig'` |
| 430 | NEW_LAUNCH_CONFIG=`echo $OLD_LAUNCH_CONFIG | jq '.dataVolumes[2]="/sys/fs/cgroup:/sys/fs/cgroup:ro,rprivate"'` |
| 431 | DATA="{ |
| 432 | \"inServiceStrategy\": { |
| 433 | \"batchSize\": 1, |
| 434 | \"intervalMillis\": 2000, |
| 435 | \"startFirst\": false, |
| 436 | \"launchConfig\": ${NEW_LAUNCH_CONFIG}, |
| 437 | \"secondaryLaunchConfigs\": [] |
| 438 | } |
| 439 | }" |
| 440 | curl -s -u $KEY_PUBLIC:$KEY_SECRET -X POST -H 'Content-Type: application/json' -d "${DATA}" "http://${LOCAL_IP}:8080/v2-beta/projects/${PROJECT_ID}/services/${KUBELET_ID}?action=upgrade" > /dev/null |
| 441 | echo "Give environment time to update (30 sec)" |
| 442 | sleep 30 |
| 443 | curl -s -u $KEY_PUBLIC:$KEY_SECRET -X POST "http://${LOCAL_IP}:8080/v2-beta/projects/${PROJECT_ID}/services/${KUBELET_ID}?action=finishupgrade" > /dev/null |
| 444 | fi |
| 445 | } |
| 446 | deploy_rancher_agent() { |
| 447 | nodeip=$1 |
| 448 | if [ -z "$REGISTRATION_DOCKER" ]; then |
| 449 | echo "ASSERT: Missing REGISTRATION_DOCKER" |
| 450 | exit 1 |
| 451 | fi |
| 452 | if [ -z "$RANCHER_URL" ]; then |
| 453 | echo "ASSERT: Missing RANCHER_URL" |
| 454 | exit 1 |
| 455 | fi |
| 456 | if [ -z "$REGISTRATION_TOKEN" ]; then |
| 457 | echo "ASSERT: Missing REGISTRATION_TOKEN" |
| 458 | exit 1 |
| 459 | fi |
| 460 | ssh $nodeip "docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/racher:/var/lib/rancher $REGISTRATION_DOCKER $RANCHER_URL/v1/scripts/$REGISTRATION_TOKEN" |
| 461 | echo "waiting 2 min for creating kubernetes environment" |
| 462 | sleep 120 |
| 463 | } |
| 464 | deploy_node() { |
| 465 | nodeip=$1 |
| 466 | os=$2 |
| 467 | echo "Deploying node $nodeip" |
| 468 | distribute_root_CA $nodeip |
| 469 | install_remote_docker $nodeip $os |
| 470 | deploy_rancher_agent $nodeip |
| 471 | } |
| 472 | deploy_onap() { |
| 473 | pushd $APROJECT_DIR/resources/oom/kubernetes |
| 474 | helm init --upgrade --skip-refresh |
| 475 | # this might fail |
| 476 | set +e |
| 477 | helm repo remove stable |
| 478 | set -e |
| 479 | helm serve & |
| 480 | echo "wait a moment before helm will come up ..." |
| 481 | sleep 5 |
| 482 | helm repo add local http://127.0.0.1:8879 |
| 483 | make all |
| 484 | #Pass the CA certificate contents directly during installation. |
| 485 | helm install local/onap -n dev --namespace onap \ |
| 486 | --set "global.cacert=$(cat ${CERTS_TARGET_PATH}/rootCAcert.crt)" |
| 487 | popd |
| 488 | } |
| 489 | expand_file() { |
| 490 | file=$1 |
| 491 | # print warning if patched file does not exist as some charts |
| 492 | # might not be available for some deployments |
| 493 | if [ ! -f "$file" ]; then |
| 494 | echo "WARNING: Can't patch file $file because this file does not exists." |
| 495 | return 0 |
| 496 | fi |
| 497 | shift |
| 498 | for ivar in "$@" ; do |
| 499 | ivalue=$(eval 'echo "$'${ivar}'"') |
| 500 | sed -i "s#${ivar}#${ivalue}#g" "$file" |
| 501 | done |
| 502 | } |
| 503 | patch_npm_oom() { |
| 504 | if [ -z "$LOCAL_IP" ] ; then |
| 505 | echo "ERROR: LOCAL_IP unset" |
| 506 | return 1 |
| 507 | fi |
| 508 | if [ -z "$NEXUS_FQDN" ] ; then |
| 509 | echo "ERROR: NEXUS_FQDN unset" |
| 510 | return 1 |
| 511 | fi |
| 512 | UPDATE_HOSTS_FILE="$LOCAL_IP $NEXUS_FQDN" |
| 513 | UPDATE_NPM_REGISTRY="npm set registry \"http://${NEXUS_FQDN}/repository/npm-private/\"" |
| 514 | expand_file $APROJECT_DIR/resources/oom/kubernetes/common/dgbuilder/templates/deployment.yaml \ |
| 515 | UPDATE_HOSTS_FILE \ |
| 516 | UPDATE_NPM_REGISTRY |
| 517 | expand_file $APROJECT_DIR/resources/oom/kubernetes/sdnc/charts/sdnc-portal/templates/deployment.yaml \ |
| 518 | UPDATE_HOSTS_FILE \ |
| 519 | UPDATE_NPM_REGISTRY |
| 520 | } |
| 521 | patch_spring_oom() { |
| 522 | if [ -z "$LOCAL_IP" ] ; then |
| 523 | echo "ERROR: LOCAL_IP unset" |
| 524 | return 1 |
| 525 | fi |
| 526 | UPDATE_HOSTS_FILE="$LOCAL_IP www.springframework.org" |
| 527 | expand_file $APROJECT_DIR/resources/oom/kubernetes/dmaap/charts/message-router/templates/deployment.yaml \ |
| 528 | UPDATE_HOSTS_FILE |
| 529 | } |
| 530 | patch_cfy_manager_depl() { |
| 531 | os="$1" |
| 532 | file="${APROJECT_DIR}/resources/oom/kubernetes/dcaegen2/charts/dcae-cloudify-manager/templates/deployment.yaml" |
| 533 | case "$os" in |
| 534 | centos|rhel) |
| 535 | CERT_PATH="/etc/pki/ca-trust/source/anchors" |
| 536 | ;; |
| 537 | ubuntu) |
| 538 | CERT_PATH="/usr/local/share/ca-certificates/extra" |
| 539 | ;; |
| 540 | '') |
| 541 | echo "ERROR: missing argument" |
| 542 | return 1 |
| 543 | ;; |
| 544 | *) |
| 545 | echo "ERROR: unknown OS: ${os}" |
| 546 | return 1 |
| 547 | ;; |
| 548 | esac |
| 549 | expand_file "$file" CERT_PATH |
| 550 | } |
| 551 | copy_onap_values_file() { |
| 552 | cp "${APROJECT_DIR}/cfg/${ONAP_SCALE}_depl_values.yaml" \ |
| 553 | "${APROJECT_DIR}/resources/oom/kubernetes/onap/values.yaml" |
| 554 | } |