@@ -300,6 +300,19 @@ function configure_vlan_subnets {
300
300
docker_run_with_host_net iptables -t filter -A FORWARD -i ${vlan_interfaces[j]} -o ${vlan_interfaces[i]} -j ACCEPT
301
301
done
302
302
done
303
+
304
+ # With FlexibleIPAM, Antrea SNAT is disabled (noSNAT: true) so Pods don't have access to the external network by default (including regular / NodeIPAM Pods).
305
+ # With our configuration, Docker will already perform SNAT for FlexibleIPAM Pods. However, we need a custom SNAT rule for regular Pods.
306
+ if [[ $FLEXIBLE_IPAM == true ]]; then
307
+ docker_run_with_host_net ipset create excluded_subnets hash:net
308
+ docker_run_with_host_net ipset add excluded_subnets 192.168.241.0/24
309
+ docker_run_with_host_net ipset add excluded_subnets 192.168.242.0/24
310
+ docker_run_with_host_net ipset add excluded_subnets 192.168.240.0/24
311
+ docker_run_with_host_net ipset list excluded_subnets
312
+
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
+ 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
315
+ fi
303
316
}
304
317
305
318
function delete_vlan_subnets {
@@ -318,17 +331,35 @@ function delete_vlan_subnets {
318
331
docker_run_with_host_net ip link del $interface_name
319
332
fi
320
333
done
334
+
335
+ if [[ $FLEXIBLE_IPAM == true ]]; then
336
+ 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
337
+ 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
338
+ fi
321
339
}
322
340
323
- function delete_networks {
324
- networks=$( docker network ls -f name=antrea --format ' {{.Name}}' )
325
- networks=" $( echo $networks ) "
326
- if [[ ! -z $networks ]]; then
341
+ function delete_network_by_filter {
342
+ local filter=" $1 " # Filter passed as a parameter
343
+ local networks
344
+ networks=$( docker network ls -f name=" $filter " --format ' {{.Name}}' )
345
+
346
+ if [[ -n $networks ]]; then
327
347
docker network rm $networks > /dev/null 2>&1
328
- echo " deleted networks $networks "
348
+ echo " Deleted networks: $networks "
329
349
fi
330
350
}
331
351
352
+ function delete_networks {
353
+ local filters=(" antrea" " kind" ) # Define network filters to process
354
+
355
+ for filter in " ${filters[@]} " ; do
356
+ if [[ $filter == " kind" && $FLEXIBLE_IPAM != true ]]; then
357
+ continue
358
+ fi
359
+ delete_network_by_filter " $filter "
360
+ done
361
+ }
362
+
332
363
function load_images {
333
364
echo " load images"
334
365
set +e
@@ -711,7 +742,6 @@ if [[ $ACTION == "destroy" ]]; then
711
742
exit
712
743
fi
713
744
714
-
715
745
kind_version=$( kind version | awk ' {print $2}' )
716
746
kind_version=${kind_version: 1} # strip leading 'v'
717
747
function version_lt() { test " $( printf ' %s\n' " $@ " | sort -rV | head -n 1) " ! = " $1 " ; }
@@ -728,5 +758,10 @@ if [[ $ACTION == "create" ]]; then
728
758
echoerr " Only one of '--subnets' and '--extra-networks' can be specified"
729
759
exit 1
730
760
fi
761
+
762
+ # Reserve IPs after 192.168.240.63 for e2e tests.
763
+ if [[ $FLEXIBLE_IPAM == true ]]; then
764
+ docker network create -d bridge --subnet 192.168.240.0/24 --gateway 192.168.240.1 --ip-range 192.168.240.0/26 kind
765
+ fi
731
766
create
732
767
fi
0 commit comments