Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
fvt:
name: Build + FVT
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ _deps-linux:
curl -sL https://github.com/kubernetes-sigs/kind/releases/download/v${KIND_VERSION}/kind-linux-amd64 > ${INSTALL_LOCATION}/kind
curl -sL https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl > ${INSTALL_LOCATION}/kubectl
chmod +x ${INSTALL_LOCATION}/operator-sdk ${INSTALL_LOCATION}/kind ${INSTALL_LOCATION}/kubectl
curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b ${INSTALL_LOCATION} v${GOSEC_VERSION}
curl -sSfL https://github.com/securego/gosec/releases/download/v${GOSEC_VERSION}/gosec_${GOSEC_VERSION}_linux_amd64.tar.gz | tar -xz -C ${INSTALL_LOCATION} gosec

_calculate-build-number:
$(eval export CONTAINER_VERSION?=$(GIT_COMMIT_SHA)-$(shell date "+%s"))
Expand Down
50 changes: 50 additions & 0 deletions scripts/fvt-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Wait loop configuration
SLEEP_COUNT=20
SLEEP_WAIT_SECONDS=6
# How long a StaticRoute deletion may take, same as the other wait loops (2 minutes)
DELETE_TIMEOUT_SECONDS=$((SLEEP_COUNT * SLEEP_WAIT_SECONDS))
declare -a NODES

originalPodSecuritySync=""
Expand Down Expand Up @@ -104,6 +106,54 @@ delete_hostnet_pods() {
kubectl delete po --selector fvt-helper=hostnet
}

# Print the operator state and logs
# so a failed run can be diagnosed after the cluster is gone
dump_debug_info() {
fvtlog "Collecting debug info..."
kubectl get nodes -o wide || true
kubectl get pods -A -o wide --selector name=static-route-operator || true
kubectl get staticroute -o yaml || true
local namespaces
namespaces=$(kubectl get pods -A --selector name=static-route-operator -o jsonpath='{.items[*].metadata.namespace}' | tr ' ' '\n' | sort -u) || true
for ns in ${namespaces}; do
fvtlog "Operator logs in namespace ${ns}:"
kubectl logs -n "${ns}" --selector name=static-route-operator --all-containers --prefix --tail=300 || true
done
}

print_remaining_static_routes() {
kubectl get staticroute -o custom-columns='NAME:.metadata.name,FINALIZERS:.metadata.finalizers,NODES IN STATUS:.status.nodeStatus[*].hostname' || true
}

# Delete StaticRoutes and wait until they are gone. Fails if the operator
# does not finish the deletion (remove the finalizer) in time.
# Parameters:
# - StaticRoute names, or --all
delete_static_routes_and_wait() {
if ! kubectl delete staticroute "$@" --timeout="${DELETE_TIMEOUT_SECONDS}s"; then
fvtlog "Failed: StaticRoute deletion did not finish within ${DELETE_TIMEOUT_SECONDS}s, the operator did not remove the finalizer."
print_remaining_static_routes
return 5
fi
}

# Cleanup only: delete the remaining StaticRoutes. If the operator does not
# finish in time, report it as a failure, then remove the finalizers so the
# CRD and the cluster can still be deleted.
force_delete_static_routes() {
if kubectl delete staticroute --all --timeout="${DELETE_TIMEOUT_SECONDS}s" &>/dev/null; then
return 0
fi
fvtlog "Failed: StaticRoutes were not deleted within ${DELETE_TIMEOUT_SECONDS}s, the operator did not remove their finalizers:"
print_remaining_static_routes
fvtlog "Removing the finalizers so the cleanup can finish"
local sr
for sr in $(kubectl get staticroute -o name); do
kubectl patch "${sr}" --type=merge -p '{"metadata":{"finalizers":null}}' || true
done
return 1
}

# Function to execute a command on the host network of a node, selected by a pod that is running on it
# Parameters:
# - Node name
Expand Down
31 changes: 21 additions & 10 deletions scripts/run-fvt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ IMAGEPULLSECRET="${IMAGEPULLSECRET:-}"
. "${SCRIPT_PATH}/fvt-tools.sh"

