Skip to content

Conversation

@mchoma
Copy link
Contributor

@mchoma mchoma commented Nov 10, 2025

Summary

This PR adds support for configuring memory resource requirements on BuildConfigs through XTF configuration properties.

Changes

  • BuildManagerConfig: Added xtf.bm.memory.request and xtf.bm.memory.limit configuration properties
  • BinaryBuild: Updated to apply ResourceRequirements when creating BuildConfig spec
  • BinarySourceBuild: Extended constructor to accept memory parameters
  • BinaryBuildTest: Added comprehensive tests for memory configuration scenarios
  • CLAUDE.md: Added project guidelines for AI-assisted development

Usage

Configure memory limits in test.properties or global-test.properties:

# Set build memory request to 2GB
xtf.bm.memory.request=2Gi

# Set build memory limit to 4GB
xtf.bm.memory.limit=4Gi

Backward Compatibility

Memory configuration is optional and backward compatible. When properties are not set, builds work as before without resource constraints.

Testing

All existing tests pass, and new tests verify:

  • Both request and limit set correctly
  • Only request set (limit null)
  • Only limit set (request null)
  • No memory config (resources null)

🤖 Generated with Claude Code on behalf of the current user

Summary by Sourcery

Add configurable memory resource settings to binary builds via XTF configuration properties, update build logic to apply and detect resource constraints, include tests for various memory scenarios and error statuses, and provide AI-assisted development guidelines.

New Features:

  • Support optional memory requests and limits for BuildConfigs via xtf.bm.memory.request and xtf.bm.memory.limit properties

Bug Fixes:

  • Consider builds in "Error" status as failed in needsUpdate logic

Enhancements:

  • Propagate memory configuration through BinaryBuild constructors and apply ResourceRequirements in BuildConfig spec
  • Add io.fabric8 openshift-server-mock dependency to the core module

Documentation:

  • Introduce CLAUDE.md guidelines for AI-assisted development

Tests:

  • Add BinaryBuildTest covering memory request/limit scenarios and build status handling

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 10, 2025

Reviewer's Guide

This PR adds optional, configurable memory requests and limits for BuildConfigs by extending the configuration and build classes, enhances failure detection, includes comprehensive tests and necessary test dependencies, and adds AI-assisted development guidelines.

Entity relationship diagram for BuildConfig resource requirements

erDiagram
    BUILD_CONFIG {
        string id
        string builderImage
        map envProperties
        string memoryRequest
        string memoryLimit
    }
    RESOURCE_REQUIREMENTS {
        string memoryRequest
        string memoryLimit
    }
    BUILD_CONFIG ||--|| RESOURCE_REQUIREMENTS : applies
Loading

Class diagram for updated BinaryBuild and BinaryBuildFromSources

classDiagram
    class BuildManagerConfig {
        +static String memoryRequest()
        +static String memoryLimit()
    }
    class BinaryBuild {
        -String memoryRequest
        -String memoryLimit
        +BinaryBuild(String builderImage, Path path, Map<String, String> envProperties, String id)
        +BinaryBuild(String builderImage, Path path, Map<String, String> envProperties, String id, String memoryRequest, String memoryLimit)
        -BuildConfig createBcDefinition()
    }
    class BinaryBuildFromSources {
        +BinaryBuildFromSources(String builderImage, Path path, Map<String, String> envProperties, String id)
        +BinaryBuildFromSources(String builderImage, Path path, Map<String, String> envProperties, String id, String memoryRequest, String memoryLimit)
    }
    BinaryBuildFromSources --|> BinaryBuild
    BinaryBuild ..> BuildManagerConfig : uses
Loading

File-Level Changes

Change Details Files
Enable configurable memory resource requirements
  • Define MEMORY_REQUEST and MEMORY_LIMIT properties and accessors in BuildManagerConfig
  • Add memoryRequest and memoryLimit fields and constructors in BinaryBuild
  • Apply ResourceRequirements in createBcDefinition when memory values are set
  • Add matching constructor in BinaryBuildFromSources
core/src/main/java/cz/xtf/core/config/BuildManagerConfig.java
core/src/main/java/cz/xtf/core/bm/BinaryBuild.java
core/src/main/java/cz/xtf/core/bm/BinaryBuildFromSources.java
Improve build status failure detection
  • Treat "Error" phase as failed in needsUpdate logic
core/src/main/java/cz/xtf/core/bm/BinaryBuild.java
Add tests and test dependency for memory scenarios
  • Include openshift-server-mock dependency for tests
  • Create BinaryBuildTest covering memory request/limit combinations and status checks
core/pom.xml
core/src/test/java/cz/xtf/core/bm/BinaryBuildTest.java
Introduce AI development guidelines
  • Add CLAUDE.md with project and Claude Code guidelines
CLAUDE.md

Possibly linked issues


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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Consider extracting the resource‐requirements construction into a shared helper method to avoid duplication and improve maintainability.
  • Verify whether other build implementations (e.g. GitBuild) should also accept memory request/limit parameters or document why they remain unchanged.
  • Replace raw phase strings like "Failed" and "Error" with constants or an enum to centralize phase definitions and prevent typos.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the resource‐requirements construction into a shared helper method to avoid duplication and improve maintainability.
- Verify whether other build implementations (e.g. GitBuild) should also accept memory request/limit parameters or document why they remain unchanged.
- Replace raw phase strings like "Failed" and "Error" with constants or an enum to centralize phase definitions and prevent typos.

## Individual Comments

