feature: Register consul services with agent API #567

Merged
lx merged 10 commits from unrob/garage:roberto/consul-agent-registration into main 2023-06-02 14:35:00 +00:00
3 changed files with 28 additions and 9 deletions
Showing only changes of commit bd6485565e - Show all commits

View file

@ -42,6 +42,17 @@ client_cert = "/etc/consul/consul-client.crt"
client_key = "/etc/consul/consul-key.crt" client_key = "/etc/consul/consul-key.crt"
tls_skip_verify = false tls_skip_verify = false
unrob marked this conversation as resolved Outdated
Outdated
Review

I think you meant for agent API mode instead?

I think you meant for `agent` API mode instead?
[consul_service_discovery]
unrob marked this conversation as resolved Outdated
Outdated
Review

Similarly, I'd suggest calling this simply token

Similarly, I'd suggest calling this simply `token`
consul_http_addr = "https://127.0.0.1:8501"
consul_http_token = "abcdef-01234-56789"
service_name = "garage"
ca_cert = "/etc/consul/consul-ca.crt"
tls_skip_verify = false
# tags to add to the published service
tags = [ "dns-enabled" ]
# additional service meta to send along registration
meta = { dns-acl = "allow trusted" }
[kubernetes_discovery] [kubernetes_discovery]
namespace = "garage" namespace = "garage"
service_name = "garage-daemon" service_name = "garage-daemon"

View file

@ -129,17 +129,22 @@ impl ConsulServiceDiscovery {
] ]
.concat(); .concat();
let mut meta = HashMap::from([
(format!("{}-pubkey", META_PREFIX), hex::encode(node_id)),
(format!("{}-hostname", META_PREFIX), hostname.to_string()),
]);
if let Some(global_meta) = &self.config.meta {
for (key, value) in global_meta.into_iter() {
meta.insert(key.clone(), value.clone());
}
}
let advertisement: ConsulPublishService = ConsulPublishService { let advertisement: ConsulPublishService = ConsulPublishService {
service_id: node.clone(), service_id: node.clone(),
service_name: self.config.service_name.clone(), service_name: self.config.service_name.clone(),
tags, tags,
meta: [ meta,
(format!("{}-pubkey", META_PREFIX), hex::encode(node_id)),
(format!("{}-hostname", META_PREFIX), hostname.to_string()),
]
.iter()
.cloned()
.collect(),
address: rpc_public_addr.ip(), address: rpc_public_addr.ip(),
port: rpc_public_addr.port(), port: rpc_public_addr.port(),
}; };

View file

@ -168,6 +168,9 @@ pub struct ConsulServiceConfig {
// Additional tags to add to the service // Additional tags to add to the service
#[serde(default)] #[serde(default)]
pub tags: Vec<String>, pub tags: Vec<String>,
// Additional service metadata to add
#[serde(default)]
pub meta: Option<std::collections::HashMap<String, String>>,
/// Skip TLS hostname verification /// Skip TLS hostname verification
#[serde(default)] #[serde(default)]
pub tls_skip_verify: bool, pub tls_skip_verify: bool,