Repository navigation
bug: Update bulk config to support the datasources for both kind and openshift cluster - #51
Conversation
Signed-off-by: kusuma chalasani <kchalasani@ibm.com>
Reviewer's GuideBulk configuration installation now resolves an ordered datasource preference list against the datasources registered in Kruize, selecting the appropriate datasource for Kind or OpenShift and providing a logged fallback when no preferred datasource is available. Sequence diagram for bulk config datasource resolutionsequenceDiagram
participant ProfileService
participant DatasourceService
participant KruizeClient
ProfileService->>ProfileService: convertValue(profileDefinition, BulkConfig.class)
ProfileService->>DatasourceService: getDatasources()
DatasourceService-->>ProfileService: registered Datasource names
ProfileService->>ProfileService: select first matching preferred datasource
alt preferred datasource is registered
ProfileService->>ProfileService: setDatasources([resolved])
else no preferred datasource is registered
ProfileService->>ProfileService: setDatasources([available.get(0)])
ProfileService->>ProfileService: LOG.errorf(...)
end
ProfileService->>KruizeClient: createBulkConfig(bulkConfig)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/main/java/com/kruize/optimizer/service/ProfileService.java" line_range="338" />
<code_context>
+ .orElse(null);
+
+ if (resolved == null) {
+ resolved = preferred.get(0);
+ LOG.errorf("None of the datasources %s of bulk config '%s' are registered in Kruize (available: %s); "
+ + "installing the config with '%s'. Bulk jobs for it will fail until a listed datasource "
</code_context>
<issue_to_address>
**Bulk jobs use an unregistered datasource**
When no preferred datasource is registered when the config is installed and a matching datasource registers later, `resolveBulkConfigDatasource` saves the first preference even though Kruize has not registered it, and `installMissingProfiles` skips the config by name on later runs, so the saved datasource is not corrected and bulk jobs fail.
Do not install the config with an unregistered fallback, and re-resolve and update it when datasource availability changes.
</issue_to_address>
### Comment 2
<location path="src/main/java/com/kruize/optimizer/service/ProfileService.java" line_range="305" />
<code_context>
- kruizeClient.createBulkConfig(
- objectMapper.convertValue(profileDefinition, BulkConfig.class));
+ BulkConfig bulkConfig = objectMapper.convertValue(profileDefinition, BulkConfig.class);
+ resolveBulkConfigDatasource(bulkConfig);
+ kruizeClient.createBulkConfig(bulkConfig);
break;
</code_context>
<issue_to_address>
**Existing configs keep the old datasource**
When the default bulk config was installed before this version or its registered datasource changes, `installMissingProfiles` skips configs whose names are already installed, so it never calls `resolveBulkConfigDatasource` or updates the stored config; `BulkConfigService` continues submitting the old datasource and bulk jobs fail.
Reconcile already-installed bulk configs with the resolved datasource during profile installation.
Also at `src/main/java/com/kruize/optimizer/service/ProfileService.java:306`, `src/main/java/com/kruize/optimizer/service/ProfileService.java:347`.
</issue_to_address>
### Comment 3
<location path="src/main/java/com/kruize/optimizer/service/ProfileService.java" line_range="332-335" />
<code_context>
+ .map(Datasource::getName)
+ .collect(Collectors.toSet());
+
+ String resolved = preferred.stream()
+ .filter(available::contains)
+ .findFirst()
+ .orElse(null);
+
+ if (resolved == null) {
</code_context>
<issue_to_address>
**Kind can choose Thanos**
When both `thanos-1` and `prometheus-1` are registered in a kind deployment, the ordered list selects `thanos-1` before `prometheus-1`, so a kind deployment with both registered installs a config that uses Thanos instead of its configured default, `prometheus-1`.
Order preferences per deployment or prioritize the configured default datasource before applying the fallback preference list.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 3 findings to address first, and the installed bulk config is persisted with only the first registered preferred datasource, so a mistaken match can make bulk jobs read from the wrong source or fail. Reverting the code does not restore configs already installed, but those configs can be updated or reinstalled.
Blocking findings: src/main/java/com/kruize/optimizer/service/ProfileService.java:338, src/main/java/com/kruize/optimizer/service/ProfileService.java:305, src/main/java/com/kruize/optimizer/service/ProfileService.java:335
Signed-off-by: kusuma chalasani <kchalasani@ibm.com>
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/main/java/com/kruize/optimizer/service/ProfileService.java" line_range="340" />
<code_context>
+ .orElse(null);
+
+ if (resolved == null) {
+ resolved = available.get(0);
+ LOG.errorf("None of the datasources %s of bulk config '%s' are registered in Kruize (registered: %s). "
+ + "Continuing the install with the registered datasource '%s'. Update the bulk config "
</code_context>
<issue_to_address>
**Default bulk config is not installed**
When kruize has no registered datasources while the bulk config has preferred datasource names, `available.get(0)` throws `IndexOutOfBoundsException`, so `installProfile` fails and `installMissingProfiles` records the config as failed; the default config and its scheduled jobs remain unavailable.
Handle an empty `available` list before selecting a datasource, and report or defer installation without indexing into it.
Also at `src/main/java/com/kruize/optimizer/service/ProfileService.java:338`, `src/main/java/com/kruize/optimizer/service/ProfileService.java:341`.
</issue_to_address>
### Comment 2
<location path="src/main/java/com/kruize/optimizer/service/ProfileService.java" line_range="350" />
<code_context>
}
}
</code_context>
<issue_to_address>
**Scheduled jobs keep a stale datasource**
When the datasource selected during installation is later removed while another preferred datasource is registered, `convertConfigToBulkJob` uses the stored datasource as-is, so scheduled jobs keep submitting the removed datasource and fail.
Resolve and update the config's datasource before converting it to a bulk job.
</issue_to_address>
### Comment 3
<location path="src/main/java/com/kruize/optimizer/service/ProfileService.java" line_range="340" />
<code_context>
+ .orElse(null);
+
+ if (resolved == null) {
+ resolved = available.get(0);
+ LOG.errorf("None of the datasources %s of bulk config '%s' are registered in Kruize (registered: %s). "
+ + "Continuing the install with the registered datasource '%s'. Update the bulk config "
</code_context>
<issue_to_address>
**Unrelated datasource gets selected**
When kruize registers a datasource, but none of the config's preferred datasources is registered, the fallback selects the first registered datasource even when it is not one of the config's preferences or a datasource for the intended cluster; the config is installed with it and bulk jobs can query the wrong data source.
Do not install with an arbitrary datasource; defer installation or require an explicitly validated fallback.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 3 findings to address first, and if none of the preferred datasource names are registered, the code selects the first registered datasource, which may contain unrelated telemetry and produce inaccurate bulk results. The selected datasource is stored in the created config, but it can be corrected and the results rerun; reverting this code alone would not undo configs already created.
Blocking findings: src/main/java/com/kruize/optimizer/service/ProfileService.java:340, src/main/java/com/kruize/optimizer/service/ProfileService.java:350, src/main/java/com/kruize/optimizer/service/ProfileService.java:340
Update bulk config to support the datasources for both kind and openshift cluster
Summary by Sourcery
Resolve each bulk configuration to the first matching registered datasource before installation so bulk jobs run with the appropriate cluster datasource.
New Features:
Bug Fixes: