From caf6dab80828f50250fec2a8683810768c2ef822 Mon Sep 17 00:00:00 2001 From: turtled Date: Thu, 18 Jul 2019 16:16:35 +0800 Subject: [PATCH] Support K8S hostname auto discovery cluster --- etc/emqx.conf | 7 ++++++- priv/emqx.schema | 10 ++++++++-- rebar.config | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/etc/emqx.conf b/etc/emqx.conf index 050f5e4f7..da3ba53f5 100644 --- a/etc/emqx.conf +++ b/etc/emqx.conf @@ -145,7 +145,7 @@ cluster.autoclean = 5m ## The address type is used to extract host from k8s service. ## -## Value: ip | dns +## Value: ip | dns | hostname ## cluster.k8s.address_type = ip ## The app name helps build 'node.name'. @@ -153,6 +153,11 @@ cluster.autoclean = 5m ## Value: String ## cluster.k8s.app_name = emqx +## The suffix added to hostname get from k8s service, only valid if cluster.k8s.address_type set to hostname +## +## Value: String +## cluster.k8s.hostname_suffix = + ## Kubernates Namespace ## ## Value: String diff --git a/priv/emqx.schema b/priv/emqx.schema index fe7607413..6c54ac945 100644 --- a/priv/emqx.schema +++ b/priv/emqx.schema @@ -129,7 +129,7 @@ ]}. {mapping, "cluster.k8s.address_type", "ekka.cluster_discovery", [ - {datatype, {enum, [ip, dns]}} + {datatype, {enum, [ip, dns, hostname]}} ]}. {mapping, "cluster.k8s.app_name", "ekka.cluster_discovery", [ @@ -140,6 +140,11 @@ {datatype, string} ]}. +{mapping, "cluster.k8s.hostname_suffix", "ekka.cluster_discovery", [ + {datatype, string}, + {default, ""} + ]}. + {translation, "ekka.cluster_discovery", fun(Conf) -> Strategy = cuttlefish:conf_get("cluster.discovery", Conf), Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end, @@ -176,7 +181,8 @@ {service_name, cuttlefish:conf_get("cluster.k8s.service_name", Conf)}, {address_type, cuttlefish:conf_get("cluster.k8s.address_type", Conf, ip)}, {app_name, cuttlefish:conf_get("cluster.k8s.app_name", Conf)}, - {namespace, cuttlefish:conf_get("cluster.k8s.namespace", Conf)}]; + {namespace, cuttlefish:conf_get("cluster.k8s.namespace", Conf)}, + {hostname_suffix, cuttlefish:conf_get("cluster.k8s.hostname_suffix", Conf, "")}]; (manual) -> [ ] end, diff --git a/rebar.config b/rebar.config index 89b9436af..9ae96648c 100644 --- a/rebar.config +++ b/rebar.config @@ -4,7 +4,7 @@ {gproc, "0.8.0"}, % hex {replayq, "0.1.1"}, %hex {esockd, "5.5.0"}, %hex - {ekka, {git, "https://github.com/emqx/ekka", {tag, "v0.5.7"}}}, + {ekka, {git, "https://github.com/emqx/ekka", {branch, "master"}}}, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.3.1"}}}, {cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.0.0"}}} ]}.