Fix Consul & Kubernetes discovery with new way of doing background things
This commit is contained in:
parent
73ed9c7403
commit
1fc220886a
1 changed files with 22 additions and 17 deletions
|
@ -521,52 +521,57 @@ impl System {
|
||||||
// ---- INTERNALS ----
|
// ---- INTERNALS ----
|
||||||
|
|
||||||
#[cfg(feature = "consul-discovery")]
|
#[cfg(feature = "consul-discovery")]
|
||||||
async fn advertise_to_consul(self: Arc<Self>) -> Result<(), Error> {
|
async fn advertise_to_consul(self: Arc<Self>) {
|
||||||
let c = match &self.consul_discovery {
|
let c = match &self.consul_discovery {
|
||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
_ => return Ok(()),
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let rpc_public_addr = match self.rpc_public_addr {
|
let rpc_public_addr = match self.rpc_public_addr {
|
||||||
Some(addr) => addr,
|
Some(addr) => addr,
|
||||||
None => {
|
None => {
|
||||||
warn!("Not advertising to Consul because rpc_public_addr is not defined in config file and could not be autodetected.");
|
warn!("Not advertising to Consul because rpc_public_addr is not defined in config file and could not be autodetected.");
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
c.publish_consul_service(
|
if let Err(e) = c
|
||||||
self.netapp.id,
|
.publish_consul_service(
|
||||||
&self.local_status.load_full().hostname,
|
self.netapp.id,
|
||||||
rpc_public_addr,
|
&self.local_status.load_full().hostname,
|
||||||
)
|
rpc_public_addr,
|
||||||
.await
|
)
|
||||||
.err_context("Error while publishing Consul service")
|
.await
|
||||||
|
{
|
||||||
|
error!("Error while publishing Consul service: {}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "kubernetes-discovery")]
|
#[cfg(feature = "kubernetes-discovery")]
|
||||||
async fn advertise_to_kubernetes(self: Arc<Self>) -> Result<(), Error> {
|
async fn advertise_to_kubernetes(self: Arc<Self>) {
|
||||||
let k = match &self.kubernetes_discovery {
|
let k = match &self.kubernetes_discovery {
|
||||||
Some(k) => k,
|
Some(k) => k,
|
||||||
_ => return Ok(()),
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let rpc_public_addr = match self.rpc_public_addr {
|
let rpc_public_addr = match self.rpc_public_addr {
|
||||||
Some(addr) => addr,
|
Some(addr) => addr,
|
||||||
None => {
|
None => {
|
||||||
warn!("Not advertising to Kubernetes because rpc_public_addr is not defined in config file and could not be autodetected.");
|
warn!("Not advertising to Kubernetes because rpc_public_addr is not defined in config file and could not be autodetected.");
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
publish_kubernetes_node(
|
if let Err(e) = publish_kubernetes_node(
|
||||||
k,
|
k,
|
||||||
self.netapp.id,
|
self.netapp.id,
|
||||||
&self.local_status.load_full().hostname,
|
&self.local_status.load_full().hostname,
|
||||||
rpc_public_addr,
|
rpc_public_addr,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.err_context("Error while publishing node to kubernetes")
|
{
|
||||||
|
error!("Error while publishing node to Kubernetes: {}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Save network configuration to disc
|
/// Save network configuration to disc
|
||||||
|
@ -778,10 +783,10 @@ impl System {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "consul-discovery")]
|
#[cfg(feature = "consul-discovery")]
|
||||||
background::spawn(self.clone().advertise_to_consul());
|
tokio::spawn(self.clone().advertise_to_consul());
|
||||||
|
|
||||||
#[cfg(feature = "kubernetes-discovery")]
|
#[cfg(feature = "kubernetes-discovery")]
|
||||||
background::spawn(self.clone().advertise_to_kubernetes());
|
tokio::spawn(self.clone().advertise_to_kubernetes());
|
||||||
|
|
||||||
let restart_at = tokio::time::sleep(DISCOVERY_INTERVAL);
|
let restart_at = tokio::time::sleep(DISCOVERY_INTERVAL);
|
||||||
select! {
|
select! {
|
||||||
|
|
Loading…
Reference in a new issue