Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E: CNI wait and retry #2133

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions test/e2e/pipeline/infra/cluster-api/cni.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ WORKDIR=$(dirname "$FILEPATH")
# shellcheck source=./pre-requirements.sh
source "$WORKDIR/pre-requirements.sh"

# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

DOCKER_PROXY="${DOCKER_PROXY:-docker.io}"

function install_calico() {
Expand Down Expand Up @@ -56,11 +59,17 @@ EOF

function wait_calico() {
local kubeconfig=$1
sleep 5
"${KUBECTL}" wait --for condition=Ready=true -n calico-system pod --all --kubeconfig "$kubeconfig" --timeout=-1s
sleep 10
if ! waitandretry 5s 12 "${KUBECTL} wait --for condition=Ready=true -n calico-system pod --all --kubeconfig $kubeconfig --timeout=-1s"
then
echo "Failed to wait for calico pods to be ready"
exit 1
fi
# set felix to use different port for VXLAN
"${KUBECTL}" patch felixconfiguration default --type='merge' -p '{"spec":{"vxlanPort": 6789}}' --kubeconfig "$kubeconfig"
if ! waitandretry 5s 12 "${KUBECTL} patch felixconfiguration default --type='merge' -p '{\"spec\":{\"vxlanPort\": 6789}}' --kubeconfig $kubeconfig";
then
echo "Failed to patch felixconfiguration"
exit 1
fi
}

function install_cilium() {
Expand Down Expand Up @@ -112,6 +121,9 @@ function install_flannel() {

function wait_flannel() {
local kubeconfig=$1
sleep 15
"${KUBECTL}" wait --for condition=Ready=true -n kube-flannel pod --all --timeout=-1s --kubeconfig "$kubeconfig"
if ! waitandretry 5s 12 "${KUBECTL} wait --for condition=Ready=true -n kube-flannel pod --all --timeout=-1s --kubeconfig $kubeconfig";
then
echo "Failed to wait for flannel pods to be ready"
exit 1
fi
}
37 changes: 37 additions & 0 deletions test/e2e/pipeline/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
#shellcheck disable=SC1091

# Define the retry function
waitandretry() {
local waittime="$1"
local retries="$2"
local command="$3"
local options="$-" # Get the current "set" options

sleep "${waittime}"

echo "Running command: ${command} (retries left: ${retries})"

# Disable set -e
if [[ $options == *e* ]]; then
set +e
fi

# Run the command, and save the exit code
$command
local exit_code=$?

# restore initial options
if [[ $options == *e* ]]; then
set -e
fi

# If the exit code is non-zero (i.e. command failed), and we have not
# reached the maximum number of retries, run the command again
if [[ $exit_code -ne 0 && $retries -gt 0 ]]; then
waitandretry "$waittime" $((retries - 1)) "$command"
else
# Return the exit code from the command
return $exit_code
fi
}