Skip to content

Ability to trigger auto rebalance on imbalance feature - #13037

Open
ShubhamRwt wants to merge 10 commits into
strimzi:mainfrom
ShubhamRwt:autoRebalanceFeature
Open

Ability to trigger auto rebalance on imbalance feature #13037
ShubhamRwt wants to merge 10 commits into
strimzi:mainfrom
ShubhamRwt:autoRebalanceFeature

Conversation

@ShubhamRwt

@ShubhamRwt ShubhamRwt commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Type of change

  • New feature

Description

This PR implements the proposal auto-rebalance-on-imbalance. This feature allows the operator to trigger rebalance automatically in case their are some imbalance in the cluster

Checklist

Please go through this checklist and make sure all applicable tasks have been done

  • Update documentation
  • Update CHANGELOG.md (if present)
  • Reference relevant issue(s) and close them after merging
  • Write tests
  • Make sure all tests pass
  • Try your changes inside a Kubernetes cluster, not just from unit tests
  • AI assistance was used to create this PR (see the Strimzi AI policy)

@snyk-io

snyk-io Bot commented Aug 7, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@scholzj scholzj added this to the 1.3.0 milestone Aug 7, 2026
@ppatierno

Copy link
Copy Markdown
Member

@ShubhamRwt can we get a green build before starting for an early review please? Failure are around the CruiseControlReconciler so maybe something to fix in the logic before taking a look. Thanks :-)

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.67139% with 100 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.72%. Comparing base (f6776c2) to head (3ac94ed).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...rator/assembly/KafkaAutoRebalancingReconciler.java 75.35% 25 Missing and 10 partials ⚠️
...r/resource/cruisecontrol/CruiseControlApiImpl.java 46.55% 19 Missing and 12 partials ⚠️
.../assembly/KafkaAutoRebalanceImbalanceDetector.java 84.87% 10 Missing and 8 partials ⚠️
...imzi/operator/common/metrics/AnomalyMetricKey.java 0.00% 12 Missing ⚠️
...urce/cruisecontrol/CruiseControlStateResponse.java 50.00% 1 Missing and 1 partial ⚠️
...uster/operator/assembly/KafkaAssemblyOperator.java 50.00% 1 Missing ⚠️
...strimzi/operator/common/metrics/MetricsHolder.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #13037      +/-   ##
============================================
- Coverage     80.93%   80.72%   -0.21%     
- Complexity     6741     6821      +80     
============================================
  Files           355      358       +3     
  Lines         23072    23414     +342     
  Branches       3148     3185      +37     
============================================
+ Hits          18673    18902     +229     
- Misses         3175     3251      +76     
- Partials       1224     1261      +37     
Files with missing lines Coverage Δ
...r/assembly/KafkaAssemblyOperatorMetricsHolder.java 100.00% <100.00%> (ø)
...perator/assembly/KafkaRebalanceConfigMapUtils.java 83.33% <100.00%> (ø)
...ator/resource/cruisecontrol/GoalViolationInfo.java 100.00% <100.00%> (ø)
...uster/operator/assembly/KafkaAssemblyOperator.java 84.17% <50.00%> (-0.31%) ⬇️
...strimzi/operator/common/metrics/MetricsHolder.java 30.18% <0.00%> (-0.59%) ⬇️
...urce/cruisecontrol/CruiseControlStateResponse.java 71.42% <50.00%> (-28.58%) ⬇️
...imzi/operator/common/metrics/AnomalyMetricKey.java 0.00% <0.00%> (ø)
.../assembly/KafkaAutoRebalanceImbalanceDetector.java 84.87% <84.87%> (ø)
...r/resource/cruisecontrol/CruiseControlApiImpl.java 69.93% <46.55%> (-6.20%) ⬇️
...rator/assembly/KafkaAutoRebalancingReconciler.java 76.50% <75.35%> (-5.00%) ⬇️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ShubhamRwt

Copy link
Copy Markdown
Contributor Author

@ppatierno All the tests seems to be passing now

@ppatierno ppatierno left a comment

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.

@ShubhamRwt I had a first quick pass but it needs more detailed review.

