Skip to content

Conversation

@kanovotn
Copy link
Contributor

@kanovotn kanovotn commented Jan 7, 2026

Upgrade Fabric8 OpenShift Client to 7.4.0

Summary

Upgrades Fabric8 OpenShift Client from 6.14.0 to 7.4.0 and migrates affected tests.

Changes

  • Upgraded openshift-client to 7.4.0
  • Removed openshift-server-mock dependency (removed in Fabric8 7.4.0)
  • Added Mockito 5.8.0 for test mocking
  • Fixed DockerImageMetadata.java API compatibility (GenericKubernetesResource)

Test Migrations

  • BinaryBuildTest: Migrated to Mockito, separated memory tests into BinaryBuildMemoryTest
  • BasicOpenShiftTest: Replaced with BuildersTest using pure unit tests (no mocking needed)

Summary by Sourcery

Upgrade Fabric8 OpenShift client to 7.4.0 and migrate dependent tests and utilities away from the removed server mock APIs.

Enhancements:

  • Adjust DockerImageMetadata to use GenericKubernetesResource additional properties for image metadata with the newer Fabric8 API.
  • Refactor BinaryBuild tests to use Mockito-based mocking of the OpenShift client fluent API instead of OpenShiftServer.
  • Split BinaryBuild memory-related configuration assertions into a dedicated BinaryBuildMemoryTest for clearer, focused coverage.
  • Replace the OpenShiftServer-based BasicOpenShiftTest with BuildersTest that unit-tests resource builders without a server mock.

Build:

  • Bump io.fabric8 openshift-client dependency to version 7.4.0 in the parent POM.
  • Introduce Mockito (core and JUnit Jupiter) as test dependencies and remove the obsolete openshift-server-mock dependencies from modules.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 7, 2026

Reviewer's Guide

Upgrades Fabric8 OpenShift client to 7.4.0, removes the deprecated server-mock in favor of Mockito-based tests, adjusts Docker image metadata handling to the new API, and refactors tests to be pure unit tests or to use explicit client DSL mocking.

Sequence diagram for DockerImageMetadata.getMetadataFromTag with new Fabric8 API

sequenceDiagram
participant Caller
participant DockerImageMetadata
participant ImageStreamTag
participant Image
participant GenericKubernetesResource

Caller->>DockerImageMetadata: getMetadataFromTag(imageStreamTag)
DockerImageMetadata->>DockerImageMetadata: areMetadataForImageReady(imageStreamTag)
alt metadata ready
  DockerImageMetadata->>ImageStreamTag: getImage()
  ImageStreamTag-->>DockerImageMetadata: Image
  DockerImageMetadata->>Image: getDockerImageMetadata()
  Image-->>DockerImageMetadata: GenericKubernetesResource
  DockerImageMetadata->>GenericKubernetesResource: getAdditionalProperties()
  GenericKubernetesResource-->>DockerImageMetadata: MapStringObject
  DockerImageMetadata-->>Caller: DockerImageMetadata
else metadata not ready
  DockerImageMetadata-->>Caller: null
end
Loading

Class diagram for updated DockerImageMetadata metadata handling

classDiagram

class DockerImageMetadata {
  +DockerImageMetadata(MapStringObject data)
  +static DockerImageMetadata getMetadata(OpenShift openShift, Image image)
  -static DockerImageMetadata getMetadataFromTag(ImageStreamTag imageStreamTag)
  -static boolean areMetadataForImageReady(ImageStreamTag tag)
}

class ImageStreamTag {
  +Image getImage()
}

class Image {
  +GenericKubernetesResource getDockerImageMetadata()
}

class GenericKubernetesResource {
  +MapStringObject getAdditionalProperties()
}

DockerImageMetadata ..> ImageStreamTag : uses
ImageStreamTag --> Image : contains
Image --> GenericKubernetesResource : dockerImageMetadata
DockerImageMetadata ..> GenericKubernetesResource : reads metadata
Loading

File-Level Changes

Change Details Files
Upgrade Fabric8 OpenShift client and adjust DockerImageMetadata to new dockerImageMetadata representation.
  • Bump OpenShift client version property from 6.14.0 to 7.4.0 in the parent POM.
  • Remove openshift-server-mock dependency from parent, core, and builder modules as it is no longer available.
  • Switch DockerImageMetadata to treat dockerImageMetadata as a GenericKubernetesResource and read additionalProperties instead of calling getValue() and casting a Map.
  • Relax DockerImageMetadata readiness check to only assert non-null dockerImageMetadata, without checking its internal value field.
