From 7742a58479883af8f4d6223cb5926a7a0f65044f Mon Sep 17 00:00:00 2001 From: camilamacedo86 Date: Tue, 30 May 2023 12:40:48 +0100 Subject: [PATCH] Add post init check --- addons/flannel/0.21.5/install.sh | 158 ++++++++++++++++++++++++ addons/flannel/template/base/install.sh | 158 ++++++++++++++++++++++++ 2 files changed, 316 insertions(+) diff --git a/addons/flannel/0.21.5/install.sh b/addons/flannel/0.21.5/install.sh index 16a6358071..5d49704567 100644 --- a/addons/flannel/0.21.5/install.sh +++ b/addons/flannel/0.21.5/install.sh @@ -590,4 +590,162 @@ function flannel_already_applied() { flannel_ready_spinner check_network + check_connection +} + +function flannel_post_init() { + check_connection +} + + +# flannel_find_free_port will check any free port to be used to do the check +function flannel_find_free_port() { + while : + do + PORT=$(shuf -i 2000-65000 -n 1) + if ss -lau | grep $PORT > /dev/null; then + echo $PORT + return 0 + fi + done +} + +# check_connection will check the connection using any port available +# note that when we have a multi node install we will create the Pods in each node to verify +# the connection across nodes +function check_connection() { + local PORT=$(flannel_find_free_port) + + logStep "Checking Flannel Connection over port $PORT" + + local num_nodes=$(kubectl get nodes --selector='!node-role.kubernetes.io/master' --no-headers | wc -l) + + echo "Creating Pods to check communication" + if [[ $num_nodes -gt 1 ]]; then + echo "Create pod to do the test using podAntiAffinity to check the communication across nodes" + kubectl apply -f - < /dev/null; then + echo $PORT + return 0 + fi + done +} + +# check_connection will check the connection using any port available +# note that when we have a multi node install we will create the Pods in each node to verify +# the connection across nodes +function check_connection() { + local PORT=$(flannel_find_free_port) + + logStep "Checking Flannel Connection over port $PORT" + + local num_nodes=$(kubectl get nodes --selector='!node-role.kubernetes.io/master' --no-headers | wc -l) + + echo "Creating Pods to check communication" + if [[ $num_nodes -gt 1 ]]; then + echo "Create pod to do the test using podAntiAffinity to check the communication across nodes" + kubectl apply -f - <