Adding k8s cluster for the CD 45/1845/1
authorr.kuralamudhan <kuralamudhan.ramakrishnan@intel.com>
Thu, 24 Oct 2019 15:59:51 +0000 (08:59 -0700)
committerr.kuralamudhan <kuralamudhan.ramakrishnan@intel.com>
Thu, 24 Oct 2019 22:13:22 +0000 (15:13 -0700)
Change-Id: I070fbd128f08cda702a7b5c88d57219055759f00
Signed-off-by: r.kuralamudhan <kuralamudhan.ramakrishnan@intel.com>
Makefile
deploy/kud/kud_bm_launch.sh [new file with mode: 0755]
env/cd_package_installer.sh [new file with mode: 0755]
env/lib/common.sh

index 8b66788..80e8cea 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,5 @@
 SHELL:=/bin/bash
+ENV:=$(CURDIR)/env
 BMDIR:=$(CURDIR)/env/metal3
 METAL3DIR:=$(CURDIR)/deploy/metal3/scripts
 BPA_OPERATOR:=$(CURDIR)/cmd/bpa-operator/
@@ -23,8 +24,8 @@ bm_install:
 
 bm_all: bm_preinstall bm_install
 
-kud_download:
-       pushd $(KUD_PATH) && ./kud_launch.sh && popd
+kud_bm_deploy:
+       pushd $(KUD_PATH) && ./kud_bm_launch.sh && popd
 
 bpa_op_install:
        pushd $(BPA_OPERATOR) && make docker && make deploy && popd
@@ -45,12 +46,12 @@ bpa_op_all: bm_all bpa_op_install
 bashate:
        bashate -i E006 `find . -name *.sh`
 
-ci_dummy_test:
-       $(info ************  TESTING ICN CD LOGS ************)
+prerequisite:
+       pushd $(ENV) && ./cd_package_installer.sh && popd
 
-verify_all: ci_dummy_test
-
-verifer: verify_all
+verify_all: prerequisite \
+       kud_bm_deploy 
 
+verifier: verify_all
 
 .PHONY: all bm_preinstall bm_install bashate
