@@ -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,33 @@ function delete_vlan_subnets {
318
331
docker_run_with_host_net ip link del $interface_name
319
332
fi
320
333
done
334
+
335
+ 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
336
+ 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
321
337
}
322
338
323
- function delete_networks {
324
- networks=$( docker network ls -f name=antrea --format ' {{.Name}}' )
325
- networks=" $( echo $networks ) "
326
- if [[ ! -z $networks ]]; then
339
+ function delete_network_by_filter {
340
+ local filter=" $1 " # Filter passed as a parameter
341
+ local networks
342
+ networks=$( docker network ls -f name=" $filter " --format ' {{.Name}}' )
343
+
344
+ if [[ -n $networks ]]; then
327
345
docker network rm $networks > /dev/null 2>&1
328
- echo " deleted networks $networks "
346
+ echo " Deleted networks: $networks "
329
347
fi
330
348
}
331
349
350
+ function delete_networks {
351
+ local filters=(" antrea" " kind" ) # Define network filters to process
352
+
353
+ for filter in " ${filters[@]} " ; do
354
+ if [[ $filter == " kind" && $FLEXIBLE_IPAM != true ]]; then
355
+ continue
356
+ fi
357
+ delete_network_by_filter " $filter "
358
+ done
359
+ }
360
+
332
361
function load_images {
333
362
echo " load images"
334
363
set +e
@@ -711,7 +740,6 @@ if [[ $ACTION == "destroy" ]]; then
711
740
exit
712
741
fi
713
742
714
-
715
743
kind_version=$( kind version | awk ' {print $2}' )
716
744
kind_version=${kind_version: 1} # strip leading 'v'
717
745
function version_lt() { test " $( printf ' %s\n' " $@ " | sort -rV | head -n 1) " ! = " $1 " ; }
@@ -728,5 +756,10 @@ if [[ $ACTION == "create" ]]; then
728
756
echoerr " Only one of '--subnets' and '--extra-networks' can be specified"
729
757
exit 1
730
758
fi
759
+
760
+ # Reserve IPs after 192.168.240.63 for e2e tests.
761
+ if [[ $FLEXIBLE_IPAM == true ]]; then
762
+ docker network create -d bridge --subnet 192.168.240.0/24 --gateway 192.168.240.1 --ip-range 192.168.240.0/26 kind
763
+ fi
731
764
create
732
765
fi
0 commit comments