update the committers for icn
[icn.git] / deploy / kud / kud_bm_launch.sh
index 86d4aa3..9ba2d40 100755 (executable)
@@ -1,17 +1,16 @@
-#!/bin/bash
-LIBDIR="$(dirname "$(dirname "$PWD")")"
+#!/usr/bin/env bash
+set -eu -o pipefail
 
-source $LIBDIR/env/lib/common.sh
+SCRIPTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
+LIBDIR="$(dirname $(dirname ${SCRIPTDIR}))/env/lib"
 
-function get_kud_repo {
-    if [ -d $DOWNLOAD_PATH/multicloud-k8s ]; then
-        rm -rf $DOWNLOAD_PATH/multicloud-k8s
-    fi
+source $LIBDIR/common.sh
 
-    mkdir -p $DOWNLOAD_PATH
-    pushd $DOWNLOAD_PATH
-    git clone https://github.com/onap/multicloud-k8s.git
-    popd
+export KUBESPRAY_VERSION=2.16.0
+
+function get_kud_repo {
+    clone_kud_repository
+    export KUD_ADDONS=multus
 }
 
 function set_ssh_key {
@@ -28,11 +27,19 @@ function set_ssh_key {
 }
 
 function set_bm_kud {
-    pushd $DOWNLOAD_PATH/multicloud-k8s/kud/hosting_providers/vagrant/inventory
+    pushd ${KUDPATH}/kud/hosting_providers/vagrant/inventory
     HOST_IP=${HOST_IP:-$(hostname -I | cut -d ' ' -f 1)}
+    DOCKER_OPTIONS=""
+    if [[ ! -z "${DOCKER_REGISTRY_MIRRORS+x}" ]]; then
+       OPTIONS=""
+       for mirror in ${DOCKER_REGISTRY_MIRRORS}; do
+           OPTIONS="${OPTIONS} --registry-mirror=${mirror}"
+       done
+       DOCKER_OPTIONS="docker_options=\"${OPTIONS# }\""
+    fi
     cat <<EOL > hosts.ini
 [all]
-$HOSTNAME ansible_ssh_host=${HOST_IP} ansible_ssh_port=22
+$HOSTNAME ansible_ssh_host=${HOST_IP} ansible_ssh_port=22 ${DOCKER_OPTIONS}
 
 [kube-master]
 $HOSTNAME
@@ -43,9 +50,6 @@ $HOSTNAME
 [etcd]
 $HOSTNAME
 
-[virtlet]
-$HOSTNAME
-
 [k8s-cluster:children]
 kube-node
 kube-master
@@ -54,8 +58,17 @@ EOL
 }
 
 function kud_install {
-    pushd $DOWNLOAD_PATH/multicloud-k8s/kud/hosting_providers/vagrant/
-    ./installer.sh | tee kud_minial_deploy.log
+    pushd ${KUDPATH}/kud/hosting_providers/vagrant/
+    ./installer.sh | tee kud_deploy.log
+    popd
+}
+
+function kud_reset {
+    # Pick up the kubespray ANSIBLE_CONFIG from /etc/environment
+    source /etc/environment
+    pushd ${KUDPATH}/kud/hosting_providers/vagrant/
+    ansible-playbook -i inventory/hosts.ini /opt/kubespray-${KUBESPRAY_VERSION}/reset.yml \
+        --become --become-user=root -e reset_confirmation=yes
     popd
 }
 
@@ -69,6 +82,10 @@ function verifier {
   call_api $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
 }
 
+if [ "$1" == "reset" ] ; then
+    kud_reset
+    exit 0
+fi
 
 get_kud_repo
 set_ssh_key