Skip to content

Commit 834b155

Browse files
committed
Fix issues in cherry-pick of antrea-io#6879
1 parent e101ced commit 834b155

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

ci/kind/kind-setup.sh

+45-17
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,15 @@ function configure_vlan_subnets {
269269

270270
bridge_id=$(docker network inspect kind -f {{.ID}})
271271
bridge_interface="br-${bridge_id:0:12}"
272-
272+
273+
vlan_interfaces=()
273274
for vlan_subnet in "${VLAN_SUBNETS[@]}"; do
274275
# Extract VLAN ID and subnets
275276
vlan_id=$(echo $vlan_subnet | cut -d= -f1)
276277
subnets=$(echo $vlan_subnet | cut -d= -f2)
277278

278279
vlan_interface="br-${bridge_id:0:7}.$vlan_id"
280+
vlan_interfaces+=("$vlan_interface")
279281

280282
docker_run_with_host_net ip link add link $bridge_interface name $vlan_interface type vlan id $vlan_id
281283
docker_run_with_host_net ip link set $vlan_interface up
@@ -287,7 +289,16 @@ function configure_vlan_subnets {
287289
done
288290

289291
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
291302
done
292303

293304
if [[ $FLEXIBLE_IPAM == true ]]; then
@@ -393,7 +404,7 @@ function create {
393404
fi
394405

395406
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
397408
if [[ $? -eq 0 ]]; then
398409
echoerr "cluster $CLUSTER_NAME already created"
399410
exit 0
@@ -447,6 +458,9 @@ EOF
447458
fi
448459
IMAGE_OPT="--image kindest/node:${K8S_VERSION}"
449460
fi
461+
462+
flock ~/.antrea/.clusters.lock --command "echo \"$CLUSTER_NAME $(date +%s)\" >> ~/.antrea/.clusters"
463+
rm -rf ~/.antrea/.clusters.lock
450464
kind create cluster --name $CLUSTER_NAME --config $config_file $IMAGE_OPT
451465

452466
# force coredns to run on control-plane node because it
@@ -497,7 +511,9 @@ EOF
497511
function destroy {
498512
update_kind_ipam_routes "del"
499513
if [[ $UNTIL_TIME_IN_MINS != "" ]]; then
500-
clean_kind
514+
if [[ -e ~/.antrea/.clusters ]]; then
515+
clean_kind
516+
fi
501517
else
502518
kind delete cluster --name $CLUSTER_NAME
503519
fi
@@ -545,19 +561,29 @@ function destroy_external_servers {
545561

546562
function clean_kind {
547563
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
561587
}
562588

563589
if ! command -v kind &> /dev/null
@@ -566,6 +592,8 @@ then
566592
exit 1
567593
fi
568594

595+
mkdir -p ~/.antrea
596+
569597
while [[ $# -gt 0 ]]
570598
do
571599
key="$1"

test/e2e/antreapolicy_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package e2e
1616

1717
import (
18+
"bytes"
1819
"context"
1920
"encoding/json"
2021
"fmt"
@@ -24,6 +25,7 @@ import (
2425
"strings"
2526
"sync"
2627
"testing"
28+
"text/template"
2729
"time"
2830

2931
log "github.com/sirupsen/logrus"
@@ -35,9 +37,11 @@ import (
3537
"k8s.io/apimachinery/pkg/util/intstr"
3638
"k8s.io/apimachinery/pkg/util/sets"
3739
"k8s.io/apimachinery/pkg/util/wait"
40+
"k8s.io/utils/ptr"
3841

3942
"antrea.io/antrea/pkg/agent/apis"
4043
crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1"
44+
agentconfig "antrea.io/antrea/pkg/config/agent"
4145
"antrea.io/antrea/pkg/controller/networkpolicy"
4246
"antrea.io/antrea/pkg/features"
4347
. "antrea.io/antrea/test/e2e/utils"

0 commit comments

Comments
 (0)