Merge "[ci] Add PDF/IDF config files for 2 virtual PODs"
authorCristina Pauna <cristina.pauna@enea.com>
Wed, 27 Mar 2019 16:06:50 +0000 (16:06 +0000)
committerGerrit Code Review <gerrit@akraino.org>
Wed, 27 Mar 2019 16:06:50 +0000 (16:06 +0000)
src/foundation/scripts/config.sh [new file with mode: 0755]
src/foundation/scripts/functest.sh [new file with mode: 0755]
src/foundation/scripts/helm.sh
src/foundation/scripts/k8s_common.sh
src/foundation/scripts/nginx.sh
src/foundation/scripts/startup.sh

diff --git a/src/foundation/scripts/config.sh b/src/foundation/scripts/config.sh
new file mode 100755 (executable)
index 0000000..9bd88e0
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# Host user which can log into master and each worker nodes
+HOST_USER=${HOST_USER:-iec}
+
+REPO_URL="https://gerrit.akraino.org/r/iec"
+#log file
+LOG_FILE="kubeadm.log"
+
+
+# Master node IP address
+K8S_MASTER_IP="10.169.36.152"
+
+# HOST_USER's password on Master node
+K8S_MASTERPW="123456"
+
+######################################################
+#
+#  K8S_WORKER_GROUP is an array which consists of 2
+#  parts. One is k8s worker ip address. The other is
+#  the user password.
+#
+######################################################
+K8S_WORKER_GROUP=(
+"10.169.40.106,123456"
+)
+
+
diff --git a/src/foundation/scripts/functest.sh b/src/foundation/scripts/functest.sh
new file mode 100755 (executable)
index 0000000..a3e4bae
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/bash
+# Run the functest-kubernetes on master node for checking
+# K8s environments
+set -e
+
+K8S_MASTER_IP=$1
+
+
+if [ -z "${K8S_MASTER_IP}" ]
+then
+  echo "Error:K8S_MASTER_IP is empty."
+  echo "Please input the k8s master ip address."
+  echo "Just as:"
+  echo "./functest.sh 10.1.1.1"
+  exit 1
+fi
+
+
+cat <<EOF > "${HOME}/k8.creds"
+export KUBERNETES_PROVIDER=local
+export KUBE_MASTER_URL=https://${K8S_MASTER_IP}:6443
+export KUBE_MASTER_IP=${K8S_MASTER_IP}
+EOF
+
+mkdir -p "${HOME}/functest/results"
+
+sudo docker run --rm -e DEPLOY_SCENARIO=k8-nosdn-nofeature-noha \
+       -v "${HOME}/k8.creds:/home/opnfv/functest/conf/env_file" \
+       -v "${HOME}/functest/results:/home/opnfv/functest/results" \
+       -v "${HOME}/.kube/config:/root/.kube/config" opnfv/functest-kubernetes-healthcheck:latest \
+       /bin/bash -c 'run_tests -r -t all'
index 3f575d2..ccd32ae 100755 (executable)
@@ -42,3 +42,4 @@ EOF
   kubectl create -f "${TILLER_SA_RBAC}"
   helm init --service-account tiller --tiller-image="jessestuart/tiller:${VERSION}"
 fi
+rm -f "${TILLER_SA_RBAC}"
index e1e086d..0e9de86 100755 (executable)
@@ -2,6 +2,7 @@
 
 DOCKER_VERSION=18.06.1~ce~3-0~ubuntu
 KUBE_VERSION=1.13.0-00
+K8S_CNI_VERSION=0.6.0-00
 
 # Install Docker as Prerequisite
 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
@@ -25,9 +26,10 @@ cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
 deb https://apt.kubernetes.io/ kubernetes-xenial main
 EOF
 sudo apt update
+# Minor fix for broken kubernetes-cni dependency in upstream xenial repo
 sudo apt install -y \
-  kubelet=${KUBE_VERSION} kubeadm=${KUBE_VERSION} kubectl=${KUBE_VERSION}
-sudo apt-mark hold kubelet kubeadm kubectl
+  kubernetes-cni=${K8S_CNI_VERSION} kubelet=${KUBE_VERSION} kubeadm=${KUBE_VERSION} kubectl=${KUBE_VERSION}
+sudo apt-mark hold kubernetes-cni kubelet kubeadm kubectl
 
 #Add extra flags to Kubelet
 if ! grep -q -e 'fail-swap-on' /etc/default/kubelet; then
index 40a9377..307371b 100755 (executable)
@@ -57,8 +57,9 @@ done
 
 svcip=$(kubectl get services nginx  -o json | grep clusterIP | cut -f4 -d'"')
 sleep 10
-wget "http://$svcip"
+wget -O /dev/null "http://$svcip"
 kubectl delete -f "${NGINX_APP}"
+rm -f "${NGINX_APP}"
 kubectl get rc
 kubectl get pods
 kubectl get services
index b58a43b..f68c2fb 100755 (executable)
@@ -7,14 +7,20 @@ set -e
 # Displays the help menu.
 #
 display_help () {
-  echo "Usage: $0 [master ip] [worker ip] [user] [password] "
+  echo "Usage:"
   echo " "
-  echo "There should be an user which will be used to install the "
-  echo "corresponding software on master & worker node. This user can "
+  echo "This script can help you to deploy a simple iec testing"
+  echo "environments."
+  echo "Firstly, the master node and worker node information must"
+  echo "be added into config file which will be used for deployment."
+  echo ""
+  echo "Secondly, there should be an user on each node which will be"
+  echo "used to install the corresponding software on master and"
+  echo "worker nodes. At the same time, this user should be enable to"
   echo "run the sudo command without input password on the hosts."
   echo " "
   echo "Example usages:"
-  echo "   ./startup.sh 10.169.40.171 10.169.41.172 iec 123456"
+  echo "   ./startup.sh"
 }
 
 
@@ -33,15 +39,26 @@ deploy_k8s () {
   #Automatic deploy the K8s environments on Master node
   SETUP_MASTER="cd iec/src/foundation/scripts/ && source k8s_master.sh ${K8S_MASTER_IP}"
   sshpass -p ${K8S_MASTERPW} ssh ${HOST_USER}@${K8S_MASTER_IP} ${INSTALL_SOFTWARE}
-  sshpass -p ${K8S_MASTERPW} ssh ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_MASTER} | tee kubeadm.log
+  sshpass -p ${K8S_MASTERPW} ssh ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_MASTER} | tee ${LOG_FILE}
 
-  KUBEADM_JOIN_CMD=$(grep "kubeadm join " ./kubeadm.log)
+  KUBEADM_JOIN_CMD=$(grep "kubeadm join " ./${LOG_FILE})
 
-  #Automatic deploy the K8s environments on Worker node
+
+  #Automatic deploy the K8s environments on each worker-node
   SETUP_WORKER="cd iec/src/foundation/scripts/ && source k8s_worker.sh"
-  sshpass -p ${K8S_WORKERPW} ssh ${HOST_USER}@${K8S_WORKER01_IP} ${INSTALL_SOFTWARE}
-  sshpass -p ${K8S_WORKERPW} ssh ${HOST_USER}@${K8S_WORKER01_IP} "echo \"sudo ${KUBEADM_JOIN_CMD}\" >> ./iec/src/foundation/scripts/k8s_worker.sh"
-  sshpass -p ${K8S_WORKERPW} ssh ${HOST_USER}@${K8S_WORKER01_IP} ${SETUP_WORKER}
+
+  for worker in "${K8S_WORKER_GROUP[@]}"
+  do
+    ip_addr="$(cut -d',' -f1 <<<${worker})"
+    passwd="$(cut -d',' -f2 <<<${worker})"
+    echo "Install & Deploy on ${ip_addr}. password:${passwd}"
+
+    sshpass -p ${passwd} ssh ${HOST_USER}@${ip_addr} ${INSTALL_SOFTWARE}
+    sshpass -p ${passwd} ssh ${HOST_USER}@${ip_addr} "echo \"sudo ${KUBEADM_JOIN_CMD}\" >> ./iec/src/foundation/scripts/k8s_worker.sh"
+    sshpass -p ${passwd} ssh ${HOST_USER}@${ip_addr} ${SETUP_WORKER}
+
+  done
+
 
   #Deploy etcd & CNI from master node
   #There may be more options in future. e.g: Calico, Contiv-vpp, Ovn-k8s ...
@@ -62,32 +79,23 @@ check_k8s_status(){
 }
 
 
-PASSWD=${4:-"123456"}
-HOST_USER=${3:-"iec"}
-
-K8S_MASTER_IP=${1:-"10.169.40.171"}
-K8S_MASTERPW=${PASSWD}
-
-K8S_WORKER01_IP=${2:-"10.169.41.172"}
-K8S_WORKERPW=${PASSWD}
-
-REPO_URL="https://gerrit.akraino.org/r/iec"
-LOG_FILE="kubeadm.log"
-
-if [ -f "./${LOG_FILE}" ]; then
-  rm "${LOG_FILE}"
-fi
-
 #
 # Init
 #
-if [ $# -lt 4 ]
+if [ $1 == "--help" ] || [ $1 == "-h" ];
 then
   display_help
   exit 0
 fi
 
 
+# Read the configuration file
+source config
+
+echo "The number of K8s-Workers:${#K8S_WORKER_GROUP[@]}"
+
+rm -f "${LOG_FILE}"
+
 deploy_k8s
 
 check_k8s_status