### Comment 1
<location> `core/src/main/java/cz/xtf/core/bm/BinaryBuild.java:172-177` </location>
<code_context>
                 Build activeBuild = openShift.getBuild(id + "-" + activeBc.getStatus().getLastVersion());
                 if (activeBuild == null || activeBuild.getStatus() == null
-                        || "Failed".equals(activeBuild.getStatus().getPhase())) {
+                        || "Failed".equals(activeBuild.getStatus().getPhase())
+                        || "Error".equals(activeBuild.getStatus().getPhase())) {
                     log.debug("Build failed");
                     needsUpdate = true;
</code_context>

<issue_to_address>
**suggestion:** Additional build phase 'Error' is now considered for update, but other failure phases may exist.

Please review all possible build phases in OpenShift to ensure the update logic handles all terminal or problematic states, not just 'Failed' and 'Error'.

```suggestion
                // List of problematic/terminal build phases according to OpenShift docs
                Set<String> problematicPhases = new HashSet<>(Arrays.asList(
                        "Failed", "Error", "Cancelled"
                ));
                if (activeBuild == null || activeBuild.getStatus() == null
                        || problematicPhases.contains(activeBuild.getStatus().getPhase())) {
                    log.debug("Build failed or in problematic phase: {}", 
                        activeBuild != null && activeBuild.getStatus() != null ? activeBuild.getStatus().getPhase() : "unknown");
                    needsUpdate = true;
                }
```
</issue_to_address>

### Comment 2
<location> `core/src/test/java/cz/xtf/core/bm/BinaryBuildTest.java:71-80` </location>
<code_context>
+        openshift = OpenShifts.master();  // NOT static field!
+    }
+
+    @Test
+    void testDeployment() {
+        // Use builders to create resources
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding tests for invalid memory values.

Add test cases with invalid or malformed memory values to ensure the system responds appropriately, such as by ignoring them or raising clear exceptions.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 172 to 177
if (activeBuild == null || activeBuild.getStatus() == null
|| "Failed".equals(activeBuild.getStatus().getPhase())) {
|| "Failed".equals(activeBuild.getStatus().getPhase())
|| "Error".equals(activeBuild.getStatus().getPhase())) {
log.debug("Build failed");
needsUpdate = true;
}
Copy link

Choose a reason for hiding this comment

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

suggestion: Additional build phase 'Error' is now considered for update, but other failure phases may exist.

Please review all possible build phases in OpenShift to ensure the update logic handles all terminal or problematic states, not just 'Failed' and 'Error'.

Suggested change
if (activeBuild == null || activeBuild.getStatus() == null
|| "Failed".equals(activeBuild.getStatus().getPhase())) {
|| "Failed".equals(activeBuild.getStatus().getPhase())
|| "Error".equals(activeBuild.getStatus().getPhase())) {
log.debug("Build failed");
needsUpdate = true;
}
// List of problematic/terminal build phases according to OpenShift docs
Set<String> problematicPhases = new HashSet<>(Arrays.asList(
"Failed", "Error", "Cancelled"
));
if (activeBuild == null || activeBuild.getStatus() == null
|| problematicPhases.contains(activeBuild.getStatus().getPhase())) {
log.debug("Build failed or in problematic phase: {}",
activeBuild != null && activeBuild.getStatus() != null ? activeBuild.getStatus().getPhase() : "unknown");
needsUpdate = true;
}

Comment on lines 71 to 80
@Test
public void testNeedsUpdate_WhenBuildStatusIsError_ShouldReturnTrue() {
// Given: BuildConfig and ImageStream exist with a build in "Error" status
ImageStream imageStream = createImageStream(TEST_BUILD_ID);
BuildConfig buildConfig = createBuildConfig(TEST_BUILD_ID, 1);
Build build = createBuildWithStatus(TEST_BUILD_ID + "-1", "Error");

openShift.imageStreams().create(imageStream);
openShift.buildConfigs().create(buildConfig);
openShift.builds().create(build);
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Consider adding tests for invalid memory values.

Add test cases with invalid or malformed memory values to ensure the system responds appropriately, such as by ignoring them or raising clear exceptions.

@mchoma mchoma force-pushed the issue_624_bc_resource_limits branch 2 times, most recently from c90f11d to db79361 Compare November 10, 2025 16:45
CLAUDE.md Outdated
@@ -0,0 +1,209 @@
# CLAUDE.md
Copy link
Contributor

Choose a reason for hiding this comment

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

Could it be added in a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it just leaked from working directory into this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed from PR

This change adds support for setting memory resource requirements on
BuildConfigs through XTF configuration properties.

Changes:
- Added xtf.bm.memory.request and xtf.bm.memory.limit configuration
  properties to BuildManagerConfig
- Updated BinaryBuild to apply ResourceRequirements when creating
  BuildConfig spec
- Extended BinarySourceBuild constructor to accept memory parameters
- Added comprehensive tests for memory configuration scenarios

Memory configuration is optional and backward compatible. When not set,
builds work as before without resource constraints.

Example usage in test.properties:
  xtf.bm.memory.request=2Gi
  xtf.bm.memory.limit=4Gi

🤖 Generated with Claude Code on behalf of mchoma
@mchoma mchoma force-pushed the issue_624_bc_resource_limits branch from db79361 to 69ede18 Compare November 11, 2025 09:04
Copy link
Contributor

@mnovak mnovak left a comment

Choose a reason for hiding this comment

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

LGTM, merging.

@mnovak mnovak merged commit 808f581 into xtf-cz:master Nov 11, 2025
5 checks passed
@mchoma mchoma deleted the issue_624_bc_resource_limits branch November 11, 2025 10:20
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.

2 participants