From 6721e05387ea07be03bf1e03f098fc78da9a9137 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Wed, 14 Jun 2023 20:21:23 +0200 Subject: [PATCH] Cleanup bugfixes. Move vars to dedicated files --- scripts/.cleanup.sh | 14 +++++++++++--- scripts/.common | 23 +++-------------------- scripts/0.start_dls.sh | 8 +------- scripts/1.qemu.sh | 2 +- scripts/2.first_start_k8s.sh | 19 +++++++++++++++++++ scripts/vars | 28 ++++++++++++++++++++++++++++ 6 files changed, 63 insertions(+), 31 deletions(-) create mode 100644 scripts/vars diff --git a/scripts/.cleanup.sh b/scripts/.cleanup.sh index 1ad108a..018787a 100755 --- a/scripts/.cleanup.sh +++ b/scripts/.cleanup.sh @@ -1,7 +1,7 @@ #!/bin/bash stopdls() { - if docker ps &>/dev/null | grep -q " $DLS_CTR_NAME$"; then + if docker ps | grep -q " $DLS_CTR_NAME$"; then pinfo "Stopping Direktil Local Server..." docker stop $DLS_CTR_NAME fi @@ -28,14 +28,20 @@ cleanuppaths() { done } +cleanupssh() { + for host in ${!hosts[*]}; do + ssh-keygen -R ${hosts[$host]} &>/dev/null + done +} + cleanupnetwork() { - if iptables -L |grep -q $QEMU_BR_NAME; then + if iptables -L -n |grep -q $QEMU_BR_NAME; then pinfo "Cleaning iptables rules..." iptables -t nat -D POSTROUTING -j MASQUERADE -s $QEMU_BR_IP/$QEMU_BR_MASK \! -o $QEMU_BR_NAME iptables -D FORWARD -o $QEMU_BR_NAME -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT iptables -D FORWARD -j ACCEPT -i $QEMU_BR_NAME fi - if ip li show $QEMU_BR_NAME ; then + if ip li show $QEMU_BR_NAME &>/dev/null; then pinfo "Cleaning existing interfaces..." ip li set $QEMU_BR_NAME down ip li del $QEMU_BR_NAME @@ -50,3 +56,5 @@ declare -A hosts get_hosts destroyvms cleanuppaths +cleanupssh +cleanupnetwork diff --git a/scripts/.common b/scripts/.common index d9f045a..98ed440 100644 --- a/scripts/.common +++ b/scripts/.common @@ -1,24 +1,6 @@ #!/bin/bash -## Vars -# Docker container name for dir2config -D2C_CTR_NAME=dir2config -# Docker container name for direktil local server -DLS_CTR_NAME=dls - -# QEMU local bridge name. If you specificy a custom name, you may have to configure qemu bridge helper to allow it -QEMU_BR_NAME=virbr0 -# QEMU VM default disk size -QEMU_DISK_SIZE=30G -# Allocated CPUs to QEMU VMs -QEMU_VM_CPU=4 -# Allocated Memory to QEMU VMs -QEMU_VM_MEM=8096 -################ - -# Token file for dls -tknfile=".dls_adm_token" - +source $(dirname $0)/vars ## Helper funcs @@ -57,9 +39,10 @@ check_root() { } prereqs() { - # set -ex + set -e cd "$(dirname $0)/.." ctxdir="$PWD" + source scripts/vars } check_conf() { diff --git a/scripts/0.start_dls.sh b/scripts/0.start_dls.sh index 03d1a14..e1cbe88 100755 --- a/scripts/0.start_dls.sh +++ b/scripts/0.start_dls.sh @@ -1,11 +1,5 @@ #!/bin/bash # -# Admin token to unlock the DLS store -DLS_UNLOCK_TOKEN=changeme -# -# -D2C_IMG=novit.tech/direktil/local-server:b6fa941 -DLS_IMG=novit.tech/direktil/local-server:b6fa941 prereqs_dls() { command -v docker 1>/dev/null || perror "Docker is needed, please install it and run again." @@ -39,8 +33,8 @@ start_store() { source $(dirname $0)/.common check_root -prereqs_dls prereqs +prereqs_dls dir2config start_store unlock_store diff --git a/scripts/1.qemu.sh b/scripts/1.qemu.sh index 889947e..b76b30a 100755 --- a/scripts/1.qemu.sh +++ b/scripts/1.qemu.sh @@ -14,7 +14,7 @@ prereqs_qemu() { done } setup_network_qemu() { - if ! ip li show $QEMU_BR_NAME ; then + if ! ip li show $QEMU_BR_NAME &>/dev/null ; then ip li add name $QEMU_BR_NAME type bridge ip li set $QEMU_BR_NAME up fi diff --git a/scripts/2.first_start_k8s.sh b/scripts/2.first_start_k8s.sh index bdf9f16..9f8953c 100755 --- a/scripts/2.first_start_k8s.sh +++ b/scripts/2.first_start_k8s.sh @@ -47,6 +47,24 @@ EOF done } +wait_for_apiserver() { + vip=$(extract_var clusters public_vip) + vip_api_port=$(extract_var clusters api_port) + + sleep 20 + 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 30 + fi + done + +} + install_addons() { body='{"Kind":"cluster","Name":"'$cluster'","Assets":["addons"]}' download_id=$(dls /authorize-download -d "$body"|tr -d \") @@ -82,6 +100,7 @@ unlock_store declare -A hosts && get_hosts checkup start_control_plane +wait_for_apiserver create_kubeconfig install_addons approve_kubelet_certificates # clients and serving certs diff --git a/scripts/vars b/scripts/vars new file mode 100644 index 0000000..a4a7067 --- /dev/null +++ b/scripts/vars @@ -0,0 +1,28 @@ +## Vars + +# Admin token to unlock the DLS store +DLS_UNLOCK_TOKEN=changeme + +# Docker container name for dir2config +D2C_IMG=novit.tech/direktil/local-server:b6fa941 +D2C_CTR_NAME=dir2config + +# Docker container name for direktil local server +DLS_IMG=novit.tech/direktil/local-server:b6fa941 +DLS_CTR_NAME=dls + +# QEMU local bridge name. If you specificy a custom name, you may have to configure qemu bridge helper to allow it +QEMU_BR_NAME=virbr0 +# QEMU VM default disk size +QEMU_DISK_SIZE=30G +# Allocated CPUs to QEMU VMs +QEMU_VM_CPU=4 +# Allocated Memory to QEMU VMs +QEMU_VM_MEM=8096 +################ + +# Token file for dls +tknfile=".dls_adm_token" + +# SSH command args +SSH_CMD="ssh -o StrictHostKeyChecking=no"