Skip to content

feat(operator): Add Role::{fixed,estimated}_replica_count#1241

Open
sbernauer wants to merge 7 commits into
mainfrom
feat/replica-count-calculation
Open

feat(operator): Add Role::{fixed,estimated}_replica_count#1241
sbernauer wants to merge 7 commits into
mainfrom
feat/replica-count-calculation

Conversation

@sbernauer

@sbernauer sbernauer commented Jul 2, 2026

Copy link
Copy Markdown
Member

Description

Needed for stackabletech/nifi-operator#953, we can then also use it in https://github.com/stackabletech/trino-operator/blob/3158402b23edde1633b2639eb50c67bb1b41889c/rust/operator-binary/src/crd/mod.rs#L918

Definition of Done Checklist

  • Not all of these items are applicable to all PRs, the author should update this template to only leave the boxes in that are relevant
  • Please make sure all these things are done and tick the boxes

Author

  • Changes are OpenShift compatible
  • CRD changes approved
  • CRD documentation for all fields, following the style guide.
  • Integration tests passed (for non trivial changes)
  • Changes need to be "offline" compatible

Reviewer

  • Code contains useful comments
  • Code contains useful logging statements
  • (Integration-)Test cases added
  • Documentation added or updated. Follows the style guide.
  • Changelog updated
  • Cargo.toml only contains references to git tags (not specific commits or branches)

Acceptance

  • Feature Tracker has been updated
  • Proper release label has been added

@sbernauer sbernauer changed the title Feat/replica count calculation feat: Add Role::fixed_replica_count and Role::estimated_replica_count helper functions Jul 2, 2026
@sbernauer sbernauer changed the title feat: Add Role::fixed_replica_count and Role::estimated_replica_count helper functions feat: Add Role::fixed_replica_count and Role::estimated_replica_count Jul 2, 2026
@sbernauer sbernauer self-assigned this Jul 2, 2026
@sbernauer sbernauer moved this to Development: Waiting for Review in Stackable Engineering Jul 2, 2026
Comment thread crates/stackable-operator/src/role_utils.rs Outdated
Comment on lines +415 to +416
/// This is the case when all `replicas` are set to [`Some<u16>`], in which case they are simply
/// summed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This especially mentions all replicas fields. The function however doesn't assert that this is actually the case in all role groups.

So either this comment needs adjusting, or the function body needs to change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As soon as a single rolegroup has None (or 0 for that matter), None is returned. See your other comment in https://github.com/stackabletech/operator-rs/pull/1241/changes#r3512315258

// The individual replicas are [`u16`]s, so a [`u32`] sum has plenty of space.
Some(replicas) => Some(u32::from(replicas)),
})
.sum()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm curious: Does sum flatten the Options produced by the map above?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sum on an iterator of Options returns None if there is at least one None present in the iterator. If all are Some the sum is returned.

E.g. the replica_counts_with_one_replica_unset test showcases this

@Techassi Techassi moved this from Development: Waiting for Review to Development: In Review in Stackable Engineering Jul 2, 2026
@Techassi Techassi changed the title feat: Add Role::fixed_replica_count and Role::estimated_replica_count feat(operator): Add Role::{fixed,estimated}_replica_count Jul 2, 2026
Co-authored-by: Techassi <git@techassi.dev>
@sbernauer sbernauer requested a review from Techassi July 2, 2026 10:29
fn replica_counts_with_all_replicas_set() {
let role = construct_role_with_replicas([Some(3), Some(2), Some(5)]);

assert_eq!(role.fixed_replica_count(false), Some(10));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe it's just me and this is non-blocking but these kinds of "true/false" boolean parameters are annoying. What does it mean? I now need to check the function. Can we use an enum ZeroReplicas instead? TreatAsNone vs. Count or something like that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I had the same idea but wondered if this is an overkill: d3cc0a2

@sbernauer sbernauer requested a review from lfrancke July 2, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Development: In Review

Development

Successfully merging this pull request may close these issues.

3 participants