pom.xml
core/pom.xml
builder/pom.xml
junit5/src/main/java/cz/xtf/junit5/model/DockerImageMetadata.java
Migrate BinaryBuildTest from Fabric8 OpenShiftServer to Mockito-based mocking and split out memory-related tests.
  • Replace OpenShiftServer-based test setup with JUnit 5 Mockito extension and @mock fields for OpenShift and the relevant MixedOperation/Resource DSL types.
  • Stub OpenShift fluent API methods (buildConfigs(), imageStreams(), withName(), get()) via a dedicated setupResourceMocks helper to simulate presence/absence of BuildConfig and ImageStream.
  • Use lenient stubbing for conditional openShift.getBuild(...) calls and verify interactions in status-related tests.
  • Remove memory/resource-related assertions from BinaryBuildTest and move them into a new BinaryBuildMemoryTest class that configures BuildManagerConfig system properties and asserts BuildConfig.resources content.
  • Ensure BinaryBuildMemoryTest cleans relevant system properties in a @beforeeach method and after each scenario to avoid cross-test contamination.
core/src/test/java/cz/xtf/core/bm/BinaryBuildTest.java
core/src/test/java/cz/xtf/core/bm/BinaryBuildMemoryTest.java
Replace OpenShiftServer-based smoke tests with pure builder unit tests and add Mockito test dependencies.
  • Remove builder module’s usage of openshift-server-mock and delete BasicOpenShiftTest which depended on a mocked OpenShift server.
  • Add mockito-core and mockito-junit-jupiter as managed dependencies in the parent POM and as test-scoped dependencies in the core module POM to support Mockito-based unit tests.
  • Introduce BuildersTest as a pure unit test that validates ConfigMapBuilder and DeploymentConfigBuilder outputs without talking to an OpenShift client.
  • Verify in BuildersTest that ConfigMap and DeploymentConfig objects have expected names, labels, data entries, replicas, strategies, and an empty container list in the generated PodSpec.
pom.xml
core/pom.xml
builder/pom.xml
builder/src/test/java/cz/xtf/builder/openshift/smoke/BuildersTest.java
builder/src/test/java/cz/xtf/builder/openshift/mocked/smoke/BasicOpenShiftTest.java

Possibly linked issues

  • #(not specified): PR performs the requested OpenShift client upgrade to 7.4.0 and adapts tests and dependencies accordingly.

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 - I've found 1 issue, and left some high level feedback:

  • In DockerImageMetadata.getMetadataFromTag, the unchecked cast to GenericKubernetesResource assumes the implementation type of getDockerImageMetadata(); consider guarding with an instanceof check (or handling alternative types) to avoid a potential ClassCastException if Fabric8 changes the underlying object again.
  • BinaryBuildMemoryTest repeats System property cleanup and XTFConfig.loadConfig() both in @beforeeach and in each test’s finally block; centralizing this reset logic (e.g., in an @AfterEach helper) would reduce duplication and lower the risk of inconsistent configuration between tests.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In DockerImageMetadata.getMetadataFromTag, the unchecked cast to GenericKubernetesResource assumes the implementation type of getDockerImageMetadata(); consider guarding with an instanceof check (or handling alternative types) to avoid a potential ClassCastException if Fabric8 changes the underlying object again.
- BinaryBuildMemoryTest repeats System property cleanup and XTFConfig.loadConfig() both in @BeforeEach and in each test’s finally block; centralizing this reset logic (e.g., in an @AfterEach helper) would reduce duplication and lower the risk of inconsistent configuration between tests.

## Individual Comments

### Comment 1
<location> `builder/src/test/java/cz/xtf/builder/openshift/smoke/BuildersTest.java:37-46` </location>
<code_context>
-        // arrange
-        final String dataEntryKey = "test.properties";
-        final String dataEntryValue = "foo=bar";
-        final ConfigMap configMap = new ConfigMapBuilder(TEST_CONFIGMAP_NAME)
-                .addLabels(TEST_RESOURCE_LABELS)
-                .configEntry(dataEntryKey, dataEntryValue)
</code_context>

<issue_to_address>
**suggestion (testing):** Extend builder tests to assert labels (and potentially triggers) to better cover builder behavior

Currently these tests only assert name/data for `ConfigMap` and a few fields for `DeploymentConfig`. Since labels are part of the builder contract (and you pass `TEST_RESOURCE_LABELS`), please also assert that these labels are present in `metadata.labels` for both resources. For `DeploymentConfigBuilder`, also verify that the image change trigger configured via `onImageChange()` appears in `.spec.triggers` with the expected type, so these tests fully cover the intended builder behavior and can reliably replace `BasicOpenShiftTest`.

Suggested implementation:

```java
        Assertions.assertEquals(TEST_CONFIGMAP_NAME,
                configMap.getMetadata().getName(),
                "ConfigMap resource has unexpected name.");
        Assertions.assertEquals(TEST_RESOURCE_LABELS,
                configMap.getMetadata().getLabels(),
                "ConfigMap resource has unexpected labels.");

```

To fully implement the requested coverage for the `DeploymentConfigBuilder` as per your review comment, make the following changes in the same test class, inside the `testDeploymentConfigBuilder` (or equivalent) method that builds and asserts the `DeploymentConfig`:

1. **Assert labels on the DeploymentConfig metadata**

   After the existing assertion that checks the DeploymentConfig name (and before or after the replicas assertion), add:

   ```java
   Assertions.assertEquals(TEST_RESOURCE_LABELS,
           deploymentConfig.getMetadata().getLabels(),
           "DeploymentConfig resource has unexpected labels.");
   ```

   This assumes the variable holding the built resource is named `deploymentConfig`. Adjust the variable name if different.

