Skip to content

Commit 5a6b4dc

Browse files
authored
Tests: dualstack improvements (knative#2919)
* Make patch-hosts ip version aware Add A and AAAA records for localtest.me depending on whether the control plane node has IPv4 and/or IPv6 address. Signed-off-by: Matej Vašek <[email protected]> * Make test locabalancer ip version aware Set MetalLB address pool appropriately with respect to IPv4 and IPv6 Signed-off-by: Matej Vašek <[email protected]> --------- Signed-off-by: Matej Vašek <[email protected]>
1 parent e3759ec commit 5a6b4dc

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

hack/allocate.sh

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ dns() {
128128
echo "${green}✅ DNS${reset}"
129129
}
130130

131+
arr2yaml() {
132+
echo -n '['
133+
local e
134+
local s=""
135+
for e in "$@"; do
136+
printf '%s"%s"' "$s" "$e";
137+
s=", "
138+
done
139+
echo -n ']'
140+
}
141+
131142
loadbalancer() {
132143
echo "${blue}Installing Load Balancer (Metallb)${reset}"
133144
$KUBECTL apply -f "https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml"
@@ -138,7 +149,22 @@ loadbalancer() {
138149
--timeout=300s
139150

140151
local kind_addr
152+
local kind_addr6
153+
local addr_array
154+
141155
kind_addr="$($CONTAINER_ENGINE container inspect func-control-plane | jq '.[0].NetworkSettings.Networks.kind.IPAddress' -r)"
156+
kind_addr6="$($CONTAINER_ENGINE container inspect func-control-plane | jq '.[0].NetworkSettings.Networks.kind.GlobalIPv6Address' -r)"
157+
158+
addr_array=()
159+
160+
if [[ -n "$kind_addr" ]]; then
161+
addr_array+=("$kind_addr/32");
162+
fi
163+
164+
if [[ -n "$kind_addr6" ]]; then
165+
addr_array+=("$kind_addr6/128");
166+
fi
167+
142168

143169
echo "Setting up address pool."
144170
$KUBECTL apply -f - <<EOF
@@ -148,8 +174,7 @@ metadata:
148174
name: example
149175
namespace: metallb-system
150176
spec:
151-
addresses:
152-
- ${kind_addr}-${kind_addr}
177+
addresses: $(arr2yaml "${addr_array[@]}")
153178
---
154179
apiVersion: metallb.io/v1beta1
155180
kind: L2Advertisement

hack/patch-hosts.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,34 @@ function patch_hosts() {
2222
echo "${blue}Configuring Magic DNS${reset}"
2323

2424
local cluster_node_addr
25+
local cluster_node_addr6
2526

2627
cluster_node_addr="$(docker container inspect func-control-plane | jq ".[0].NetworkSettings.Networks.kind.IPAddress" -r)"
28+
cluster_node_addr6="$(docker container inspect func-control-plane | jq ".[0].NetworkSettings.Networks.kind.GlobalIPv6Address" -r)"
29+
30+
local a_recs=""
31+
local aaaa_recs=""
32+
33+
if [[ -n $cluster_node_addr ]]; then
34+
a_recs="\
35+
localtest.me. IN A ${cluster_node_addr}\n\
36+
*.localtest.me. IN A ${cluster_node_addr}\n";
37+
fi
38+
39+
if [[ -n $cluster_node_addr6 ]]; then
40+
aaaa_recs="\
41+
localtest.me. IN AAAA ${cluster_node_addr6}\n\
42+
*.localtest.me. IN AAAA ${cluster_node_addr6}\n";
43+
fi
2744

2845
$KUBECTL patch cm/coredns -n kube-system --patch-file /dev/stdin <<EOF
2946
{
3047
"data": {
3148
"Corefile": ".:53 {\n errors\n health {\n lameduck 5s\n }\n ready\n kubernetes cluster.local in-addr.arpa ip6.arpa {\n pods insecure\n fallthrough in-addr.arpa ip6.arpa\n ttl 30\n }\n file /etc/coredns/example.db localtest.me\n prometheus :9153\n forward . /etc/resolv.conf {\n max_concurrent 1000\n }\n cache 30\n loop\n reload\n loadbalance\n}\n",
32-
"example.db": "; localtest.me test file\nlocaltest.me. IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600\nlocaltest.me. IN A ${cluster_node_addr}\n*.localtest.me. IN A ${cluster_node_addr}\n"
49+
"example.db": "; localtest.me test file\n\
50+
localtest.me. IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600\n\
51+
$a_recs\
52+
$aaaa_recs"
3353
}
3454
}
3555
EOF

0 commit comments

Comments
 (0)