cleanup() {
fvtlog "Running cleanup, error code $?"
local exit_code=$?
fvtlog "Running cleanup, error code ${exit_code}"
if [[ ${exit_code} -ne 0 ]]; then
dump_debug_info
fi
delete_hostnet_pods
local deletion_stuck=false
if [[ "${KEEP_ENV}" == "false" ]]; then
kubectl delete staticroute --all &>/dev/null
if ! force_delete_static_routes; then
deletion_stuck=true
fi
if [[ "${SKIP_OPERATOR_INSTALL}" == "false" ]]; then
manage_common_operator_resources "delete"
fi
Expand All @@ -28,6 +35,10 @@ cleanup() {
rm -rf "${SCRIPT_PATH}"/kubeconfig.yaml
fi
fi

if [[ ${exit_code} -eq 0 && ${deletion_stuck} == true ]]; then
exit 1
fi
}

trap cleanup EXIT
Expand Down Expand Up @@ -63,7 +74,7 @@ update_node_list
create_hostnet_pods

# Delete all the static routes before the test
kubectl delete staticroute --all &>/dev/null
delete_static_routes_and_wait --all

# Restore default labels on nodes
label_nodes_with_default "zone01"
Expand Down Expand Up @@ -185,13 +196,13 @@ fi
update_node_list
fvtlog "Test static-route deletion - routes must be deleted"
if [[ ${PROVIDER} == "kind" ]]; then
kubectl delete staticroute example-static-route-simple
delete_static_routes_and_wait example-static-route-simple
check_route_on_nodes "192.168.0.0/24 via ${GW}" "all" "default" "negative"
kubectl delete staticroute example-static-route-with-gateway
delete_static_routes_and_wait example-static-route-with-gateway
check_route_on_nodes "192.168.1.0/24 via ${GW}" "all" "default" "negative"
fi

kubectl delete staticroute example-static-route-with-selector
delete_static_routes_and_wait example-static-route-with-selector
check_route_on_nodes "192.168.2.0/24 via ${GW}" "all" "default" "negative"

fvtlog "Test wrong gateway configuration"
Expand All @@ -206,7 +217,7 @@ spec:
EOF
check_static_route_crd_status "example-static-route-with-wrong-gateway" "all_nodes_shall_post_status" "given gateway IP is not directly routable, cannot setup the route"
check_route_on_nodes "192.168.0.0/24 via 1.2.3.4" "all" "default" "negative"
kubectl delete staticroute example-static-route-with-wrong-gateway
delete_static_routes_and_wait example-static-route-with-wrong-gateway

if [[ "${PROVIDER}" == "kind" ]]; then
fvtlog "Test subnet protection (KinD)"
Expand Down Expand Up @@ -255,7 +266,7 @@ EOF
check_static_route_crd_status "example-static-route-protected-subnet2" "all_nodes_shall_post_status" "given subnet overlaps with some protected subnet"
check_route_on_nodes "${SUBNET1} via ${GW}" "all" "default" "negative"
check_route_on_nodes "${SUBNET2} via ${GW}" "all" "default" "negative"
kubectl delete staticroute example-static-route-protected-subnet1 example-static-route-protected-subnet2
delete_static_routes_and_wait example-static-route-protected-subnet1 example-static-route-protected-subnet2
fi

if [[ ${PROVIDER} == "kind" ]]; then
Expand All @@ -277,7 +288,7 @@ spec:
EOF
check_static_route_crd_status "example-static-route-no-match" "nodes_shall_not_post_status"
check_route_on_nodes "192.168.0.0/24 via ${GW}" "all" "default" "negative"
kubectl delete staticroute example-static-route-no-match
delete_static_routes_and_wait example-static-route-no-match
fi

if [[ ${PROVIDER} == "kind" ]]; then
Expand All @@ -294,7 +305,7 @@ spec:
EOF
check_static_route_crd_status "example-static-route-different-table"
check_route_on_nodes "192.168.0.0/24 via ${GW}" "all" "30"
kubectl delete staticroute example-static-route-different-table
delete_static_routes_and_wait example-static-route-different-table
fi

fvtlog "All tests passed!"
Loading