mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-15 18:20:11 +00:00
feat(gateway): get node id from kubernetes
This commit is contained in:
parent
bfa0071f90
commit
44c5a2d106
2 changed files with 12 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
use anyhow::anyhow;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use libpk::{_config::ClusterSettings, runtime_config::RuntimeConfig};
|
use libpk::{_config::ClusterSettings, runtime_config::RuntimeConfig};
|
||||||
use metrics::counter;
|
use metrics::counter;
|
||||||
|
|
@ -48,6 +49,12 @@ pub fn create_shards(redis: fred::clients::RedisPool) -> anyhow::Result<Vec<Shar
|
||||||
|
|
||||||
let (start_shard, end_shard): (u32, u32) = if cluster_settings.total_shards < 16 {
|
let (start_shard, end_shard): (u32, u32) = if cluster_settings.total_shards < 16 {
|
||||||
warn!("we have less than 16 shards, assuming single gateway process");
|
warn!("we have less than 16 shards, assuming single gateway process");
|
||||||
|
if cluster_settings.node_id != 0 {
|
||||||
|
return Err(anyhow!(
|
||||||
|
"expecting to be node 0 in single-process mode, but we are node {}",
|
||||||
|
cluster_settings.node_id
|
||||||
|
));
|
||||||
|
}
|
||||||
(0, (cluster_settings.total_shards - 1).into())
|
(0, (cluster_settings.total_shards - 1).into())
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
|
|
|
||||||
|
|
@ -138,10 +138,15 @@ impl PKConfig {
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub static ref CONFIG: Arc<PKConfig> = {
|
pub static ref CONFIG: Arc<PKConfig> = {
|
||||||
|
// hacks
|
||||||
if let Ok(var) = std::env::var("NOMAD_ALLOC_INDEX")
|
if let Ok(var) = std::env::var("NOMAD_ALLOC_INDEX")
|
||||||
&& std::env::var("pluralkit__discord__cluster__total_nodes").is_ok() {
|
&& std::env::var("pluralkit__discord__cluster__total_nodes").is_ok() {
|
||||||
std::env::set_var("pluralkit__discord__cluster__node_id", var);
|
std::env::set_var("pluralkit__discord__cluster__node_id", var);
|
||||||
}
|
}
|
||||||
|
if let Ok(var) = std::env::var("STATEFULSET_NAME_FOR_INDEX")
|
||||||
|
&& std::env::var("pluralkit__discord__cluster__total_nodes").is_ok() {
|
||||||
|
std::env::set_var("pluralkit__discord__cluster__node_id", var.split("-").last().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
Arc::new(Config::builder()
|
Arc::new(Config::builder()
|
||||||
.add_source(config::Environment::with_prefix("pluralkit").separator("__"))
|
.add_source(config::Environment::with_prefix("pluralkit").separator("__"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue