From 472c54f79a9ba826a46a16bcc5f29b39b7d2a84f Mon Sep 17 00:00:00 2001 From: MasterPtato <23087326+MasterPtato@users.noreply.github.com> Date: Thu, 31 Oct 2024 22:06:23 +0000 Subject: [PATCH] fix: move cluster config to rivet config (#1295) ## Changes --- packages/api/admin/src/route/mod.rs | 17 ++- packages/cli/Cargo.toml | 1 + packages/cli/src/commands/db/mod.rs | 1 - packages/cli/src/commands/wf/mod.rs | 12 +- packages/cli/src/commands/wf/signal.rs | 8 +- packages/cli/src/util/api.rs | 42 +++--- packages/cli/src/util/wf/mod.rs | 2 +- packages/common/config/src/config/rivet.rs | 103 ++++++++++++--- packages/services/cluster/src/types.rs | 39 ++++++ .../standalone/default-update/src/lib.rs | 125 ++---------------- .../pegboard/standalone/dc-init/Cargo.toml | 5 +- .../pegboard/standalone/dc-init/src/lib.rs | 32 +---- sdks/full/typescript/archive.tgz | 4 +- sdks/runtime/typescript/archive.tgz | 4 +- 14 files changed, 185 insertions(+), 210 deletions(-) diff --git a/packages/api/admin/src/route/mod.rs b/packages/api/admin/src/route/mod.rs index 5b0b17b16f..d233c4feb1 100644 --- a/packages/api/admin/src/route/mod.rs +++ b/packages/api/admin/src/route/mod.rs @@ -11,19 +11,24 @@ define_router! { "login": { POST: login::login( body: models::AdminLoginRequest, + internal_endpoint: true, ), }, "clusters": { - GET: clusters::list(), + GET: clusters::list( + internal_endpoint: true, + ), POST: clusters::create( body: models::AdminClustersCreateClusterRequest, + internal_endpoint: true, ), }, "clusters" / Uuid / "servers": { GET: clusters::servers::list( query: clusters::servers::ServerFilterQuery, + internal_endpoint: true, ), }, @@ -31,6 +36,7 @@ define_router! { POST: clusters::servers::taint( query: clusters::servers::ServerFilterQuery, body: serde_json::Value, + internal_endpoint: true, ), }, @@ -38,12 +44,14 @@ define_router! { POST: clusters::servers::destroy( query: clusters::servers::ServerFilterQuery, body: serde_json::Value, + internal_endpoint: true, ), }, "clusters" / Uuid / "servers" / "lost": { GET: clusters::servers::list_lost( query: clusters::servers::ServerFilterQuery, + internal_endpoint: true, ), }, @@ -51,19 +59,24 @@ define_router! { POST: clusters::servers::prune( query: clusters::servers::ServerFilterQuery, body: serde_json::Value, + internal_endpoint: true, ), }, "clusters" / Uuid / "datacenters": { - GET: clusters::datacenters::list(), + GET: clusters::datacenters::list( + internal_endpoint: true, + ), POST: clusters::datacenters::create( body: models::AdminClustersCreateDatacenterRequest, + internal_endpoint: true, ), }, "clusters" / Uuid / "datacenters" / Uuid : { PATCH: clusters::datacenters::update( body: models::AdminClustersUpdateDatacenterRequest, + internal_endpoint: true, ), }, diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml index 26bef9bfd8..2fd218f17f 100644 --- a/packages/cli/Cargo.toml +++ b/packages/cli/Cargo.toml @@ -16,6 +16,7 @@ colored_json = "5.0.0" global-error = { path = "../common/global-error" } include_dir = "0.7.4" indoc = "2.0.5" +rivet-api = { path = "../../sdks/full/rust" } rivet-migrate = { path = "../common/migrate" } rivet-pools = { version = "0.1.0", path = "../common/pools" } rivet-runtime = { version = "0.1.0", path = "../common/runtime" } diff --git a/packages/cli/src/commands/db/mod.rs b/packages/cli/src/commands/db/mod.rs index 5ef3105115..54a480956a 100644 --- a/packages/cli/src/commands/db/mod.rs +++ b/packages/cli/src/commands/db/mod.rs @@ -1,6 +1,5 @@ use anyhow::*; use clap::{Parser, ValueEnum}; -use std::path::PathBuf; use crate::run_config::RunConfig; diff --git a/packages/cli/src/commands/wf/mod.rs b/packages/cli/src/commands/wf/mod.rs index 838e214a92..1cf4df0147 100644 --- a/packages/cli/src/commands/wf/mod.rs +++ b/packages/cli/src/commands/wf/mod.rs @@ -12,9 +12,7 @@ mod signal; #[derive(Parser)] pub enum SubCommand { /// Prints the given workflow(s). - Get { - workflow_ids: Vec, - }, + Get { workflow_ids: Vec }, /// Finds workflows with the given tags, name and state. List { tags: Vec, @@ -28,13 +26,9 @@ pub enum SubCommand { pretty: bool, }, /// Silences a workflow from showing up as dead or running again. - Ack { - workflow_ids: Vec, - }, + Ack { workflow_ids: Vec }, /// Sets the wake immediate property of a workflow to true. - Wake { - workflow_ids: Vec, - }, + Wake { workflow_ids: Vec }, /// Lists the entire event history of a workflow. History { #[clap(index = 1)] diff --git a/packages/cli/src/commands/wf/signal.rs b/packages/cli/src/commands/wf/signal.rs index 1aaf945f5e..837720397a 100644 --- a/packages/cli/src/commands/wf/signal.rs +++ b/packages/cli/src/commands/wf/signal.rs @@ -10,9 +10,7 @@ use crate::util::{ #[derive(Parser)] pub enum SubCommand { /// Prints the given signal(s). - Get { - signal_ids: Vec, - }, + Get { signal_ids: Vec }, /// Finds signals that match the given tags. List { tags: Vec, @@ -28,9 +26,7 @@ pub enum SubCommand { pretty: bool, }, /// Silences a signal from showing up as dead or running again. - Ack { - signal_ids: Vec, - }, + Ack { signal_ids: Vec }, } impl SubCommand { diff --git a/packages/cli/src/util/api.rs b/packages/cli/src/util/api.rs index 99b1881f38..cb789950b4 100644 --- a/packages/cli/src/util/api.rs +++ b/packages/cli/src/util/api.rs @@ -1,8 +1,10 @@ use anyhow::*; -use serde_json::json; +use rivet_api::{ + apis::{admin_api, configuration::Configuration}, + models, +}; -/// Creates a login link for the hub. -pub async fn admin_login_url(config: &rivet_config::Config, username: String) -> Result { +pub fn private_api_config(config: &rivet_config::Config) -> Result { let server_config = config.server().map_err(|err| anyhow!("{err}"))?; let admin_token = server_config.rivet.token.admin.as_ref().context( @@ -10,29 +12,19 @@ pub async fn admin_login_url(config: &rivet_config::Config, username: String) -> )?; let api_private_config = &server_config.rivet.api_private; - let response = reqwest::Client::new() - .post(format!( - "http://{}:{}/admin/login", - api_private_config.host(), - api_private_config.port() - )) - .bearer_auth(admin_token.read()) - .json(&json!({ - "name": username, - })) - .send() - .await?; - - if !response.status().is_success() { - bail!( - "failed to login ({}):\n{:#?}", - response.status().as_u16(), - response.json::().await? - ); - } + Ok(Configuration { + base_path: api_private_config.internal_origin().to_string().trim_end_matches("/").to_string(), + bearer_access_token: Some(admin_token.read().clone()), + ..Default::default() + }) +} - let body = response.json::().await?; - let url = body.get("url").expect("url in login body").to_string(); +/// Creates a login link for the hub. +pub async fn admin_login_url(config: &rivet_config::Config, username: String) -> Result { + let api_config = private_api_config(config)?; + let url = admin_api::admin_login(&api_config, models::AdminLoginRequest { name: username }) + .await? + .url; Ok(url) } diff --git a/packages/cli/src/util/wf/mod.rs b/packages/cli/src/util/wf/mod.rs index 80ee327edf..d675bd6f2c 100644 --- a/packages/cli/src/util/wf/mod.rs +++ b/packages/cli/src/util/wf/mod.rs @@ -1,7 +1,7 @@ use std::cmp::Ordering; use anyhow::*; -use chrono::{Utc, TimeZone}; +use chrono::{TimeZone, Utc}; use clap::ValueEnum; use indoc::indoc; use rivet_pools::CrdbPool; diff --git a/packages/common/config/src/config/rivet.rs b/packages/common/config/src/config/rivet.rs index ad7a66e0fc..955716c363 100644 --- a/packages/common/config/src/config/rivet.rs +++ b/packages/common/config/src/config/rivet.rs @@ -46,63 +46,48 @@ pub struct Rivet { #[serde(default)] pub default_cluster_id: Option, - /// Manages the automatic provisioning of servers that Rivet runs on. #[serde(default)] pub cluster: Option, - /// The service that manages Rivet Actors. #[serde(default, rename = "orchestrator")] pub pegboard: Pegboard, - /// Configuration for authentication and access control. #[serde(default)] pub auth: Auth, - /// Configuration for various tokens used in the system. #[serde(default)] pub token: Tokens, - /// Configuration for the public API service. #[serde(default)] pub api_public: ApiPublic, - /// Configuration for the edge API service. #[serde(default)] pub api_edge: ApiEdge, - /// Configuration for the private API service. #[serde(default)] pub api_private: ApiPrivate, - /// Configuration for the metrics service. #[serde(default)] pub metrics: Metrics, - /// Configuration for the health check service. #[serde(default)] pub health: Health, - /// Configuration for the tunnel service. #[serde(default)] pub tunnel: Tunnel, - /// Configuration for the UI service. #[serde(default)] pub ui: Ui, - /// Configuration for DNS management. #[serde(default)] pub dns: Option, - /// Configuration for telemetry collection. #[serde(default)] pub telemetry: Telemetry, - /// Configuration for billing features (Enterprise Edition). #[serde(default)] pub billing: Option, - /// Configuration for backend features (Enterprise Edition). #[serde(default)] pub backend: Option, @@ -110,11 +95,9 @@ pub struct Rivet { #[serde(default)] pub test_builds: HashMap, - /// Deprecated: Configuration for job running. #[serde(default)] pub job_run: Option, - /// Deprecated: Configuration for CDN. #[serde(default)] pub cdn: Option, } @@ -183,6 +166,7 @@ pub enum RivetAccessKind { Private, } +/// Configuration for billing features (Enterprise Edition). #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Billing { @@ -192,6 +176,7 @@ pub struct Billing { pub studio_price_id: String, } +/// Configuration for backend features (Enterprise Edition). #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Backend { @@ -199,6 +184,7 @@ pub struct Backend { pub base_domain: String, } +/// Configuration for a default test build. #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct TestBuild { @@ -208,6 +194,7 @@ pub struct TestBuild { pub key: PathBuf, } +/// Configuration for the public API service. #[derive(Debug, Serialize, Deserialize, Clone, Default)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct ApiPublic { @@ -229,7 +216,7 @@ pub struct ApiPublic { impl ApiPublic { pub fn public_origin(&self) -> Url { self.public_origin.clone().unwrap_or_else(|| { - url::Url::parse(&format!("http://127.0.0.1:{}", default_ports::API_PUBLIC)).unwrap() + url::Url::parse(&format!("http://127.0.0.1:{}", self.port())).unwrap() }) } @@ -250,6 +237,7 @@ impl ApiPublic { } } +/// Configuration for the edge API service. #[derive(Debug, Serialize, Deserialize, Clone, Default)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct ApiEdge { @@ -267,14 +255,23 @@ impl ApiEdge { } } +/// Configuration for the private API service. #[derive(Debug, Serialize, Deserialize, Clone, Default)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct ApiPrivate { + /// The internal origin URL for the API. + pub internal_origin: Option, pub host: Option, pub port: Option, } impl ApiPrivate { + pub fn internal_origin(&self) -> Url { + self.internal_origin.clone().unwrap_or_else(|| { + url::Url::parse(&format!("http://{}:{}", self.host(), self.port())).unwrap() + }) + } + pub fn host(&self) -> IpAddr { self.host.unwrap_or(default_hosts::API_PRIVATE) } @@ -284,6 +281,7 @@ impl ApiPrivate { } } +/// Deprecated: Configuration for CDN. #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Cdn {} @@ -294,6 +292,7 @@ impl Default for Cdn { } } +/// Configuration for DNS management. #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Dns { @@ -313,13 +312,66 @@ pub enum DnsProvider { Cloudflare, } +/// Manages the automatic provisioning of servers that Rivet runs on. #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Cluster { - /// Configuration for different server pools. + pub name_id: String, + pub datacenters: HashMap, + + /// Configuration for server pools that use a margin for scaling. pub pools: ClusterPools, - /// Default configuration for new clusters. - pub default_cluster_config: Option, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "snake_case", deny_unknown_fields)] +pub struct Datacenter { + pub datacenter_id: Uuid, + pub display_name: String, + pub provider: Provider, + pub provider_datacenter_name: String, + pub pools: HashMap, + pub build_delivery_method: BuildDeliveryMethod, + pub prebakes_enabled: bool, +} + +#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] +#[serde(rename_all = "snake_case", deny_unknown_fields)] +pub enum Provider { + Linode, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "snake_case", deny_unknown_fields)] +pub struct Pool { + pub hardware: Vec, + pub desired_count: u32, + pub min_count: u32, + pub max_count: u32, + pub drain_timeout: u64, +} + +#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)] +#[serde(rename_all = "snake_case", deny_unknown_fields)] +pub enum PoolType { + Job, + Gg, + Ats, + Pegboard, + PegboardIsolate, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "snake_case", deny_unknown_fields)] +pub struct Hardware { + pub name: String, +} + +#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] +#[serde(rename_all = "snake_case", deny_unknown_fields)] +pub enum BuildDeliveryMethod { + TrafficServer, + S3Direct, } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -335,6 +387,7 @@ pub struct ClusterPool { pub provision_margin: u32, } +/// The service that manages Rivet Actors. #[derive(Debug, Serialize, Deserialize, Clone, Default)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Pegboard { @@ -375,12 +428,14 @@ impl Pegboard { } } +/// Deprecated: Configuration for job running. #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct JobRun { pub job_runner_binary_url: Url, } +/// Configuration for authentication and access control. #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Auth { @@ -402,6 +457,7 @@ impl Default for Auth { } } +/// Configuration for the tunnel service. #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Tunnel { @@ -416,6 +472,7 @@ impl Default for Tunnel { } } +/// Configuration for the UI service. #[derive(Debug, Serialize, Deserialize, Clone, Default)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Ui { @@ -450,6 +507,7 @@ impl Ui { } } +/// Configuration for various tokens used in the system. #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Tokens { @@ -471,6 +529,7 @@ impl Default for Tokens { } } +/// Configuration for the health check service. #[derive(Debug, Serialize, Deserialize, Clone, Default)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Health { @@ -488,6 +547,7 @@ impl Health { } } +/// Configuration for the metrics service. #[derive(Debug, Serialize, Deserialize, Clone, Default)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Metrics { @@ -505,6 +565,7 @@ impl Metrics { } } +/// Configuration for telemetry collection. #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Telemetry { diff --git a/packages/services/cluster/src/types.rs b/packages/services/cluster/src/types.rs index 66b7f7dfe6..ca46fa10af 100644 --- a/packages/services/cluster/src/types.rs +++ b/packages/services/cluster/src/types.rs @@ -37,6 +37,14 @@ pub enum Provider { Linode = 0, } +impl From for Provider { + fn from(value: rivet_config::config::rivet::Provider) -> Provider { + match value { + rivet_config::config::rivet::Provider::Linode => Provider::Linode, + } + } +} + #[derive(Debug, Clone, Serialize, Deserialize, Hash)] pub struct Pool { pub pool_type: PoolType, @@ -91,11 +99,31 @@ impl std::fmt::Display for PoolType { } } +impl From for PoolType { + fn from(value: rivet_config::config::rivet::PoolType) -> PoolType { + match value { + rivet_config::config::rivet::PoolType::Job => PoolType::Job, + rivet_config::config::rivet::PoolType::Gg => PoolType::Gg, + rivet_config::config::rivet::PoolType::Ats => PoolType::Ats, + rivet_config::config::rivet::PoolType::Pegboard => PoolType::Pegboard, + rivet_config::config::rivet::PoolType::PegboardIsolate => PoolType::PegboardIsolate, + } + } +} + #[derive(Debug, Clone, Serialize, Deserialize, Hash)] pub struct Hardware { pub provider_hardware: String, } +impl From for Hardware { + fn from(value: rivet_config::config::rivet::Hardware) -> Hardware { + Hardware { + provider_hardware: value.name, + } + } +} + #[derive(Debug, Serialize, Deserialize, Hash)] pub struct PoolUpdate { pub pool_type: PoolType, @@ -114,6 +142,17 @@ pub enum BuildDeliveryMethod { S3Direct = 1, } +impl From for BuildDeliveryMethod { + fn from(value: rivet_config::config::rivet::BuildDeliveryMethod) -> BuildDeliveryMethod { + match value { + rivet_config::config::rivet::BuildDeliveryMethod::TrafficServer => { + BuildDeliveryMethod::TrafficServer + } + rivet_config::config::rivet::BuildDeliveryMethod::S3Direct => BuildDeliveryMethod::S3Direct, + } + } +} + #[derive(Debug)] pub struct Server { pub server_id: Uuid, diff --git a/packages/services/cluster/standalone/default-update/src/lib.rs b/packages/services/cluster/standalone/default-update/src/lib.rs index e5f66d5e19..5ebea0490b 100644 --- a/packages/services/cluster/standalone/default-update/src/lib.rs +++ b/packages/services/cluster/standalone/default-update/src/lib.rs @@ -1,101 +1,4 @@ -use std::collections::HashMap; - use chirp_workflow::prelude::*; -use serde::Deserialize; - -#[derive(Deserialize)] -struct Cluster { - name_id: String, - datacenters: HashMap, -} - -#[derive(Deserialize)] -struct Datacenter { - datacenter_id: Uuid, - display_name: String, - provider: Provider, - provider_datacenter_name: String, - pools: HashMap, - build_delivery_method: BuildDeliveryMethod, - prebakes_enabled: bool, -} - -#[derive(Deserialize)] -enum Provider { - #[serde(rename = "linode")] - Linode, -} - -impl From for cluster::types::Provider { - fn from(value: Provider) -> cluster::types::Provider { - match value { - Provider::Linode => cluster::types::Provider::Linode, - } - } -} - -#[derive(Deserialize)] -struct Pool { - hardware: Vec, - desired_count: u32, - min_count: u32, - max_count: u32, - drain_timeout: u64, -} - -#[derive(Deserialize, PartialEq, Eq, Hash)] -#[serde(rename_all = "snake_case")] -enum PoolType { - Job, - Gg, - Ats, - Pegboard, - PegboardIsolate, -} - -impl From for cluster::types::PoolType { - fn from(value: PoolType) -> cluster::types::PoolType { - match value { - PoolType::Job => cluster::types::PoolType::Job, - PoolType::Gg => cluster::types::PoolType::Gg, - PoolType::Ats => cluster::types::PoolType::Ats, - PoolType::Pegboard => cluster::types::PoolType::Pegboard, - PoolType::PegboardIsolate => cluster::types::PoolType::PegboardIsolate, - } - } -} - -#[derive(Deserialize)] -struct Hardware { - name: String, -} - -impl From for cluster::types::Hardware { - fn from(value: Hardware) -> cluster::types::Hardware { - cluster::types::Hardware { - provider_hardware: value.name, - } - } -} - -#[derive(Deserialize)] -enum BuildDeliveryMethod { - #[serde(rename = "traffic_server")] - TrafficServer, - #[serde(rename = "s3_direct")] - S3Direct, -} - -impl From for cluster::types::BuildDeliveryMethod { - fn from(value: BuildDeliveryMethod) -> cluster::types::BuildDeliveryMethod { - match value { - BuildDeliveryMethod::TrafficServer => { - cluster::types::BuildDeliveryMethod::TrafficServer - } - BuildDeliveryMethod::S3Direct => cluster::types::BuildDeliveryMethod::S3Direct, - } - } -} pub async fn start( config: rivet_config::Config, @@ -128,17 +31,15 @@ pub async fn start_inner( .await?; // Read config from env - let Some(config_json) = &ctx + let Ok(config) = &ctx .config() .server()? .rivet - .cluster()? - .default_cluster_config + .cluster() else { tracing::warn!("no cluster config set in namespace config"); return Ok(()); }; - let config = serde_json::from_value::(config_json.clone())?; // HACK: When deploying both monolith worker and this service for the first time, there is a race // condition which might result in the message being published from here but not caught by @@ -188,7 +89,7 @@ pub async fn start_inner( } } - for (name_id, datacenter) in config.datacenters { + for (name_id, datacenter) in &config.datacenters { let existing_datacenter = datacenters_res .datacenters .iter() @@ -198,7 +99,7 @@ pub async fn start_inner( if existing_datacenter { let new_pools = datacenter .pools - .into_iter() + .iter() .map(|(pool_type, pool)| { let desired_count = if use_autoscaler { None @@ -207,10 +108,11 @@ pub async fn start_inner( }; cluster::types::PoolUpdate { - pool_type: pool_type.into(), + pool_type: (*pool_type).into(), hardware: pool .hardware - .into_iter() + .iter() + .cloned() .map(Into::into) .collect::>(), desired_count, @@ -233,21 +135,22 @@ pub async fn start_inner( else { ctx.signal(cluster::workflows::cluster::DatacenterCreate { datacenter_id: datacenter.datacenter_id, - name_id, - display_name: datacenter.display_name, + name_id: name_id.clone(), + display_name: datacenter.display_name.clone(), provider: datacenter.provider.into(), - provider_datacenter_id: datacenter.provider_datacenter_name, + provider_datacenter_id: datacenter.provider_datacenter_name.clone(), provider_api_token: None, pools: datacenter .pools - .into_iter() + .iter() .map(|(pool_type, pool)| cluster::types::Pool { - pool_type: pool_type.into(), + pool_type: (*pool_type).into(), hardware: pool .hardware - .into_iter() + .iter() + .cloned() .map(Into::into) .collect::>(), desired_count: pool.desired_count, diff --git a/packages/services/pegboard/standalone/dc-init/Cargo.toml b/packages/services/pegboard/standalone/dc-init/Cargo.toml index f792af3bec..65384804cf 100644 --- a/packages/services/pegboard/standalone/dc-init/Cargo.toml +++ b/packages/services/pegboard/standalone/dc-init/Cargo.toml @@ -9,18 +9,19 @@ license = "Apache-2.0" chirp-client = { path = "../../../../common/chirp/client" } chirp-workflow = { path = "../../../../common/chirp-workflow/core" } reqwest = "0.11" +rivet-config = { version = "0.1.0", path = "../../../../common/config" } rivet-connection = { path = "../../../../common/connection" } rivet-pools = { path = "../../../../common/pools" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" tokio = { version = "1.40", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "json", "ansi"] } tracing-logfmt = "0.3" +tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "json", "ansi"] } uuid = { version = "1", features = ["v4"] } +cluster = { path = "../../../cluster" } pegboard = { path = "../.." } -rivet-config = { version = "0.1.0", path = "../../../../common/config" } [dev-dependencies] chirp-worker = { path = "../../../../common/chirp/worker" } diff --git a/packages/services/pegboard/standalone/dc-init/src/lib.rs b/packages/services/pegboard/standalone/dc-init/src/lib.rs index bf1ac5cb4e..b27b2ede05 100644 --- a/packages/services/pegboard/standalone/dc-init/src/lib.rs +++ b/packages/services/pegboard/standalone/dc-init/src/lib.rs @@ -1,27 +1,5 @@ -use std::collections::HashMap; - use chirp_workflow::prelude::*; -use serde::Deserialize; - -#[derive(Deserialize)] -struct Cluster { - datacenters: HashMap, -} - -#[derive(Deserialize)] -struct Datacenter { - datacenter_id: Uuid, - pools: HashMap, -} - -#[derive(Deserialize, PartialEq, Eq, Hash)] -#[serde(rename_all = "snake_case")] -enum PoolType { - Job, - Gg, - Ats, - Pegboard, -} +use cluster::types::PoolType; // TODO: This is not idempotent. #[tracing::instrument(skip_all)] @@ -37,17 +15,15 @@ pub async fn start(config: rivet_config::Config, pools: rivet_pools::Pools) -> G .await?; // Read config from env - let Some(cluster_config_json) = &ctx + let Ok(cluster_config) = &ctx .config() .server()? .rivet - .cluster()? - .default_cluster_config + .cluster() else { tracing::warn!("no cluster config set in namespace config"); return Ok(()); }; - let cluster_config = serde_json::from_value::(cluster_config_json.clone())?; // Find datacenter ids with pegboard pools let datacenter_ids = cluster_config @@ -56,7 +32,7 @@ pub async fn start(config: rivet_config::Config, pools: rivet_pools::Pools) -> G .flat_map(|(_, dc)| { dc.pools .iter() - .any(|(pool_type, _)| matches!(pool_type, PoolType::Pegboard)) + .any(|(pool_type, _)| matches!((*pool_type).into(), PoolType::Pegboard)) .then_some(dc.datacenter_id) }) .collect::>(); diff --git a/sdks/full/typescript/archive.tgz b/sdks/full/typescript/archive.tgz index 14fb242de2..e496b3ae7b 100644 --- a/sdks/full/typescript/archive.tgz +++ b/sdks/full/typescript/archive.tgz @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e5293fb5c90d09571cd8263f1d3d12429abf97e04ce6dd6461e966081bccdae3 -size 529054 +oid sha256:ca2a51543a42a51abf3fff98fe1beacf6b6471df38b39ef9f8f019bee7f53a2a +size 529216 diff --git a/sdks/runtime/typescript/archive.tgz b/sdks/runtime/typescript/archive.tgz index b632f1c261..3e0cbb7916 100644 --- a/sdks/runtime/typescript/archive.tgz +++ b/sdks/runtime/typescript/archive.tgz @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7fc703e9bee0b5ecf0d345021136f8359c6fe3a331cbec1d2e551a76f9164368 -size 276993 +oid sha256:feb37f1b373a6a21747931a879417e6d4dea7272fed55d28b0f7cf39b1e68ccb +size 276989