Procházet zdrojové kódy

feat: add dns.record_type config for cluster discovery

Zaiming (Stone) Shi před 3 roky
rodič
revize
7d49d1ee5c

+ 11 - 0
apps/emqx_conf/i18n/emqx_conf_schema.conf

@@ -258,6 +258,17 @@ Applicable when <code>cluster.discovery_strategy = dns</code>
     }
   }
 
+  cluster_dns_record_type {
+    desc {
+      en: """DNS record type. """
+      zh: """DNS 记录类型。"""
+    }
+    label {
+      en: "DNS Record Type"
+      zh: "DNS记录类型"
+    }
+  }
+
   cluster_etcd_server {
     desc {
       en: """List of endpoint URLs of the etcd cluster"""

+ 18 - 8
apps/emqx_conf/src/emqx_conf_schema.erl

@@ -287,6 +287,15 @@ fields(cluster_dns) ->
                     desc => ?DESC(cluster_dns_name),
                     'readOnly' => true
                 }
+            )},
+        {"record_type",
+            sc(
+                hoconsc:enum([a, srv]),
+                #{
+                    default => a,
+                    desc => ?DESC(cluster_dns_record_type),
+                    'readOnly' => true
+                }
             )}
     ];
 fields(cluster_etcd) ->
@@ -1009,7 +1018,7 @@ tr_override_conf_file(Conf, Filename) ->
 
 tr_cluster_discovery(Conf) ->
     Strategy = conf_get("cluster.discovery_strategy", Conf),
-    {Strategy, filter(options(Strategy, Conf))}.
+    {Strategy, filter(cluster_options(Strategy, Conf))}.
 
 -spec tr_logger_level(hocon:config()) -> logger:level().
 tr_logger_level(Conf) ->
@@ -1267,9 +1276,9 @@ sc(Type, Meta) -> hoconsc:mk(Type, Meta).
 
 map(Name, Type) -> hoconsc:map(Name, Type).
 
-options(static, Conf) ->
+cluster_options(static, Conf) ->
     [{seeds, conf_get("cluster.static.seeds", Conf, [])}];
-options(mcast, Conf) ->
+cluster_options(mcast, Conf) ->
     {ok, Addr} = inet:parse_address(conf_get("cluster.mcast.addr", Conf)),
     {ok, Iface} = inet:parse_address(conf_get("cluster.mcast.iface", Conf)),
     Ports = conf_get("cluster.mcast.ports", Conf),
@@ -1280,11 +1289,12 @@ options(mcast, Conf) ->
         {ttl, conf_get("cluster.mcast.ttl", Conf, 1)},
         {loop, conf_get("cluster.mcast.loop", Conf, true)}
     ];
-options(dns, Conf) ->
+cluster_options(dns, Conf) ->
     [
-        {name, conf_get("cluster.dns.name", Conf)}
+        {name, conf_get("cluster.dns.name", Conf)},
+        {type, conf_get("cluster.dns.record_type", Conf)}
     ];
-options(etcd, Conf) ->
+cluster_options(etcd, Conf) ->
     Namespace = "cluster.etcd.ssl",
     SslOpts = fun(C) ->
         Options = keys(Namespace, C),
@@ -1296,7 +1306,7 @@ options(etcd, Conf) ->
         {node_ttl, conf_get("cluster.etcd.node_ttl", Conf, 60)},
         {ssl_options, filter(SslOpts(Conf))}
     ];
-options(k8s, Conf) ->
+cluster_options(k8s, Conf) ->
     [
         {apiserver, conf_get("cluster.k8s.apiserver", Conf)},
         {service_name, conf_get("cluster.k8s.service_name", Conf)},
@@ -1304,7 +1314,7 @@ options(k8s, Conf) ->
         {namespace, conf_get("cluster.k8s.namespace", Conf)},
         {suffix, conf_get("cluster.k8s.suffix", Conf, "")}
     ];
-options(manual, _Conf) ->
+cluster_options(manual, _Conf) ->
     [].
 
 to_atom(Atom) when is_atom(Atom) ->

+ 1 - 0
scripts/test-node-discovery-dns.sh

@@ -70,6 +70,7 @@ start_emqx() {
         -e EMQX_NODE_COOKIE="$COOKIE" \
         -e EMQX_cluster__discovery_strategy='dns' \
         -e EMQX_cluster__dns__name="$DOMAIN" \
+        -e EMQX_cluster__dns__record_type="a" \
         "$IMAGE"
 }