Skip to content

Commit 35e66ab

Browse files
committed
fix: adujust to optimal replicas
1 parent c7e621e commit 35e66ab

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

rust/operator-binary/src/controller/build/resource/pdb.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ pub fn build_pdb(
4242
}
4343

4444
/// Total number of worker replicas across all worker role groups.
45+
///
46+
/// Role groups without an explicit replica count (i.e. those left to a HorizontalPodAutoscaler)
47+
/// contribute nothing, as their size is not known at reconcile time.
4548
fn worker_count(cluster: &ValidatedCluster) -> u16 {
4649
cluster
4750
.role_group_configs
4851
.get(&TrinoRole::Worker)
4952
.into_iter()
5053
.flat_map(|groups| groups.values())
51-
.map(|rg| rg.replicas)
54+
.filter_map(|rg| rg.replicas)
5255
.sum()
5356
}
5457

rust/operator-binary/src/controller/build/resource/statefulset.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,9 @@ pub fn build_rolegroup_statefulset(
459459
.build(),
460460
spec: Some(StatefulSetSpec {
461461
pod_management_policy: Some("Parallel".to_string()),
462-
replicas: Some(i32::from(role_group_config.replicas)),
462+
// Forward `None` when the user did not set `replicas`, leaving the field unset on the
463+
// StatefulSet so a HorizontalPodAutoscaler can own the replica count.
464+
replicas: role_group_config.replicas.map(i32::from),
463465
selector: LabelSelector {
464466
match_labels: Some(
465467
cluster

rust/operator-binary/src/controller/validate.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,11 @@ pub fn validate(
291291

292292
/// Adapts the validated [`RoleGroup`] produced by [`with_validated_config`] into the flattened
293293
/// [`TrinoRoleGroupConfig`] consumed by the build steps.
294-
///
295-
/// Upstream `with_validated_config` returns a [`RoleGroup`] with a `HashMap` of env overrides and an
296-
/// optional replica count; this converts it to the ergonomic [`RoleGroupConfig`] with an
297-
/// [`EnvVarSet`] and a concrete replica count (defaulting to 1).
298294
fn into_role_group_config(
299295
merged: RoleGroup<v1alpha1::TrinoConfig, JavaCommonConfig, v1alpha1::TrinoConfigOverrides>,
300296
vector_aggregator_config_map_name: &Option<ConfigMapName>,
301297
) -> Result<TrinoRoleGroupConfig> {
302-
let replicas = merged.replicas.unwrap_or(1);
298+
let replicas = merged.replicas;
303299
let common = merged.config;
304300

305301
let mut env_overrides = EnvVarSet::new();
@@ -383,7 +379,7 @@ mod tests {
383379
);
384380
assert_eq!(
385381
validated.role_group_configs[&TrinoRole::Coordinator]["default"].replicas,
386-
1
382+
Some(1)
387383
);
388384
}
389385
}

0 commit comments

Comments
 (0)