@ShubhamRwt
ShubhamRwt force-pushed the autoRebalanceFeature branch 2 times, most recently from dcb35bc to 6ce0247 Compare September 1, 2026 10:35
Signed-off-by: ShubhamRwt <shubhamrwt02@gmail.com>
Signed-off-by: ShubhamRwt <shubhamrwt02@gmail.com>
Signed-off-by: ShubhamRwt <shubhamrwt02@gmail.com>
Signed-off-by: ShubhamRwt <shubhamrwt02@gmail.com>
Signed-off-by: ShubhamRwt <shubhamrwt02@gmail.com>
Signed-off-by: ShubhamRwt <shubhamrwt02@gmail.com>
Signed-off-by: ShubhamRwt <shubhamrwt02@gmail.com>
Signed-off-by: ShubhamRwt <shubhamrwt02@gmail.com>
Signed-off-by: ShubhamRwt <shubhamrwt02@gmail.com>
@ShubhamRwt
ShubhamRwt marked this pull request as ready for review September 9, 2026 08:58
@ShubhamRwt
ShubhamRwt marked this pull request as draft September 9, 2026 08:59
Signed-off-by: ShubhamRwt <shubhamrwt02@gmail.com>
@ShubhamRwt
ShubhamRwt marked this pull request as ready for review September 9, 2026 12:30
@ShubhamRwt

Copy link
Copy Markdown
Contributor Author

This PR is now ready for review

});
} else {
LOGGER.infoCr(reconciliation, "Rebalancing completed, transitioning to Idle");
return updateRebalanceCompletionTime()

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.

we are updating the rebalance completion time when the rebalancing completed but how does it relate with the proposal where at some point we said:

The ConfigMap's lastRebalanceCompletionTime now reflects the failure timestamp

So it looks like the timestamp should be updated when there is a failure too?

* @return CompletionStage with GoalViolationInfo if violations detected, null otherwise
*/
public CompletionStage<GoalViolationInfo> checkForGoalViolations() {
if (kafkaCr.getSpec() == null || kafkaCr.getSpec().getCruiseControl() == null) {

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.

why are we checking the CC is configured, I would assume this code at this deep level won't be never reached if CC is not configured. I mean, why I should check for goal violations if CC is not even configured?


if (imbalanceConfig.isEmpty()) {
return CompletableFuture.completedFuture(null);
}

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.

The same applies to the above checks, why should I check for goal violation if auto-rebalance is not configured? Should this being called only when we are sure CC is enabled in the Kafka CR? Maybe a check would be needed somewhere in a upper level within the code?

return supplier.secretOperations.getAsync(reconciliation.namespace(), CruiseControlResources.secretName(reconciliation.name()))
.thenCompose(ccSecret -> {
if (ccSecret == null) {
LOGGER.warnCr(reconciliation, "Cruise Control secret not found, skipping anomaly detection");

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.

The log is misleading, we are not skipping anomaly detection. We tried to detect anomalies but it failed because for some reason the CC Secret is not available. I would more use:

Cruise Control secret not found, goal violations cannot be detected

}

return supplier.secretOperations.getAsync(reconciliation.namespace(), CruiseControlResources.apiSecretName(reconciliation.name()))
.thenCompose(ccApiSecret -> {

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.

We checked for ccSecret to be null before but we are not doing the same here for ccApiSecret, why?

- DiskCapacityGoal
- DiskUsageDistributionGoal
skipHardGoalCheck: true
----

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.

you should take a look on this approved proposal https://github.com/strimzi/proposals/blob/main/154-kafkarebalance-custom-resource-consolidation.md that should be land at some point.
If it comes first, we need to update the examples with the new KafkaRebalance API.


The operator tracks rebalance completion times in a ConfigMap named `<cluster_name>-auto-rebalance-imbalance-tracker`.
This prevents the operator from retriggering rebalances for anomalies that were already addressed by a previous rebalance.
The ConfigMap is automatically managed by the operator and deleted when the Kafka cluster is deleted.

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 an example of the ConfigMap structure would be useful.


== Failure recovery

If an auto-rebalance fails (the `KafkaRebalance` transitions to `NotReady`), the operator transitions back to `Idle` and deletes the failed resource.

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.

the operator transitions back to Idle

What is transitioning to Idle? The operator itself doesn't have Idle state. What are you referring to?


If an auto-rebalance fails (the `KafkaRebalance` transitions to `NotReady`), the operator transitions back to `Idle` and deletes the failed resource.
The operator does not immediately retry.
If the underlying issue persists, Cruise Control detects the goal violation again in the next anomaly detection cycle and a fresh rebalance is triggered.

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.

It's related to what I already mention about the detection interval in CC. It's different from the reconciliation period. This sentence let the user thinks that a new rebalance triggers when CC detect an anomaly while it's not true. It triggers when the operator ask to CC for anomaly on the next reconciliation.

If the underlying issue persists, Cruise Control detects the goal violation again in the next anomaly detection cycle and a fresh rebalance is triggered.

If the operator crashes while in `RebalanceOnImbalance` state, on restart it resumes monitoring from the current state.
If the `KafkaRebalance` resource is missing (for example, deleted while the operator was not running), the operator transitions to `Idle` and relies on Cruise Control's next anomaly detection cycle to retrigger if violations persist.

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.

Still this ...

operator transitions to Idle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants