Includes all pending changes needed for nixos-anywhere: - fiberlb: L7 policy, rule, certificate types - deployer: New service for cluster management - nix-nos: Generic network modules - Various service updates and fixes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
93 lines
2.4 KiB
Rust
93 lines
2.4 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use std::net::SocketAddr;
|
|
|
|
/// Deployer server configuration
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Config {
|
|
/// HTTP server bind address
|
|
#[serde(default = "default_bind_addr")]
|
|
pub bind_addr: SocketAddr,
|
|
|
|
/// ChainFire cluster endpoints
|
|
#[serde(default)]
|
|
pub chainfire: ChainFireConfig,
|
|
|
|
/// Node heartbeat timeout (seconds)
|
|
#[serde(default = "default_heartbeat_timeout")]
|
|
pub heartbeat_timeout_secs: u64,
|
|
}
|
|
|
|
impl Default for Config {
|
|
fn default() -> Self {
|
|
Self {
|
|
bind_addr: default_bind_addr(),
|
|
chainfire: ChainFireConfig::default(),
|
|
heartbeat_timeout_secs: default_heartbeat_timeout(),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// ChainFire configuration
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct ChainFireConfig {
|
|
/// ChainFire cluster endpoints
|
|
#[serde(default = "default_chainfire_endpoints")]
|
|
pub endpoints: Vec<String>,
|
|
|
|
/// Namespace for deployer state
|
|
#[serde(default = "default_chainfire_namespace")]
|
|
pub namespace: String,
|
|
}
|
|
|
|
impl Default for ChainFireConfig {
|
|
fn default() -> Self {
|
|
Self {
|
|
endpoints: default_chainfire_endpoints(),
|
|
namespace: default_chainfire_namespace(),
|
|
}
|
|
}
|
|
}
|
|
|
|
fn default_bind_addr() -> SocketAddr {
|
|
"0.0.0.0:8080".parse().unwrap()
|
|
}
|
|
|
|
fn default_chainfire_endpoints() -> Vec<String> {
|
|
vec!["http://127.0.0.1:7000".to_string()]
|
|
}
|
|
|
|
fn default_chainfire_namespace() -> String {
|
|
"deployer".to_string()
|
|
}
|
|
|
|
fn default_heartbeat_timeout() -> u64 {
|
|
300 // 5 minutes
|
|
}
|
|
|
|
/// Load configuration from environment or use defaults
|
|
pub fn load_config() -> anyhow::Result<Config> {
|
|
// TODO: Load from config file or environment variables
|
|
// For now, use defaults
|
|
Ok(Config::default())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_default_config() {
|
|
let config = Config::default();
|
|
assert_eq!(config.bind_addr.to_string(), "0.0.0.0:8080");
|
|
assert_eq!(config.chainfire.namespace, "deployer");
|
|
assert_eq!(config.heartbeat_timeout_secs, 300);
|
|
}
|
|
|
|
#[test]
|
|
fn test_config_serialization() {
|
|
let config = Config::default();
|
|
let json = serde_json::to_string(&config).unwrap();
|
|
let deserialized: Config = serde_json::from_str(&json).unwrap();
|
|
assert_eq!(deserialized.bind_addr, config.bind_addr);
|
|
}
|
|
}
|