diff --git a/deploy/kud/kud_bm_launch.sh b/deploy/kud/kud_bm_launch.sh
new file mode 100755 (executable)
index 0000000..86d4aa3
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/bash
+LIBDIR="$(dirname "$(dirname "$PWD")")"
+
+source $LIBDIR/env/lib/common.sh
+
+function get_kud_repo {
+    if [ -d $DOWNLOAD_PATH/multicloud-k8s ]; then
+        rm -rf $DOWNLOAD_PATH/multicloud-k8s
+    fi
+
+    mkdir -p $DOWNLOAD_PATH
+    pushd $DOWNLOAD_PATH
+    git clone https://github.com/onap/multicloud-k8s.git
+    popd
+}
+
+function set_ssh_key {
+    if ! [ -f ~/.ssh/id_rsa ]; then
+        echo "Generating rsa key for this host"
+        ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa <&-
+    fi
+
+    if ! grep -qF "$(ssh-keygen -y -f ~/.ssh/id_rsa)" ~/.ssh/authorized_keys; then
+        ssh-keygen -y -f ~/.ssh/id_rsa >> ~/.ssh/authorized_keys
+    fi
+
+    chmod og-wx ~/.ssh/authorized_keys
+}
+
+function set_bm_kud {
+    pushd $DOWNLOAD_PATH/multicloud-k8s/kud/hosting_providers/vagrant/inventory
+    HOST_IP=${HOST_IP:-$(hostname -I | cut -d ' ' -f 1)}
+    cat <<EOL > hosts.ini
+[all]
+$HOSTNAME ansible_ssh_host=${HOST_IP} ansible_ssh_port=22
+
+[kube-master]
+$HOSTNAME
+
+[kube-node]
+$HOSTNAME
+
+[etcd]
+$HOSTNAME
+
+[virtlet]
+$HOSTNAME
+
+[k8s-cluster:children]
+kube-node
+kube-master
+EOL
+    popd
+}
+
+function kud_install {
+    pushd $DOWNLOAD_PATH/multicloud-k8s/kud/hosting_providers/vagrant/
+    ./installer.sh | tee kud_minial_deploy.log
+    popd
+}
+
+function verifier {
+    APISERVER=$(kubectl config view --minify -o \
+                    jsonpath='{.clusters[0].cluster.server}')
+    TOKEN=$(kubectl get secret \
+        $(kubectl get serviceaccount default -o \
+        jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | \
+        base64 --decode )
+  call_api $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
+}
+
+
+get_kud_repo
+set_ssh_key
+set_bm_kud
+kud_install
+verifier
+
+exit 0
diff --git a/env/cd_package_installer.sh b/env/cd_package_installer.sh
new file mode 100755 (executable)
index 0000000..6370f01
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+set -ex
+
+if [[ $EUID -ne 0 ]]; then
+    echo "This script must be run as root"
+    exit 1
+fi
+
+function install_essential_packages {
+    export DEBIAN_FRONTEND=noninteractive
+    apt-get update
+    apt-get -y install \
+    crudini \
+    curl \
+    dnsmasq \
+    figlet \
+    nmap \
+    patch \
+    psmisc \
+    python-pip \
+    python-requests \
+    python-setuptools \
+    vim \
+    wget \
+    git \
+    software-properties-common
+
+    add-apt-repository -y ppa:longsleep/golang-backports
+    apt-get update
+    apt-get install -y golang-go
+}
+
+install_essential_packages
index f4198d0..5705402 100755 (executable)
@@ -4,7 +4,7 @@
 UBUNTU_BIONIC=${UBUNTU_BIONIC:-Ubuntu 18.04.2 LTS}
 
 #offline mode variable
-DOWNLOAD_PATH=${DOWNLOAD_PATH:-/opt/icn/}
+DOWNLOAD_PATH=${DOWNLOAD_PATH:-/opt/icn}
 LOCAL_APT_REPO=${LOCAL_APT_REPO:-$DOWNLOAD_PATH/apt}
 PIP_CACHE_DIR=${PIP_CACHE_DIR:-$DOWNLOAD_PATH/pip-cache-dir}
 BUILD_DIR=${BUILD_DIR:-$DOWNLOAD_PATH/build-dir}
@@ -43,3 +43,34 @@ COMPUTE_IPMI_PASSWORD=${COMPUTE_IPMI_PASSWORD:-"changeme1"}
 COMPUTE_NODE_FQDN=${COMPUTE_NODE_FQDN:-"node01.akraino.org"}
 #COMPUTE_NODE_HOSTNAME=${COMPUTE_NODE_HOSTNAME:-"node01"}
 COMPUTE_NODE_PASSWORD=${COMPUTE_NODE_PASSWORD:-"mypasswd"}
+
+#refered from onap
+function call_api {
+    #Runs curl with passed flags and provides
+    #additional error handling and debug information
+
+    #Function outputs server response body
+    #and performs validation of http_code
+
+    local status
+    local curl_response_file="$(mktemp -p /tmp)"
+    local curl_common_flags=(-s -w "%{http_code}" -o "${curl_response_file}")
+    local command=(curl "${curl_common_flags[@]}" "$@")
+
+    echo "[INFO] Running '${command[@]}'" >&2
+    if ! status="$("${command[@]}")"; then
+        echo "[ERROR] Internal curl error! '$status'" >&2
+        cat "${curl_response_file}"
+        rm "${curl_response_file}"
+        return 2
+    else
+        echo "[INFO] Server replied with status: ${status}" >&2
+        cat "${curl_response_file}"
+        rm "${curl_response_file}"
+        if [[ "${status:0:1}" =~ [45] ]]; then
+            return 1
+        else
+            return 0
+        fi
+    fi
+}