#!/bin/bash # # Starting control plane prereqs_control_plane() { for com in kubectl ; do command -v $com 1>/dev/null || perror "Command $com is not installed, aborting..." done } prereqs_addons() { for com in curl kubectl ; do command -v $com 1>/dev/null || perror "Command $com is not installed, aborting..." done cluster=$(basename $ctxdir/clusters/*.yaml|sed 's/.yaml//') } checkup() { for host in ${!hosts[*]}; do tries=3 while : do pinfo "Checking availability of node $host..." if true | sshcmd -q root@${hosts[$host]}; then pinfo "VM $host is up!" break else ((tries--)) if [ "$tries" -lt "1" ]; then pinfo "Timeout waiting for node detection, please investigate why node $host is not up by now" break fi sleep 30 fi done done } start_control_plane() { for host in ${!hosts[*]}; do sshcmd -q root@${hosts[$host]} << EOF if ls /etc/kubernetes/manifests.static/* &>/dev/null ; then mv /etc/kubernetes/manifests.static/* /var/lib/kubelet/manifests/ fi EOF done } wait_for_apiserver() { vip=$(extract_var clusters public_vip) vip_api_port=$(extract_var clusters api_port) while : do pinfo "Waiting for apiserver availability ($vip:$vip_api_port). Images may still being pulled... " if kctl get node &>/dev/null ; then pinfo "API is up!" break else sleep 20 fi done } install_addons() { body='{"Kind":"cluster","Name":"'$cluster'","Assets":["addons"]}' download_id=$(dls /authorize-download -d "$body"|tr -d \") dls /public/downloads/${download_id}/addons |\ kctl apply -f - } approve_kubelet_certificates() { tries=10 nodes_num=$(kctl get node -oname|wc -l) while [ "$nodes_num" -lt "${#hosts[*]}" ] ; do pinfo "Waiting for certificates requests to be created by Kubelet when it's ready... ($tries tries out of 10)" sleep 20s csrs="$(kctl get csr|awk '/Pending/ {print $1}')" if [ "$csrs" != "" ]; then kctl certificate approve $csrs fi ((tries--)) if [ "$tries" -lt "1" ]; then perror "Timeout waiting for kubelet certificates creation, please investigate why all nodes are not up by now" fi nodes_num=$(kctl get node -oname|wc -l) done pinfo "All kubelets ($nodes_num) are up, enjoy !" } source $(dirname $0)/.common prereqs prereqs_control_plane prereqs_addons check_conf unlock_store declare -A hosts && get_hosts checkup start_control_plane create_kubeconfig wait_for_apiserver install_addons approve_kubelet_certificates # clients and serving certs