Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use url::Url;
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct ClusterProvision {
/// Configuration for server pools that use a margin for scaling.
/// Configuration for server pools.
pub pools: ClusterPools,

#[schemars(with = "Option<String>")]
Expand Down Expand Up @@ -53,7 +53,6 @@ pub struct ClusterPools {
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct ClusterPoolJob {
pub autoscale_margin: u32,
// All other properties are read from Pegboard since they're identical
}

Expand All @@ -62,8 +61,6 @@ pub struct ClusterPoolJob {
#[derive(Debug, Serialize, Deserialize, Clone, Default, JsonSchema)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct ClusterPoolPegboard {
pub autoscale_margin: u32,

pub vlan_addr_range_min: Option<Ipv4Addr>,
pub vlan_addr_range_max: Option<Ipv4Addr>,

Expand Down Expand Up @@ -134,8 +131,6 @@ impl ClusterPoolPegboard {
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct ClusterPoolGg {
pub autoscale_margin: u32,

#[schemars(with = "Option<String>")]
pub vlan_ip_net: Option<Ipv4Net>,
pub firewall_rules: Option<Vec<FirewallRule>>,
Expand Down Expand Up @@ -217,8 +212,6 @@ impl ClusterPoolGg {
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct ClusterPoolAts {
pub autoscale_margin: u32,

#[schemars(with = "Option<String>")]
pub vlan_ip_net: Option<Ipv4Net>,
pub firewall_rules: Option<Vec<FirewallRule>>,
Expand Down Expand Up @@ -263,8 +256,6 @@ impl ClusterPoolFdb {
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct ClusterPoolWorker {
pub autoscale_margin: u32,

#[schemars(with = "Option<String>")]
pub vlan_ip_net: Option<Ipv4Net>,
pub firewall_rules: Option<Vec<FirewallRule>>,
Expand All @@ -287,8 +278,6 @@ impl ClusterPoolWorker {
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct ClusterPoolNats {
pub autoscale_margin: u32,

#[schemars(with = "Option<String>")]
pub vlan_ip_net: Option<Ipv4Net>,
pub firewall_rules: Option<Vec<FirewallRule>>,
Expand All @@ -311,8 +300,6 @@ impl ClusterPoolNats {
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct ClusterPoolGuard {
pub autoscale_margin: u32,

#[schemars(with = "Option<String>")]
pub vlan_ip_net: Option<Ipv4Net>,
pub firewall_rules: Option<Vec<FirewallRule>>,
Expand Down
4 changes: 4 additions & 0 deletions packages/core/services/cluster/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub struct Pool {
pub min_count: u32,
pub max_count: u32,
pub drain_timeout: u64,
#[serde(default)]
pub margin: u32,
}

// Backwards compatibility
Expand All @@ -69,6 +71,7 @@ impl TryFrom<backend::cluster::Pool> for Pool {
min_count: value.min_count,
max_count: value.max_count,
drain_timeout: value.drain_timeout,
margin: 0,
})
}
}
Expand Down Expand Up @@ -119,6 +122,7 @@ pub struct PoolUpdate {
pub min_count: Option<u32>,
pub max_count: Option<u32>,
pub drain_timeout: Option<u64>,
pub margin: Option<u32>,
}

#[derive(Serialize, Deserialize, Hash, Debug, Clone, Copy, PartialEq, Eq, FromRepr)]
Expand Down
12 changes: 8 additions & 4 deletions packages/core/services/cluster/src/workflows/datacenter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,26 +316,29 @@ async fn update_db(ctx: &ActivityCtx, input: &UpdateDbInput) -> GlobalResult<()>
if let Some(drain_timeout) = pool.drain_timeout {
current_pool.drain_timeout = drain_timeout;
}
if let Some(margin) = pool.margin {
current_pool.margin = margin;
}
} else {
tracing::info!(pool_type=?pool.pool_type, "creating new pool");

if pool.hardware.is_empty() {
tracing::warn!("must define hardware when creating new pool");
tracing::error!("must define hardware when creating new pool");
return Ok(());
}

let Some(min_count) = pool.min_count else {
tracing::warn!("must have `min_count` when creating a new pool");
tracing::error!("must have `min_count` when creating a new pool");
return Ok(());
};

let Some(max_count) = pool.max_count else {
tracing::warn!("must have `max_count` when creating a new pool");
tracing::error!("must have `max_count` when creating a new pool");
return Ok(());
};

let Some(drain_timeout) = pool.drain_timeout else {
tracing::warn!("must have `max_count` when creating a new pool");
tracing::error!("must have `max_count` when creating a new pool");
return Ok(());
Comment on lines +341 to 342

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Error message is incorrect - mentions 'max_count' but should be 'drain_timeout'

Suggested change
tracing::error!("must have `max_count` when creating a new pool");
return Ok(());
let Some(drain_timeout) = pool.drain_timeout else {
tracing::error!("must have `drain_timeout` when creating a new pool");
return Ok(());
};

};

Expand All @@ -346,6 +349,7 @@ async fn update_db(ctx: &ActivityCtx, input: &UpdateDbInput) -> GlobalResult<()>
min_count,
max_count,
drain_timeout,
margin: 0,
});
};
}
Expand Down
Loading