fix: resolve DNS hostnames in STEMEDB_SEED_NODES for k8s headless service
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
SocketAddr::parse() doesn't resolve DNS names. Use tokio::net::lookup_host
for k8s pod DNS (stemedb-{0,1,2}.stemedb-headless.stemedb.svc:18182).
This commit is contained in:
parent
0fa7cfdf9b
commit
9afb36078c
@ -38,7 +38,8 @@ struct NodeConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NodeConfig {
|
impl NodeConfig {
|
||||||
fn from_env() -> Self {
|
/// Load config from env, resolving DNS hostnames in seed nodes.
|
||||||
|
async fn from_env() -> Self {
|
||||||
let api_addr = std::env::var("STEMEDB_NODE_API_ADDR")
|
let api_addr = std::env::var("STEMEDB_NODE_API_ADDR")
|
||||||
.unwrap_or_else(|_| "127.0.0.1:18181".to_string())
|
.unwrap_or_else(|_| "127.0.0.1:18181".to_string())
|
||||||
.parse()
|
.parse()
|
||||||
@ -49,12 +50,28 @@ impl NodeConfig {
|
|||||||
.parse()
|
.parse()
|
||||||
.unwrap_or_else(|_| SocketAddr::from(([127, 0, 0, 1], 18182)));
|
.unwrap_or_else(|_| SocketAddr::from(([127, 0, 0, 1], 18182)));
|
||||||
|
|
||||||
let seed_nodes = std::env::var("STEMEDB_SEED_NODES")
|
let raw_seeds = std::env::var("STEMEDB_SEED_NODES").unwrap_or_default();
|
||||||
.unwrap_or_default()
|
let mut seed_nodes = Vec::new();
|
||||||
.split(',')
|
for entry in raw_seeds.split(',').filter(|s| !s.trim().is_empty()) {
|
||||||
.filter(|s| !s.trim().is_empty())
|
let entry = entry.trim();
|
||||||
.filter_map(|s| s.trim().parse().ok())
|
// Try direct SocketAddr parse first (e.g., "10.0.0.1:18182")
|
||||||
.collect();
|
if let Ok(addr) = entry.parse::<SocketAddr>() {
|
||||||
|
seed_nodes.push(addr);
|
||||||
|
} else {
|
||||||
|
// DNS hostname (e.g., "stemedb-0.stemedb-headless.stemedb.svc:18182")
|
||||||
|
match tokio::net::lookup_host(entry).await {
|
||||||
|
Ok(mut addrs) => {
|
||||||
|
if let Some(addr) = addrs.next() {
|
||||||
|
info!(seed = entry, resolved = %addr, "Resolved seed node");
|
||||||
|
seed_nodes.push(addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
info!(seed = entry, error = %e, "Failed to resolve seed (may not be up yet)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let num_shards =
|
let num_shards =
|
||||||
std::env::var("STEMEDB_NUM_SHARDS").ok().and_then(|s| s.parse().ok()).unwrap_or(4);
|
std::env::var("STEMEDB_NUM_SHARDS").ok().and_then(|s| s.parse().ok()).unwrap_or(4);
|
||||||
@ -80,7 +97,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
tracing_subscriber::registry().with(env_filter).with(tracing_subscriber::fmt::layer()).init();
|
tracing_subscriber::registry().with(env_filter).with(tracing_subscriber::fmt::layer()).init();
|
||||||
|
|
||||||
let config = NodeConfig::from_env();
|
let config = NodeConfig::from_env().await;
|
||||||
|
|
||||||
// Use stable NodeId (env var → hostname → random fallback)
|
// Use stable NodeId (env var → hostname → random fallback)
|
||||||
let node_id = stable_node_id();
|
let node_id = stable_node_id();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user