Modify setup_network function to add support for Node 3-5
[kuberef.git] / functions.sh
index f0e1213..5b4a3fd 100755 (executable)
@@ -74,7 +74,7 @@ check_prerequisites() {
     if [ "${ID,,}" == "ubuntu" ] && [ "$VERSION_ID" == "16.04" ]; then
         libvirt_group+="d"
     fi
-    if ! groups | grep " $libvirt_group "; then
+    if ! groups | grep "$libvirt_group"; then
         echo "ERROR : $(id -nu) user doesn't belong to $libvirt_group group."
         exit 1
     fi
@@ -145,16 +145,19 @@ EOF
 
 # Setup networking on provisioned hosts (Adapt setup_network.sh according to your network setup)
 setup_network() {
-    MASTER_IP=$(get_host_pxe_ip "nodes[0]")
-    WORKER_IP=$(get_host_pxe_ip "nodes[1]")
+# Set Upper limit of number nodes in RI2 cluster (starting from 0)
+NODE_MAX_ID=$(($(yq r "$CURRENTPATH"/hw_config/"$VENDOR"/idf.yaml --length idf.kubespray.hostnames)-1))
+
+for idx in $(seq 0 "$NODE_MAX_ID")
+do
+    NODE_IP=$(get_host_pxe_ip "nodes[${idx}]")
 # SSH to jumphost
     # shellcheck disable=SC2087
     ssh -o StrictHostKeyChecking=no -tT "$USERNAME"@"$(get_vm_ip)" << EOF
-ssh -o StrictHostKeyChecking=no root@$MASTER_IP \
-    'bash -s' <  ${PROJECT_ROOT}/${VENDOR}/setup_network.sh
-ssh -o StrictHostKeyChecking=no root@$WORKER_IP \
+ssh -o StrictHostKeyChecking=no root@${NODE_IP} \
     'bash -s' <  ${PROJECT_ROOT}/${VENDOR}/setup_network.sh
 EOF
+done
 }
 
 # k8s Provisioning (currently BMRA)