Skip to content

bug: Update bulk config to support the datasources for both kind and openshift cluster - #51

Merged
chandrams merged 2 commits into
kruize:mvp_demofrom
kusumachalasani:config-update
Oct 28, 2026
Merged

chandrams merged 2 commits into
kruize:mvp_demofrom
kusumachalasani:config-update

Conversation

@kusumachalasani

@kusumachalasani kusumachalasani commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Update bulk config to support the datasources for both kind and openshift cluster

  • Bulk config datasource is an ordered list, and based on the available datasources registered in kruize, the datasource gets picked.
  • This ensures the right datasource is selected while triggering the bulk jobs.
  • For openshift it is thanos-1 , and for kind it is prometheus-1

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:

  • Support platform-independent bulk configuration by selecting a registered datasource from an ordered preference list.

Bug Fixes:

  • Ensure bulk jobs use a valid datasource for both OpenShift and kind clusters, with a fallback to an available datasource when no preference matches.

Signed-off-by: kusuma chalasani <kchalasani@ibm.com>
@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Bulk 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 resolution

sequenceDiagram
    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)
Loading

File-Level Changes

Change Details Files
Resolve bulk-config datasource preferences against datasources registered in Kruize before installation.
  • Inject the datasource service and collect registered datasource names.
  • Select the first available datasource from the ordered preference list.
  • Replace the bulk config list with the single datasource supported by bulk jobs.
  • Fall back to the first registered datasource and log an actionable error when no preference matches.
  • Add or update the default bulk configuration to provide platform-independent datasource preferences.
src/main/java/com/kruize/optimizer/service/ProfileService.java
src/main/resources/configs/v1.0/bulk-configs/default-bulk-config.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Signed-off-by: kusuma chalasani <kchalasani@ibm.com>
@kusumachalasani

Copy link
Copy Markdown
Contributor Author

@sourcery-ai review

@kusumachalasani kusumachalasani moved this to Under Review in Monitoring Oct 27, 2026
@kusumachalasani kusumachalasani added the bug Something isn't working label Oct 27, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@kusumachalasani kusumachalasani changed the title Update bulk config to support the datasources for both kind and openshift cluster bug: Update bulk config to support the datasources for both kind and openshift cluster Oct 28, 2026

@chandrams chandrams left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@chandrams
chandrams merged commit 1aacef5 into kruize:mvp_demo Oct 28, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from Under Review to Done in Monitoring Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants