From 46b01f34189ecc1285be5b60b5f10c8b01e9dcca Mon Sep 17 00:00:00 2001 From: MasterPtato Date: Thu, 30 May 2024 17:35:52 +0000 Subject: [PATCH] fix: add min count to autoscaler --- fern/definition/admin/clusters/common.yml | 2 +- .../definition/admin/clusters/datacenters.yml | 2 +- .../cli/src/commands/cluster/datacenter.rs | 5 ++++ lib/bolt/config/src/ns.rs | 2 ++ lib/bolt/core/src/context/project.rs | 24 +++++++++++++++---- lib/convert/src/impls/admin.rs | 1 + proto/backend/cluster.proto | 1 + sdks/full/go/admin/clusters/datacenters.go | 1 + sdks/full/go/admin/clusters/types.go | 1 + sdks/full/openapi/openapi.yml | 5 ++++ sdks/full/openapi_compat/openapi.yml | 5 ++++ sdks/full/rust-cli/docs/AdminClustersPool.md | 1 + .../AdminClustersUpdateDatacenterRequest.md | 1 + .../src/models/admin_clusters_pool.rs | 5 +++- ...dmin_clusters_update_datacenter_request.rs | 3 +++ sdks/full/rust/docs/AdminClustersPool.md | 1 + .../AdminClustersUpdateDatacenterRequest.md | 1 + .../rust/src/models/admin_clusters_pool.rs | 5 +++- ...dmin_clusters_update_datacenter_request.rs | 3 +++ sdks/full/typescript/archive.tgz | 4 ++-- .../clusters/resources/common/types/Pool.d.ts | 1 + .../types/UpdateDatacenterRequest.d.ts | 1 + .../clusters/resources/common/types/Pool.d.ts | 1 + .../types/UpdateDatacenterRequest.d.ts | 1 + sdks/runtime/typescript/archive.tgz | 4 ++-- .../admin/src/route/clusters/datacenters.rs | 4 ++++ .../standalone/default-update/src/lib.rs | 3 +++ .../standalone/gc/tests/integration.rs | 1 + .../cluster/types/msg/datacenter-update.proto | 1 + .../worker/src/workers/datacenter_create.rs | 6 ++--- .../worker/src/workers/datacenter_scale.rs | 2 +- .../worker/src/workers/datacenter_update.rs | 3 +++ svc/pkg/cluster/worker/tests/common.rs | 1 + .../cluster/worker/tests/datacenter_update.rs | 2 ++ svc/pkg/cluster/worker/tests/server_taint.rs | 2 ++ 35 files changed, 89 insertions(+), 17 deletions(-) diff --git a/fern/definition/admin/clusters/common.yml b/fern/definition/admin/clusters/common.yml index d2199184b..9d3bdae93 100644 --- a/fern/definition/admin/clusters/common.yml +++ b/fern/definition/admin/clusters/common.yml @@ -18,6 +18,7 @@ types: pool_type: PoolType hardware: list desired_count: integer + min_count: integer max_count: integer drain_timeout: long Hardware: @@ -44,4 +45,3 @@ types: properties: server_id: uuid public_ip: string - diff --git a/fern/definition/admin/clusters/datacenters.yml b/fern/definition/admin/clusters/datacenters.yml index 485b223a9..bfaa687c3 100644 --- a/fern/definition/admin/clusters/datacenters.yml +++ b/fern/definition/admin/clusters/datacenters.yml @@ -49,6 +49,6 @@ types: pool_type: localCommons.PoolType hardware: list desired_count: optional + min_count: optional max_count: optional drain_timeout: optional - diff --git a/lib/bolt/cli/src/commands/cluster/datacenter.rs b/lib/bolt/cli/src/commands/cluster/datacenter.rs index 7fee55815..457a31c5d 100644 --- a/lib/bolt/cli/src/commands/cluster/datacenter.rs +++ b/lib/bolt/cli/src/commands/cluster/datacenter.rs @@ -100,6 +100,9 @@ pub enum SubCommand { /// The desired count #[clap(long)] desired_count: Option, + /// The min count + #[clap(long)] + min_count: Option, /// The max count #[clap(long)] max_count: Option, @@ -192,6 +195,7 @@ impl SubCommand { pool, hardware, desired_count, + min_count, max_count, drain_timeout, } => { @@ -234,6 +238,7 @@ impl SubCommand { provider_hardware: hardware.clone(), }) .collect(), + min_count, max_count, pool_type: pool.into(), }, diff --git a/lib/bolt/config/src/ns.rs b/lib/bolt/config/src/ns.rs index 4984a1a39..541ffbe23 100644 --- a/lib/bolt/config/src/ns.rs +++ b/lib/bolt/config/src/ns.rs @@ -669,6 +669,8 @@ pub enum ProvisioningBuildDeliveryMethod { pub struct ProvisioningDatacenterPool { pub hardware: Vec, pub desired_count: u32, + #[serde(default)] + pub min_count: u32, pub max_count: u32, /// Server drain time in ms. pub drain_timeout: u64, diff --git a/lib/bolt/core/src/context/project.rs b/lib/bolt/core/src/context/project.rs index 2f811c316..ddd6dfbd7 100644 --- a/lib/bolt/core/src/context/project.rs +++ b/lib/bolt/core/src/context/project.rs @@ -260,12 +260,18 @@ impl ProjectContextData { panic!("invalid datacenter ({}): Missing ATS pool", name_id); }; - // Validate the build delivery method assert!( ats_pool.desired_count <= ats_pool.max_count, "invalid datacenter ({}): ATS desired > max", - name_id + name_id, + ); + assert!( + ats_pool.min_count <= ats_pool.desired_count, + "invalid datacenter ({}): ATS min > desired", + name_id, ); + + // Validate the build delivery method match datacenter.build_delivery_method { config::ns::ProvisioningBuildDeliveryMethod::TrafficServer => { assert_ne!( @@ -296,7 +302,12 @@ impl ProjectContextData { assert!( gg_count <= gg_pool.unwrap().max_count, "invalid datacenter ({}): GG desired > max", - name_id + name_id, + ); + assert!( + gg_pool.unwrap().min_count <= gg_pool.unwrap().desired_count, + "invalid datacenter ({}): GG min > desired", + name_id, ); let job_pool = datacenter @@ -312,7 +323,12 @@ impl ProjectContextData { assert!( job_count <= job_pool.unwrap().max_count, "invalid datacenter ({}): Job desired > max", - name_id + name_id, + ); + assert!( + job_pool.unwrap().min_count <= job_pool.unwrap().desired_count, + "invalid datacenter ({}): Job min > desired", + name_id, ); } } diff --git a/lib/convert/src/impls/admin.rs b/lib/convert/src/impls/admin.rs index 998185eff..6598bd6bc 100644 --- a/lib/convert/src/impls/admin.rs +++ b/lib/convert/src/impls/admin.rs @@ -108,6 +108,7 @@ impl ApiTryFrom for models::AdminClustersDatacente }) }) .collect::, GlobalError>>()?, + min_count: unwrap!(p.min_count.try_into()), max_count: unwrap!(p.max_count.try_into()), pool_type: unwrap!(backend::cluster::PoolType::from_i32(p.pool_type)) .api_into(), diff --git a/proto/backend/cluster.proto b/proto/backend/cluster.proto index 2e48eea09..84bbd11c7 100644 --- a/proto/backend/cluster.proto +++ b/proto/backend/cluster.proto @@ -37,6 +37,7 @@ message Pool { // See docs on failover (/docs/packages/cluster/SERVER_PROVISIONING.md#creating-a-new-server) repeated Hardware hardware = 2; uint32 desired_count = 3; + uint32 min_count = 6; uint32 max_count = 4; // Server drain timeout In ms uint64 drain_timeout = 5; diff --git a/sdks/full/go/admin/clusters/datacenters.go b/sdks/full/go/admin/clusters/datacenters.go index bb4e1df51..5215c46d2 100644 --- a/sdks/full/go/admin/clusters/datacenters.go +++ b/sdks/full/go/admin/clusters/datacenters.go @@ -104,6 +104,7 @@ type UpdateDatacenterRequest struct { PoolType PoolType `json:"pool_type,omitempty"` Hardware []*Hardware `json:"hardware,omitempty"` DesiredCount *int `json:"desired_count,omitempty"` + MinCount *int `json:"min_count,omitempty"` MaxCount *int `json:"max_count,omitempty"` DrainTimeout *int64 `json:"drain_timeout,omitempty"` diff --git a/sdks/full/go/admin/clusters/types.go b/sdks/full/go/admin/clusters/types.go index c4cb1aecb..37e85c883 100644 --- a/sdks/full/go/admin/clusters/types.go +++ b/sdks/full/go/admin/clusters/types.go @@ -133,6 +133,7 @@ type Pool struct { PoolType PoolType `json:"pool_type,omitempty"` Hardware []*Hardware `json:"hardware,omitempty"` DesiredCount int `json:"desired_count"` + MinCount int `json:"min_count"` MaxCount int `json:"max_count"` DrainTimeout int64 `json:"drain_timeout"` diff --git a/sdks/full/openapi/openapi.yml b/sdks/full/openapi/openapi.yml index 08bd68cee..fec893e32 100644 --- a/sdks/full/openapi/openapi.yml +++ b/sdks/full/openapi/openapi.yml @@ -9927,6 +9927,8 @@ components: $ref: '#/components/schemas/AdminClustersHardware' desired_count: type: integer + min_count: + type: integer max_count: type: integer drain_timeout: @@ -9936,6 +9938,7 @@ components: - pool_type - hardware - desired_count + - min_count - max_count - drain_timeout AdminClustersHardware: @@ -10055,6 +10058,8 @@ components: $ref: '#/components/schemas/AdminClustersHardware' desired_count: type: integer + min_count: + type: integer max_count: type: integer drain_timeout: diff --git a/sdks/full/openapi_compat/openapi.yml b/sdks/full/openapi_compat/openapi.yml index 852c12364..381a25156 100644 --- a/sdks/full/openapi_compat/openapi.yml +++ b/sdks/full/openapi_compat/openapi.yml @@ -151,12 +151,15 @@ components: type: array max_count: type: integer + min_count: + type: integer pool_type: $ref: '#/components/schemas/AdminClustersPoolType' required: - pool_type - hardware - desired_count + - min_count - max_count - drain_timeout type: object @@ -194,6 +197,8 @@ components: type: array max_count: type: integer + min_count: + type: integer pool_type: $ref: '#/components/schemas/AdminClustersPoolType' required: diff --git a/sdks/full/rust-cli/docs/AdminClustersPool.md b/sdks/full/rust-cli/docs/AdminClustersPool.md index 617eb2c80..85b3e1534 100644 --- a/sdks/full/rust-cli/docs/AdminClustersPool.md +++ b/sdks/full/rust-cli/docs/AdminClustersPool.md @@ -8,6 +8,7 @@ Name | Type | Description | Notes **drain_timeout** | **i64** | | **hardware** | [**Vec**](AdminClustersHardware.md) | | **max_count** | **i32** | | +**min_count** | **i32** | | **pool_type** | [**crate::models::AdminClustersPoolType**](AdminClustersPoolType.md) | | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/sdks/full/rust-cli/docs/AdminClustersUpdateDatacenterRequest.md b/sdks/full/rust-cli/docs/AdminClustersUpdateDatacenterRequest.md index 5c226d40d..7e05f0a82 100644 --- a/sdks/full/rust-cli/docs/AdminClustersUpdateDatacenterRequest.md +++ b/sdks/full/rust-cli/docs/AdminClustersUpdateDatacenterRequest.md @@ -8,6 +8,7 @@ Name | Type | Description | Notes **drain_timeout** | Option<**i64**> | | [optional] **hardware** | [**Vec**](AdminClustersHardware.md) | | **max_count** | Option<**i32**> | | [optional] +**min_count** | Option<**i32**> | | [optional] **pool_type** | [**crate::models::AdminClustersPoolType**](AdminClustersPoolType.md) | | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/sdks/full/rust-cli/src/models/admin_clusters_pool.rs b/sdks/full/rust-cli/src/models/admin_clusters_pool.rs index 7c28c2307..d1baf2e6d 100644 --- a/sdks/full/rust-cli/src/models/admin_clusters_pool.rs +++ b/sdks/full/rust-cli/src/models/admin_clusters_pool.rs @@ -21,17 +21,20 @@ pub struct AdminClustersPool { pub hardware: Vec, #[serde(rename = "max_count")] pub max_count: i32, + #[serde(rename = "min_count")] + pub min_count: i32, #[serde(rename = "pool_type")] pub pool_type: crate::models::AdminClustersPoolType, } impl AdminClustersPool { - pub fn new(desired_count: i32, drain_timeout: i64, hardware: Vec, max_count: i32, pool_type: crate::models::AdminClustersPoolType) -> AdminClustersPool { + pub fn new(desired_count: i32, drain_timeout: i64, hardware: Vec, max_count: i32, min_count: i32, pool_type: crate::models::AdminClustersPoolType) -> AdminClustersPool { AdminClustersPool { desired_count, drain_timeout, hardware, max_count, + min_count, pool_type, } } diff --git a/sdks/full/rust-cli/src/models/admin_clusters_update_datacenter_request.rs b/sdks/full/rust-cli/src/models/admin_clusters_update_datacenter_request.rs index 3c9e72640..3fabb783b 100644 --- a/sdks/full/rust-cli/src/models/admin_clusters_update_datacenter_request.rs +++ b/sdks/full/rust-cli/src/models/admin_clusters_update_datacenter_request.rs @@ -21,6 +21,8 @@ pub struct AdminClustersUpdateDatacenterRequest { pub hardware: Vec, #[serde(rename = "max_count", skip_serializing_if = "Option::is_none")] pub max_count: Option, + #[serde(rename = "min_count", skip_serializing_if = "Option::is_none")] + pub min_count: Option, #[serde(rename = "pool_type")] pub pool_type: crate::models::AdminClustersPoolType, } @@ -32,6 +34,7 @@ impl AdminClustersUpdateDatacenterRequest { drain_timeout: None, hardware, max_count: None, + min_count: None, pool_type, } } diff --git a/sdks/full/rust/docs/AdminClustersPool.md b/sdks/full/rust/docs/AdminClustersPool.md index 617eb2c80..85b3e1534 100644 --- a/sdks/full/rust/docs/AdminClustersPool.md +++ b/sdks/full/rust/docs/AdminClustersPool.md @@ -8,6 +8,7 @@ Name | Type | Description | Notes **drain_timeout** | **i64** | | **hardware** | [**Vec**](AdminClustersHardware.md) | | **max_count** | **i32** | | +**min_count** | **i32** | | **pool_type** | [**crate::models::AdminClustersPoolType**](AdminClustersPoolType.md) | | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/sdks/full/rust/docs/AdminClustersUpdateDatacenterRequest.md b/sdks/full/rust/docs/AdminClustersUpdateDatacenterRequest.md index 5c226d40d..7e05f0a82 100644 --- a/sdks/full/rust/docs/AdminClustersUpdateDatacenterRequest.md +++ b/sdks/full/rust/docs/AdminClustersUpdateDatacenterRequest.md @@ -8,6 +8,7 @@ Name | Type | Description | Notes **drain_timeout** | Option<**i64**> | | [optional] **hardware** | [**Vec**](AdminClustersHardware.md) | | **max_count** | Option<**i32**> | | [optional] +**min_count** | Option<**i32**> | | [optional] **pool_type** | [**crate::models::AdminClustersPoolType**](AdminClustersPoolType.md) | | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/sdks/full/rust/src/models/admin_clusters_pool.rs b/sdks/full/rust/src/models/admin_clusters_pool.rs index 7c28c2307..d1baf2e6d 100644 --- a/sdks/full/rust/src/models/admin_clusters_pool.rs +++ b/sdks/full/rust/src/models/admin_clusters_pool.rs @@ -21,17 +21,20 @@ pub struct AdminClustersPool { pub hardware: Vec, #[serde(rename = "max_count")] pub max_count: i32, + #[serde(rename = "min_count")] + pub min_count: i32, #[serde(rename = "pool_type")] pub pool_type: crate::models::AdminClustersPoolType, } impl AdminClustersPool { - pub fn new(desired_count: i32, drain_timeout: i64, hardware: Vec, max_count: i32, pool_type: crate::models::AdminClustersPoolType) -> AdminClustersPool { + pub fn new(desired_count: i32, drain_timeout: i64, hardware: Vec, max_count: i32, min_count: i32, pool_type: crate::models::AdminClustersPoolType) -> AdminClustersPool { AdminClustersPool { desired_count, drain_timeout, hardware, max_count, + min_count, pool_type, } } diff --git a/sdks/full/rust/src/models/admin_clusters_update_datacenter_request.rs b/sdks/full/rust/src/models/admin_clusters_update_datacenter_request.rs index 3c9e72640..3fabb783b 100644 --- a/sdks/full/rust/src/models/admin_clusters_update_datacenter_request.rs +++ b/sdks/full/rust/src/models/admin_clusters_update_datacenter_request.rs @@ -21,6 +21,8 @@ pub struct AdminClustersUpdateDatacenterRequest { pub hardware: Vec, #[serde(rename = "max_count", skip_serializing_if = "Option::is_none")] pub max_count: Option, + #[serde(rename = "min_count", skip_serializing_if = "Option::is_none")] + pub min_count: Option, #[serde(rename = "pool_type")] pub pool_type: crate::models::AdminClustersPoolType, } @@ -32,6 +34,7 @@ impl AdminClustersUpdateDatacenterRequest { drain_timeout: None, hardware, max_count: None, + min_count: None, pool_type, } } diff --git a/sdks/full/typescript/archive.tgz b/sdks/full/typescript/archive.tgz index 8291dbfd4..debca6583 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:6404df58c289f0aafbd1bf64d81b17df19b987fc2ed00402ee2ed04a9156d406 -size 639921 +oid sha256:33099a9a53151c8183723b13166dc46499f385288b8805cd48a88d671113a4e5 +size 640123 diff --git a/sdks/full/typescript/types/api/resources/admin/resources/clusters/resources/common/types/Pool.d.ts b/sdks/full/typescript/types/api/resources/admin/resources/clusters/resources/common/types/Pool.d.ts index a2692e013..2b7befbb8 100644 --- a/sdks/full/typescript/types/api/resources/admin/resources/clusters/resources/common/types/Pool.d.ts +++ b/sdks/full/typescript/types/api/resources/admin/resources/clusters/resources/common/types/Pool.d.ts @@ -6,6 +6,7 @@ export interface Pool { poolType: Rivet.admin.clusters.PoolType; hardware: Rivet.admin.clusters.Hardware[]; desiredCount: number; + minCount: number; maxCount: number; drainTimeout: number; } diff --git a/sdks/full/typescript/types/api/resources/admin/resources/clusters/resources/datacenters/types/UpdateDatacenterRequest.d.ts b/sdks/full/typescript/types/api/resources/admin/resources/clusters/resources/datacenters/types/UpdateDatacenterRequest.d.ts index bcba4c00a..c2bcb74bd 100644 --- a/sdks/full/typescript/types/api/resources/admin/resources/clusters/resources/datacenters/types/UpdateDatacenterRequest.d.ts +++ b/sdks/full/typescript/types/api/resources/admin/resources/clusters/resources/datacenters/types/UpdateDatacenterRequest.d.ts @@ -6,6 +6,7 @@ export interface UpdateDatacenterRequest { poolType: Rivet.admin.clusters.PoolType; hardware: Rivet.admin.clusters.Hardware[]; desiredCount?: number; + minCount?: number; maxCount?: number; drainTimeout?: number; } diff --git a/sdks/full/typescript/types/serialization/resources/admin/resources/clusters/resources/common/types/Pool.d.ts b/sdks/full/typescript/types/serialization/resources/admin/resources/clusters/resources/common/types/Pool.d.ts index 5aa7fb22d..fdad214a5 100644 --- a/sdks/full/typescript/types/serialization/resources/admin/resources/clusters/resources/common/types/Pool.d.ts +++ b/sdks/full/typescript/types/serialization/resources/admin/resources/clusters/resources/common/types/Pool.d.ts @@ -10,6 +10,7 @@ export declare namespace Pool { pool_type: serializers.admin.clusters.PoolType.Raw; hardware: serializers.admin.clusters.Hardware.Raw[]; desired_count: number; + min_count: number; max_count: number; drain_timeout: number; } diff --git a/sdks/full/typescript/types/serialization/resources/admin/resources/clusters/resources/datacenters/types/UpdateDatacenterRequest.d.ts b/sdks/full/typescript/types/serialization/resources/admin/resources/clusters/resources/datacenters/types/UpdateDatacenterRequest.d.ts index 5e6286cb4..ce5533572 100644 --- a/sdks/full/typescript/types/serialization/resources/admin/resources/clusters/resources/datacenters/types/UpdateDatacenterRequest.d.ts +++ b/sdks/full/typescript/types/serialization/resources/admin/resources/clusters/resources/datacenters/types/UpdateDatacenterRequest.d.ts @@ -10,6 +10,7 @@ export declare namespace UpdateDatacenterRequest { pool_type: serializers.admin.clusters.PoolType.Raw; hardware: serializers.admin.clusters.Hardware.Raw[]; desired_count?: number | null; + min_count?: number | null; max_count?: number | null; drain_timeout?: number | null; } diff --git a/sdks/runtime/typescript/archive.tgz b/sdks/runtime/typescript/archive.tgz index 0ed3c52cc..fb45057e6 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:92a08028ffdd9a3d657005ba4e62950e444aa59f74301b87ade46b0f368e767f -size 371619 +oid sha256:c7d3c9fa927cdb76d6e31bb0839b642eb445bd0dbb9f0755aec3c37c4f609415 +size 371475 diff --git a/svc/api/admin/src/route/clusters/datacenters.rs b/svc/api/admin/src/route/clusters/datacenters.rs index cbad5d0a4..fb3ab9993 100644 --- a/svc/api/admin/src/route/clusters/datacenters.rs +++ b/svc/api/admin/src/route/clusters/datacenters.rs @@ -61,6 +61,7 @@ pub async fn create( provider_hardware: "g6-nanode-1".to_string(), }], desired_count: 0, + min_count: 0, max_count: 0, drain_timeout, }, @@ -70,6 +71,7 @@ pub async fn create( provider_hardware: "g6-nanode-1".to_string(), }], desired_count: 0, + min_count: 0, max_count: 0, drain_timeout, }, @@ -79,6 +81,7 @@ pub async fn create( provider_hardware: "g6-nanode-1".to_string(), }], desired_count: 0, + min_count: 0, max_count: 0, drain_timeout, }, @@ -136,6 +139,7 @@ pub async fn update( }) .collect(), desired_count: body.desired_count.map(|c| c as u32), + min_count: body.min_count.map(|c| c as u32), max_count: body.max_count.map(|c| c as u32), drain_timeout: body.drain_timeout.map(|d| d as u64), }]; diff --git a/svc/pkg/cluster/standalone/default-update/src/lib.rs b/svc/pkg/cluster/standalone/default-update/src/lib.rs index c15bd2ba9..ef4d503c7 100644 --- a/svc/pkg/cluster/standalone/default-update/src/lib.rs +++ b/svc/pkg/cluster/standalone/default-update/src/lib.rs @@ -39,6 +39,7 @@ impl From for backend::cluster::Provider { struct Pool { hardware: Vec, desired_count: u32, + min_count: u32, max_count: u32, drain_timeout: u64, } @@ -204,6 +205,7 @@ pub async fn run_from_env(use_autoscaler: bool) -> GlobalResult<()> { .map(Into::into) .collect::>(), desired_count, + min_count: Some(pool.min_count), max_count: Some(pool.max_count), drain_timeout: Some(pool.drain_timeout), } @@ -233,6 +235,7 @@ pub async fn run_from_env(use_autoscaler: bool) -> GlobalResult<()> { pool_type: Into::::into(pool_type) as i32, hardware: pool.hardware.into_iter().map(Into::into).collect::>(), desired_count: pool.desired_count, + min_count: pool.min_count, max_count: pool.max_count, drain_timeout: pool.drain_timeout, } diff --git a/svc/pkg/cluster/standalone/gc/tests/integration.rs b/svc/pkg/cluster/standalone/gc/tests/integration.rs index dc8a573fb..78c04ad03 100644 --- a/svc/pkg/cluster/standalone/gc/tests/integration.rs +++ b/svc/pkg/cluster/standalone/gc/tests/integration.rs @@ -112,6 +112,7 @@ async fn setup( provider_hardware: util_cluster::test::LINODE_HARDWARE.to_string(), }], desired_count: 0, + min_count: 0, max_count: 0, drain_timeout: DRAIN_TIMEOUT as u64, }]; diff --git a/svc/pkg/cluster/types/msg/datacenter-update.proto b/svc/pkg/cluster/types/msg/datacenter-update.proto index 994f83f66..cbd794dcf 100644 --- a/svc/pkg/cluster/types/msg/datacenter-update.proto +++ b/svc/pkg/cluster/types/msg/datacenter-update.proto @@ -20,6 +20,7 @@ message PoolUpdate { // Each can be optionally updated repeated rivet.backend.cluster.Hardware hardware = 2; optional uint32 desired_count = 3; + optional uint32 min_count = 6; optional uint32 max_count = 4; optional uint64 drain_timeout = 5; } diff --git a/svc/pkg/cluster/worker/src/workers/datacenter_create.rs b/svc/pkg/cluster/worker/src/workers/datacenter_create.rs index 03259a99c..2a7bf149e 100644 --- a/svc/pkg/cluster/worker/src/workers/datacenter_create.rs +++ b/svc/pkg/cluster/worker/src/workers/datacenter_create.rs @@ -11,11 +11,9 @@ async fn worker( let mut pools = ctx.pools.clone(); - // Cap the desired count below the max count + // Constrain the desired count for pool in &mut pools { - if pool.desired_count > pool.max_count { - pool.desired_count = pool.max_count; - } + pool.desired_count = pool.desired_count.max(pool.min_count).min(pool.max_count); } // Copy pools config to write to db diff --git a/svc/pkg/cluster/worker/src/workers/datacenter_scale.rs b/svc/pkg/cluster/worker/src/workers/datacenter_scale.rs index 3a953912e..ac2932d68 100644 --- a/svc/pkg/cluster/worker/src/workers/datacenter_scale.rs +++ b/svc/pkg/cluster/worker/src/workers/datacenter_scale.rs @@ -178,7 +178,7 @@ async fn inner( datacenter_id, provider: dc.provider, pool_type: unwrap!(backend::cluster::PoolType::from_i32(pool.pool_type)), - desired_count: pool.desired_count.min(pool.max_count) as usize, + desired_count: pool.desired_count.max(pool.min_count).min(pool.max_count) as usize, }; scale_servers(&ctx, tx, &mut msgs, &servers, &pool_ctx).await?; diff --git a/svc/pkg/cluster/worker/src/workers/datacenter_update.rs b/svc/pkg/cluster/worker/src/workers/datacenter_update.rs index e2c2e0697..9b819e1ca 100644 --- a/svc/pkg/cluster/worker/src/workers/datacenter_update.rs +++ b/svc/pkg/cluster/worker/src/workers/datacenter_update.rs @@ -36,6 +36,9 @@ async fn worker( if let Some(desired_count) = pool.desired_count { current_pool.desired_count = desired_count; } + if let Some(min_count) = pool.min_count { + current_pool.min_count = min_count; + } if let Some(max_count) = pool.max_count { current_pool.max_count = max_count; } diff --git a/svc/pkg/cluster/worker/tests/common.rs b/svc/pkg/cluster/worker/tests/common.rs index 4d2e2727c..35f0dc4d5 100644 --- a/svc/pkg/cluster/worker/tests/common.rs +++ b/svc/pkg/cluster/worker/tests/common.rs @@ -21,6 +21,7 @@ pub async fn setup(ctx: &TestCtx, opts: Setup) -> SetupRes { provider_hardware: util_cluster::test::LINODE_HARDWARE.to_string(), }], desired_count: 0, + min_count: 0, max_count: 0, drain_timeout: opts.drain_timeout, }]; diff --git a/svc/pkg/cluster/worker/tests/datacenter_update.rs b/svc/pkg/cluster/worker/tests/datacenter_update.rs index ad42f1a82..c1a6596bb 100644 --- a/svc/pkg/cluster/worker/tests/datacenter_update.rs +++ b/svc/pkg/cluster/worker/tests/datacenter_update.rs @@ -9,6 +9,7 @@ async fn datacenter_update(ctx: TestCtx) { pool_type: backend::cluster::PoolType::Ats as i32, hardware: Vec::new(), desired_count: 0, + min_count: 0, max_count: 0, drain_timeout: 0, }]; @@ -44,6 +45,7 @@ async fn datacenter_update(ctx: TestCtx) { pool_type: backend::cluster::PoolType::Ats as i32, hardware: Vec::new(), desired_count: Some(1), + min_count: None, max_count: None, drain_timeout: None, }], diff --git a/svc/pkg/cluster/worker/tests/server_taint.rs b/svc/pkg/cluster/worker/tests/server_taint.rs index 15f96a406..9cca2e30d 100644 --- a/svc/pkg/cluster/worker/tests/server_taint.rs +++ b/svc/pkg/cluster/worker/tests/server_taint.rs @@ -71,6 +71,7 @@ async fn datacenter_taint(ctx: TestCtx) { pool_type: backend::cluster::PoolType::Job as i32, hardware: Vec::new(), desired_count: Some(1), + min_count: None, max_count: Some(1), drain_timeout: None, }], @@ -113,6 +114,7 @@ async fn datacenter_taint(ctx: TestCtx) { pool_type: backend::cluster::PoolType::Job as i32, hardware: Vec::new(), desired_count: Some(0), + min_count: None, max_count: Some(0), drain_timeout: None, }],