Skip to content

Commit 1f2cf4a

Browse files
authored
Add a new Github workflow to validate FlexibleIPAM (#6879)
The workflow is using the runners provided by the CNCF through the Github Enterprise plan (`ubuntu-latest-4-cores`). Signed-off-by: KMAnju-2021 <[email protected]>
1 parent a265cc3 commit 1f2cf4a

File tree

4 files changed

+122
-8
lines changed

4 files changed

+122
-8
lines changed

.github/workflows/kind.yml

+63
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,69 @@ jobs:
277277
path: log.tar.gz
278278
retention-days: 30
279279

280+
test-e2e-ipam-feature-enabled:
281+
name: E2e tests on a Kind cluster on Linux with FlexibleIPAM feature enabled
282+
needs: [build-antrea-coverage-image]
283+
runs-on: [ubuntu-latest-4-cores]
284+
steps:
285+
- uses: actions/checkout@v4
286+
with:
287+
show-progress: false
288+
- uses: actions/setup-go@v5
289+
with:
290+
go-version-file: 'go.mod'
291+
- name: Download Antrea image from previous job
292+
uses: actions/download-artifact@v4
293+
with:
294+
name: antrea-ubuntu-cov
295+
- name: Load Antrea image
296+
run: |
297+
docker load -i antrea-ubuntu.tar
298+
- name: Install Kind
299+
run: |
300+
KIND_VERSION=$(head -n1 ./ci/kind/version)
301+
curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64
302+
chmod +x ./kind
303+
sudo mv kind /usr/local/bin
304+
- name: Run ipam e2e tests
305+
# We enable multicast as some FlexibleIPAM e2e tests require it
306+
run: |
307+
mkdir log
308+
mkdir test-ipam-e2e-coverage
309+
ANTREA_LOG_DIR=$PWD/log ANTREA_COV_DIR=$PWD/test-ipam-e2e-coverage ./ci/kind/test-e2e-kind.sh \
310+
--encap-mode noEncap \
311+
--coverage \
312+
--multicast \
313+
--flexible-ipam \
314+
- name: Tar coverage files
315+
run: tar -czf test-ipam-e2e-coverage.tar.gz test-ipam-e2e-coverage
316+
- name: Upload coverage for test-ipam-e2e-coverage
317+
uses: actions/upload-artifact@v4
318+
with:
319+
name: test-ipam-e2e-coverage
320+
path: test-ipam-e2e-coverage.tar.gz
321+
retention-days: 30
322+
- name: Codecov
323+
uses: codecov/codecov-action@v5
324+
with:
325+
token: ${{ secrets.CODECOV_TOKEN }}
326+
files: '*.cov.out*'
327+
disable_search: true
328+
flags: kind-e2e-tests
329+
name: test-ipam-e2e-coverage
330+
directory: test-ipam-e2e-coverage
331+
fail_ci_if_error: ${{ github.event_name == 'push' }}
332+
- name: Tar log files
333+
if: ${{ failure() }}
334+
run: tar -czf log.tar.gz log
335+
- name: Upload test log
336+
uses: actions/upload-artifact@v4
337+
if: ${{ failure() }}
338+
with:
339+
name: e2e-kind-ipam-features-enabled.tar.gz
340+
path: log.tar.gz
341+
retention-days: 30
342+
280343
test-e2e-noencap:
281344
name: E2e tests on a Kind cluster on Linux (noEncap)
282345
needs: [build-antrea-coverage-image]

ci/kind/kind-setup.sh

+38-6
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,22 @@ function configure_vlan_subnets {
300300
docker_run_with_host_net iptables -t filter -A FORWARD -i ${vlan_interfaces[j]} -o ${vlan_interfaces[i]} -j ACCEPT
301301
done
302302
done
303+
304+
if [[ $FLEXIBLE_IPAM == true ]]; then
305+
docker_run_with_host_net ipset create excluded_subnets hash:net
306+
docker_run_with_host_net ipset add excluded_subnets 192.168.241.0/24
307+
docker_run_with_host_net ipset add excluded_subnets 192.168.242.0/24
308+
docker_run_with_host_net ipset add excluded_subnets 192.168.240.0/24
309+
docker_run_with_host_net ipset list excluded_subnets
310+
311+
# Bypass default Docker SNAT rule for FlexibleIPAM traffic from the untagged subnet (192.168.240.0/24, which is the subnet for the Docker bridge network)
312+
# and destined to the VLAN subnets (192.168.241.0/24, 192.168.242.0/24).
313+
docker_run_with_host_net iptables -t nat -I POSTROUTING 1 ! -o $bridge_interface -s 192.168.240.0/24 -m set --match-set excluded_subnets dst -j RETURN
314+
315+
# With FlexibleIPAM, Antrea SNAT is disabled (noSNAT: true) so Pods don't have access to the external network by default (including regular / NodeIPAM Pods).
316+
# Our e2e tests require external network access for regular Pods, so we need to add a custom SNAT rule.
317+
docker_run_with_host_net iptables -t nat -A POSTROUTING ! -o $bridge_interface -s 10.244.0.0/16 -m set ! --match-set excluded_subnets dst -j MASQUERADE
318+
fi
303319
}
304320

305321
function delete_vlan_subnets {
@@ -318,17 +334,29 @@ function delete_vlan_subnets {
318334
docker_run_with_host_net ip link del $interface_name
319335
fi
320336
done
337+
338+
if [[ $FLEXIBLE_IPAM == true ]]; then
339+
docker_run_with_host_net iptables -t nat -D POSTROUTING ! -o $bridge_interface -s 192.168.240.0/24 -m set --match-set excluded_subnets dst -j RETURN || true
340+
docker_run_with_host_net iptables -t nat -D POSTROUTING ! -o $bridge_interface -s 10.244.0.0/16 -m set ! --match-set excluded_subnets dst -j MASQUERADE || true
341+
docker_run_with_host_net ipset destroy excluded_subnets || true
342+
fi
321343
}
322344

323-
function delete_networks {
324-
networks=$(docker network ls -f name=antrea --format '{{.Name}}')
325-
networks="$(echo $networks)"
326-
if [[ ! -z $networks ]]; then
345+
function delete_network_by_filter {
346+
local networks=$(docker network ls -f name="$1" --format '{{.Name}}')
347+
if [[ -n $networks ]]; then
327348
docker network rm $networks > /dev/null 2>&1
328-
echo "deleted networks $networks"
349+
echo "Deleted networks: $networks"
329350
fi
330351
}
331352

353+
function delete_networks {
354+
if [[ $FLEXIBLE_IPAM == true ]]; then
355+
delete_network_by_filter "kind"
356+
fi
357+
delete_network_by_filter "antrea"
358+
}
359+
332360
function load_images {
333361
echo "load images"
334362
set +e
@@ -711,7 +739,6 @@ if [[ $ACTION == "destroy" ]]; then
711739
exit
712740
fi
713741

714-
715742
kind_version=$(kind version | awk '{print $2}')
716743
kind_version=${kind_version:1} # strip leading 'v'
717744
function version_lt() { test "$(printf '%s\n' "$@" | sort -rV | head -n 1)" != "$1"; }
@@ -728,5 +755,10 @@ if [[ $ACTION == "create" ]]; then
728755
echoerr "Only one of '--subnets' and '--extra-networks' can be specified"
729756
exit 1
730757
fi
758+
759+
# Reserve IPs after 192.168.240.63 for e2e tests.
760+
if [[ $FLEXIBLE_IPAM == true ]]; then
761+
docker network create -d bridge --subnet 192.168.240.0/24 --gateway 192.168.240.1 --ip-range 192.168.240.0/26 kind
762+
fi
731763
create
732764
fi

ci/kind/test-e2e-kind.sh

+20-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ setup_only=false
8989
cleanup_only=false
9090
test_only=false
9191
run=""
92+
flexible_ipam=false
9293
antrea_controller_image="antrea/antrea-controller-ubuntu"
9394
antrea_agent_image="antrea/antrea-agent-ubuntu"
9495
use_non_default_images=false
@@ -110,6 +111,10 @@ case $key in
110111
proxy_all=true
111112
shift
112113
;;
114+
--flexible-ipam)
115+
flexible_ipam=true
116+
shift
117+
;;
113118
--no-kube-proxy)
114119
no_kube_proxy=true
115120
shift
@@ -248,6 +253,9 @@ fi
248253
if $flow_visibility; then
249254
manifest_args="$manifest_args --feature-gates FlowExporter=true,L7FlowExporter=true --extra-helm-values-file $FLOW_VISIBILITY_HELM_VALUES"
250255
fi
256+
if $flexible_ipam; then
257+
manifest_args="$manifest_args --flexible-ipam"
258+
fi
251259

252260
COMMON_IMAGES_LIST=("registry.k8s.io/e2e-test-images/agnhost:2.40" \
253261
"antrea/nginx:1.21.6-alpine" \
@@ -302,6 +310,10 @@ if $extra_vlan; then
302310
fi
303311
fi
304312

313+
if $flexible_ipam; then
314+
vlan_args="$vlan_args --vlan-subnets 11=192.168.241.1/24 --vlan-subnets 12=192.168.242.1/24"
315+
fi
316+
305317
function setup_cluster {
306318
args=$1
307319

@@ -328,7 +340,9 @@ function setup_cluster {
328340
if $bgp_policy; then
329341
args="$args --deploy-external-frr"
330342
fi
331-
343+
if $flexible_ipam; then
344+
args="$args --flexible-ipam"
345+
fi
332346
echo "creating test bed with args $args"
333347
eval "timeout 600 $TESTBED_CMD create kind $args"
334348
}
@@ -401,6 +415,11 @@ function run_test {
401415
EXTRA_ARGS="$EXTRA_ARGS --external-frr-cid $external_frr_cid --external-frr-ips $external_frr_ips"
402416
fi
403417

418+
if $flexible_ipam; then
419+
EXTRA_ARGS="$EXTRA_ARGS --antrea-ipam"
420+
timeout="100m"
421+
fi
422+
404423
go test -v -timeout=$timeout $RUN_OPT antrea.io/antrea/test/e2e $flow_visibility_args -provider=kind --logs-export-dir=$ANTREA_LOG_DIR $np_evaluation_flag --skip-cases=$skiplist $coverage_args $EXTRA_ARGS
405424

406425
if $coverage; then

test/e2e/antreapolicy_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5468,7 +5468,7 @@ func createPolicyForFQDNCacheMinTTL(t *testing.T, data *TestData, testFQDN strin
54685468

54695469
annp, err := data.CreateOrUpdateANNP(builder.Get())
54705470
require.NoError(t, err, "error while deploying Antrea policy")
5471-
require.NoError(t, data.waitForANNPRealized(t, annp.Namespace, annp.Name, 10*time.Second))
5471+
require.NoError(t, data.waitForANNPRealized(t, annp.Namespace, annp.Name, 30*time.Second))
54725472
}
54735473

54745474
// createHttpAgnhostPod creates an agnhost Pod that serves HTTP requests and returns the IP of Pod created.

0 commit comments

Comments
 (0)