2. **Assert the presence of the ImageChange trigger**

   After the basic structural assertions (name, replicas, etc.), add assertions that verify the `ImageChange` trigger created by `.onImageChange()` is present in `.spec.triggers`:

   ```java
   Assertions.assertNotNull(deploymentConfig.getSpec(), "DeploymentConfig spec should not be null.");
   Assertions.assertNotNull(deploymentConfig.getSpec().getTriggers(), "DeploymentConfig triggers should not be null.");

   boolean hasImageChangeTrigger = deploymentConfig.getSpec().getTriggers()
           .stream()
           .anyMatch(trigger -> "ImageChange".equals(trigger.getType()));

   Assertions.assertTrue(hasImageChangeTrigger,
           "DeploymentConfig should contain an ImageChange trigger configured via onImageChange().");
   ```

   If your test currently doesn’t import `java.util.stream.*` or similar, no extra imports are needed because `stream()` is available on `List`. Ensure the `deploymentConfig` type is `io.fabric8.openshift.api.model.DeploymentConfig` (or compatible) so `getSpec().getTriggers()` and `getType()` on the trigger objects are available.

These additions will ensure the tests cover both label propagation and trigger configuration behavior for the builders, so they can reliably replace the previous `BasicOpenShiftTest` coverage.
</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 +37 to +46
final ConfigMap configMap = new ConfigMapBuilder(TEST_CONFIGMAP_NAME)
.addLabels(TEST_RESOURCE_LABELS)
.configEntry(dataEntryKey, dataEntryValue)
.build();

// assert - verify the built ConfigMap structure
Assertions.assertNotNull(configMap, "ConfigMap resource creation failed.");
Assertions.assertEquals(TEST_CONFIGMAP_NAME,
configMap.getMetadata().getName(),
"ConfigMap resource has unexpected name.");
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Extend builder tests to assert labels (and potentially triggers) to better cover builder behavior

Currently these tests only assert name/data for ConfigMap and a few fields for DeploymentConfig. Since labels are part of the builder contract (and you pass TEST_RESOURCE_LABELS), please also assert that these labels are present in metadata.labels for both resources. For DeploymentConfigBuilder, also verify that the image change trigger configured via onImageChange() appears in .spec.triggers with the expected type, so these tests fully cover the intended builder behavior and can reliably replace BasicOpenShiftTest.

Suggested implementation:

        Assertions.assertEquals(TEST_CONFIGMAP_NAME,
                configMap.getMetadata().getName(),
                "ConfigMap resource has unexpected name.");
        Assertions.assertEquals(TEST_RESOURCE_LABELS,
                configMap.getMetadata().getLabels(),
                "ConfigMap resource has unexpected labels.");

To fully implement the requested coverage for the DeploymentConfigBuilder as per your review comment, make the following changes in the same test class, inside the testDeploymentConfigBuilder (or equivalent) method that builds and asserts the DeploymentConfig:

  1. Assert labels on the DeploymentConfig metadata

    After the existing assertion that checks the DeploymentConfig name (and before or after the replicas assertion), add:

    Assertions.assertEquals(TEST_RESOURCE_LABELS,
            deploymentConfig.getMetadata().getLabels(),
            "DeploymentConfig resource has unexpected labels.");

    This assumes the variable holding the built resource is named deploymentConfig. Adjust the variable name if different.

  2. Assert the presence of the ImageChange trigger

    After the basic structural assertions (name, replicas, etc.), add assertions that verify the ImageChange trigger created by .onImageChange() is present in .spec.triggers:

    Assertions.assertNotNull(deploymentConfig.getSpec(), "DeploymentConfig spec should not be null.");
    Assertions.assertNotNull(deploymentConfig.getSpec().getTriggers(), "DeploymentConfig triggers should not be null.");
    
    boolean hasImageChangeTrigger = deploymentConfig.getSpec().getTriggers()
            .stream()
            .anyMatch(trigger -> "ImageChange".equals(trigger.getType()));
    
    Assertions.assertTrue(hasImageChangeTrigger,
            "DeploymentConfig should contain an ImageChange trigger configured via onImageChange().");

    If your test currently doesn’t import java.util.stream.* or similar, no extra imports are needed because stream() is available on List. Ensure the deploymentConfig type is io.fabric8.openshift.api.model.DeploymentConfig (or compatible) so getSpec().getTriggers() and getType() on the trigger objects are available.

These additions will ensure the tests cover both label propagation and trigger configuration behavior for the builders, so they can reliably replace the previous BasicOpenShiftTest coverage.

@kanovotn kanovotn force-pushed the openshiftClient74 branch 2 times, most recently from cad69d3 to bc3e79f Compare January 8, 2026 12:44
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, thanks a lot for this work. Merging.

@mnovak mnovak merged commit 954a309 into xtf-cz:master Jan 14, 2026
4 checks passed
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