diff --git a/addons/flannel/0.21.5/install.sh b/addons/flannel/0.21.5/install.sh index 1f8b8d0dc2..ed4e9b6a16 100644 --- a/addons/flannel/0.21.5/install.sh +++ b/addons/flannel/0.21.5/install.sh @@ -329,4 +329,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 - <