test: add a script to test dns cluster node discovery

This commit is contained in:
Zaiming (Stone) Shi 2022-06-15 23:57:24 +02:00
parent d35b95d00f
commit 67b8e6c3bd
5 changed files with 82 additions and 4 deletions

View File

@ -27,7 +27,7 @@
{jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.5"}}}, {jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.5"}}},
{cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.9.0"}}}, {cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.9.0"}}},
{esockd, {git, "https://github.com/emqx/esockd", {tag, "5.9.3"}}}, {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.9.3"}}},
{ekka, {git, "https://github.com/emqx/ekka", {tag, "0.12.9"}}}, {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.13.0"}}},
{gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.8.1"}}}, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.8.1"}}},
{hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.28.2"}}}, {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.28.2"}}},
{pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {tag, "2.0.4"}}}, {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {tag, "2.0.4"}}},

View File

@ -342,7 +342,7 @@ It is refreshed automatically, as long as the node is alive.
cluster_k8s_address_type { cluster_k8s_address_type {
desc { desc {
en: """Address type used for connecting to the discovered nodes. en: """Address type used for connecting to the discovered nodes.
setting <code>cluster.k8s.address_type</code> to <code>ip</code> will Setting <code>cluster.k8s.address_type</code> to <code>ip</code> will
make EMQX to discover IP addresses of peer nodes from Kubernetes API. make EMQX to discover IP addresses of peer nodes from Kubernetes API.
""" """
zh: """当使用 k8s 方式集群时address_type 用来从 Kubernetes 接口的应答里获取什么形式的 Host 列表。 zh: """当使用 k8s 方式集群时address_type 用来从 Kubernetes 接口的应答里获取什么形式的 Host 列表。

View File

@ -287,7 +287,7 @@ fields(cluster_dns) ->
desc => ?DESC(cluster_dns_name), desc => ?DESC(cluster_dns_name),
'readOnly' => true 'readOnly' => true
} }
)}, )}
]; ];
fields(cluster_etcd) -> fields(cluster_etcd) ->
[ [

View File

@ -22,7 +22,8 @@ if [ "$COMPILE" = '--compile' ]; then
sync sync
fi fi
export DOCKER_BUILDKIT=1 # cannot enable DOCKER_BUILDKIT because the COPY often gets stale layers
#export DOCKER_BUILDKIT=1
docker build --build-arg PROFILE="${PROFILE}" \ docker build --build-arg PROFILE="${PROFILE}" \
-t "emqx/emqx:${PKG_VSN}-${DISTRO}" \ -t "emqx/emqx:${PKG_VSN}-${DISTRO}" \
-f "$EMQX_DOCKERFILE" . -f "$EMQX_DOCKERFILE" .

View File

@ -0,0 +1,77 @@
#!/usr/bin/env bash
## Test two nodes-cluster discover each other using DNS A records lookup result.
set -euo pipefail
cd -P -- "$(dirname -- "$0")/.."
IMAGE="${1}"
NET='test_node_discovery_dns'
NODE1='emqx1'
NODE2='emqx2'
COOKIE='this-is-a-secret'
# cleanup
docker rm -f dnsmasq >/dev/null 2>&1 || true
docker rm -f "$NODE1" >/dev/null 2>&1 || true
docker rm -f "$NODE2" >/dev/null 2>&1 || true
docker network rm "$NET" >/dev/null 2>&1 || true
docker network create --subnet=172.18.0.0/16 $NET
IP0="172.18.0.100"
IP1="172.18.0.101"
IP2="172.18.0.102"
DOMAIN="dnstest.mynet"
# create configs for dnsmasq
cat <<-EOF > "/tmp/dnsmasq.conf"
conf-dir=/etc/dnsmasq,*.conf
addn-hosts=/etc/hosts.$DOMAIN
EOF
cat <<-EOF > "/tmp/hosts.$DOMAIN"
$IP1 $DOMAIN
$IP2 $DOMAIN
EOF
cat <<-EOF > /tmp/dnsmasq.base.conf
domain-needed
bogus-priv
no-hosts
keep-in-foreground
no-resolv
expand-hosts
server=8.8.8.8
EOF
docker run -d -t --name dnsmasq \
--net "$NET" \
--ip "$IP0" \
-v /tmp/dnsmasq.conf:/etc/dnsmasq.conf \
-v "/tmp/hosts.$DOMAIN:/etc/hosts.$DOMAIN" \
-v "/tmp/dnsmasq.base.conf:/etc/dnsmasq/0.base.conf" \
--cap-add=NET_ADMIN \
storytel/dnsmasq dnsmasq --no-daemon --log-queries
start_emqx() {
NAME="$1"
IP="$2"
DASHBOARD_PORT="$3"
docker run -d -t \
--name "$NAME" \
--net "$NET" \
--ip "$IP" \
--dns "$IP0" \
-p "$DASHBOARD_PORT:18083" \
-e EMQX_LOG__CONSOLE_HANDLER__LEVEL=debug \
-e EMQX_NODE_COOKIE="$COOKIE" \
-e EMQX_cluster__discovery_strategy='dns' \
-e EMQX_cluster__dns__name="$DOMAIN" \
"$IMAGE"
}
start_emqx "$NODE1" "$IP1" 18083
start_emqx "$NODE2" "$IP2" 18084