Skip to content

Commit

Permalink
Using the code that exist already
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed May 31, 2023
1 parent 145e0f6 commit 7c2f6b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 89 deletions.
95 changes: 8 additions & 87 deletions addons/flannel/0.21.5/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ function flannel_check_nodes_connectivity() {
fi
fi

log "Verifying if all nodes can communicate with each other through port 8472/UDP."
logStep "Verifying if all nodes can communicate with each other through port 8472/UDP."
if ! "$DIR"/bin/kurl netutil nodes-connectivity --port 8472 --image "$KURL_UTIL_IMAGE" --proto udp; then
logFail "Flannel requires UDP port 8472 for communication between nodes."
logFail "Please make sure this port is open prior to running this upgrade."
bail "Not migrating from Weave to Flannel"
fi
logSuccess "Nodes can communicate with each other successfully"
}

function flannel_join() {
Expand Down Expand Up @@ -304,91 +305,11 @@ function flannel_already_applied() {
}

function flannel_post_init() {
check_udp_port
}

function check_udp_port() {
logSubstep "Checking Flannel UDP Connection over port 8472"

# Get the number of worker nodes in the cluster
# If we have at least 2 nodes we will use affinity to be able to test it across the nodes
local num_nodes=$(kubectl get nodes --selector='!node-role.kubernetes.io/master' --no-headers | wc -l)

# Create the receiver pod
echo "Creating Pods to check communication"
if [[ $num_nodes -gt 1 ]]; then
# Use podAntiAffinity if there are multiple nodes
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
name: udp-receiver
labels:
app: udp-receiver
spec:
containers:
- name: udp-receiver
image: busybox
command: ["sh", "-c", "nc -lu 8472"]
ports:
- containerPort: 8472
protocol: UDP
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- udp-sender
topologyKey: "kubernetes.io/hostname"
EOF
else

# Do not use podAntiAffinity if there is only one node
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
name: udp-receiver
spec:
containers:
- name: udp-receiver
image: busybox
command: ["sh", "-c", "nc -lu 8472"]
ports:
- containerPort: 8472
protocol: UDP
EOF
logStep "Verifying if all nodes can communicate with each other through port 8472/UDP."
if ! "$DIR"/bin/kurl netutil nodes-connectivity --port 8472 --image "$KURL_UTIL_IMAGE" --proto udp; then
logFail "Flannel requires UDP port 8472 for communication between nodes."
logFail "Unable to check communication between nodes successfully"
fi

# Wait for the pods to be Running
for i in {1..60}; do
if [[ $(kubectl get pod udp-receiver -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') == "True" ]] && [[ $(kubectl get pod udp-sender -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') == "True" ]]; then
log "Pods to check UPD communication with Flannel are in Running state."
break
elif [[ $i -eq 60 ]]; then
logWarn "Pods to check UPD communication with Flannel did not become Ready within the expected time."
exit 1
fi
echo "Waiting for pods to verify communication be Ready..."
sleep 1
done

# Check the output
for i in {1..60}; do
if kubectl logs udp-receiver | grep -q "Test message"; then
logSuccess "UDP communication is working correctly"
break
elif [[ $i -eq 60 ]]; then
logWarn "Unable to check that Flannel UDP communication is working correctly"
exit 1
fi
echo "Waiting for UDP communication..."
sleep 1
done

echo "Clean up the pods created to do the check"
kubectl delete pod udp-receiver udp-sender
logSuccess "Nodes can communicate with each other successfully"
}

10 changes: 8 additions & 2 deletions addons/flannel/template/base/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ function flannel_check_nodes_connectivity() {
fi
fi

log "Verifying if all nodes can communicate with each other through port 8472/UDP."
logStep "Verifying if all nodes can communicate with each other through port 8472/UDP."
if ! "$DIR"/bin/kurl netutil nodes-connectivity --port 8472 --image "$KURL_UTIL_IMAGE" --proto udp; then
logFail "Flannel requires UDP port 8472 for communication between nodes."
logFail "Please make sure this port is open prior to running this upgrade."
bail "Not migrating from Weave to Flannel"
fi
logSuccess "Nodes can communicate with each other successfully"
}

function flannel_join() {
Expand Down Expand Up @@ -304,7 +305,12 @@ function flannel_already_applied() {
}

function flannel_post_init() {
check_udp_port
logStep "Verifying if all nodes can communicate with each other through port 8472/UDP."
if ! "$DIR"/bin/kurl netutil nodes-connectivity --port 8472 --image "$KURL_UTIL_IMAGE" --proto udp; then
logFail "Flannel requires UDP port 8472 for communication between nodes."
logFail "Unable to check communication between nodes successfully"
fi
logSuccess "Nodes can communicate with each other successfully"
}

function check_udp_port() {
Expand Down

0 comments on commit 7c2f6b2

Please sign in to comment.