@@ -269,13 +269,15 @@ function configure_vlan_subnets {
269
269
270
270
bridge_id=$( docker network inspect kind -f {{.ID}})
271
271
bridge_interface=" br-${bridge_id: 0: 12} "
272
-
272
+
273
+ vlan_interfaces=()
273
274
for vlan_subnet in " ${VLAN_SUBNETS[@]} " ; do
274
275
# Extract VLAN ID and subnets
275
276
vlan_id=$( echo $vlan_subnet | cut -d= -f1)
276
277
subnets=$( echo $vlan_subnet | cut -d= -f2)
277
278
278
279
vlan_interface=" br-${bridge_id: 0: 7} .$vlan_id "
280
+ vlan_interfaces+=(" $vlan_interface " )
279
281
280
282
docker_run_with_host_net ip link add link $bridge_interface name $vlan_interface type vlan id $vlan_id
281
283
docker_run_with_host_net ip link set $vlan_interface up
@@ -287,7 +289,16 @@ function configure_vlan_subnets {
287
289
done
288
290
289
291
docker_run_with_host_net iptables -t filter -A FORWARD -i $bridge_interface -o $vlan_interface -j ACCEPT
290
- docker_run_with_host_net iptables -t filter -A FORWARD -o $bridge_interface -i $vlan_interface -j ACCEPT
292
+ docker_run_with_host_net iptables -t filter -A FORWARD -i $vlan_interface -o $bridge_interface -j ACCEPT
293
+ docker_run_with_host_net iptables -t filter -A FORWARD -i $vlan_interface -o $vlan_interface -j ACCEPT
294
+ done
295
+
296
+ # Allow traffic between VLANs
297
+ for (( i= 0 ; i< ${# vlan_interfaces[@]} ; i++ )) ; do
298
+ for (( j= i+ 1 ; j< ${# vlan_interfaces[@]} ; j++ )) ; do
299
+ docker_run_with_host_net iptables -t filter -A FORWARD -i ${vlan_interfaces[i]} -o ${vlan_interfaces[j]} -j ACCEPT
300
+ docker_run_with_host_net iptables -t filter -A FORWARD -i ${vlan_interfaces[j]} -o ${vlan_interfaces[i]} -j ACCEPT
301
+ done
291
302
done
292
303
293
304
if [[ $FLEXIBLE_IPAM == true ]]; then
@@ -393,7 +404,7 @@ function create {
393
404
fi
394
405
395
406
set +e
396
- kind get clusters | grep $CLUSTER_NAME > /dev/null 2>&1
407
+ kind get clusters | grep -x " $CLUSTER_NAME " > /dev/null 2>&1
397
408
if [[ $? -eq 0 ]]; then
398
409
echoerr " cluster $CLUSTER_NAME already created"
399
410
exit 0
447
458
fi
448
459
IMAGE_OPT=" --image kindest/node:${K8S_VERSION} "
449
460
fi
461
+
462
+ flock ~ /.antrea/.clusters.lock --command " echo \" $CLUSTER_NAME $( date +%s) \" >> ~/.antrea/.clusters"
463
+ rm -rf ~ /.antrea/.clusters.lock
450
464
kind create cluster --name $CLUSTER_NAME --config $config_file $IMAGE_OPT
451
465
452
466
# force coredns to run on control-plane node because it
497
511
function destroy {
498
512
update_kind_ipam_routes " del"
499
513
if [[ $UNTIL_TIME_IN_MINS != " " ]]; then
500
- clean_kind
514
+ if [[ -e ~ /.antrea/.clusters ]]; then
515
+ clean_kind
516
+ fi
501
517
else
502
518
kind delete cluster --name $CLUSTER_NAME
503
519
fi
@@ -545,19 +561,29 @@ function destroy_external_servers {
545
561
546
562
function clean_kind {
547
563
echo " === Cleaning up stale kind clusters ==="
548
- read -a all_kind_clusters <<< $( kind get clusters)
549
- for kind_cluster_name in " ${all_kind_clusters[@]} " ; do
550
- creationTimestamp=$( kubectl get nodes --context kind-$kind_cluster_name -o json -l node-role.kubernetes.io/control-plane | \
551
- jq -r ' .items[0].metadata.creationTimestamp' )
552
- creation=$( printUnixTimestamp " $creationTimestamp " )
553
- now=$( date -u ' +%s' )
554
- diff=$(( now- creation))
555
- timeout=$(( $UNTIL_TIME_IN_MINS * 60 ))
556
- if [[ $diff -gt $timeout ]]; then
557
- echo " === kind ${kind_cluster_name} present from more than $UNTIL_TIME_IN_MINS minutes ==="
558
- kind delete cluster --name $kind_cluster_name
559
- fi
560
- done
564
+ (
565
+ flock -x 200
566
+
567
+ current_timestamp=$( date +%s)
568
+ > ~ /.antrea/.clusters.swp
569
+ while IFS=' ' read -r name creationTimestamp; do
570
+ if [[ -z " $name " || -z " $creationTimestamp " ]]; then
571
+ continue
572
+ fi
573
+ # Calculate the time difference
574
+ time_difference=$(( current_timestamp - creationTimestamp))
575
+ # Check if the creation happened more than 1 hour ago (3600 seconds)
576
+ if (( time_difference > 3600 )) ; then
577
+ echo " The creation of $name happened more than 1 hour ago."
578
+ kind delete cluster --name " $name " || echo " Cluster could not be deleted"
579
+ else
580
+ echo " The creation of $name happened within the last hour."
581
+ echo " $name $creationTimestamp " >> ~ /.antrea/.clusters.swp
582
+ fi
583
+ done < ~ /.antrea/.clusters
584
+ mv ~ /.antrea/.clusters.swp ~ /.antrea/.clusters
585
+ ) 200>> ~/.antrea/.clusters.lock
586
+ rm -rf ~ /.antrea/.clusters.lock
561
587
}
562
588
563
589
if ! command -v kind & > /dev/null
566
592
exit 1
567
593
fi
568
594
595
+ mkdir -p ~ /.antrea
596
+
569
597
while [[ $# -gt 0 ]]
570
598
do
571
599
key=" $1 "
0 commit comments