Skip to main content

Overview

The OpenshiftDeployable interface extends Deployable to provide OpenShift-specific deployment capabilities. It adds pod management, readiness checks, and OpenShift resource lifecycle methods. Package: software.tnb.common.deployment Extends: Deployable

Core methods

create()

void create()
Creates the OpenShift resources for the service. This is called by deploy() if the service is not already deployed.
Implement this method to define your OpenShift resource creation logic (deployments, services, routes, etc.).

isReady()

default boolean isReady()
Checks if all service pods are ready.
return
boolean
Returns true if service pods exist and all are ready, false otherwise.
The default implementation checks that servicePods() returns a non-empty list and all pods are ready.

isDeployed()

boolean isDeployed()
Checks if the service is already deployed in OpenShift.
return
boolean
Returns true if the service resources exist in the cluster, false otherwise.

podSelector()

Predicate<Pod> podSelector()
Provides a predicate to identify pods belonging to this service.
return
Predicate<Pod>
A predicate that returns true for pods belonging to this service.
This is used internally by servicePods() to filter the pods in the namespace. Typically implemented using labels.

Pod management

servicePod()

default PodResource servicePod()
Retrieves the first service pod.
return
PodResource
The first pod resource, or null if no pods are available.
Useful for services that run a single pod. For multi-pod services, use servicePods() instead.

servicePods()

default List<PodResource> servicePods()
Retrieves all pods belonging to this service.
return
List<PodResource>
A list of pod resources matching the podSelector(), or null on transient errors.
Returns null if a KubernetesClientException occurs, allowing for transient network errors.

getLogs()

default String getLogs()
Retrieves logs from the first service pod.
return
String
The pod logs as a string.

Configuration methods

waitTime()

default long waitTime()
Specifies the maximum time to wait for the service to become ready during deployment.
return
long
default:"300000"
The wait time in milliseconds. Default is 300,000ms (5 minutes).
Override this method to customize the deployment timeout for services with different startup characteristics.

Overridden lifecycle methods

deploy()

default void deploy()
Deploys the service to OpenShift with automatic readiness checking. Behavior:
  1. Calls create() if isDeployed() returns false
  2. Waits for isReady() to return true using waitTime() as the timeout
  3. Throws TimeoutException if the service doesn’t become ready in time
If deployment times out, the exception message includes all pods in the namespace to aid debugging.

restart()

default void restart()
Restarts the service by deleting the pod and waiting for a new one to become ready. Behavior:
  1. Calls closeResources()
  2. Deletes the service pod
  3. Waits for new pods to be ready and not marked for deletion
  4. Calls openResources()
This performs a pod restart without recreating the entire deployment, which is faster than a full redeploy.

afterAll()

default void afterAll(ExtensionContext extensionContext) throws Exception
Cleans up resources after tests, with special handling for parallel test execution.
extensionContext
ExtensionContext
The JUnit extension context.
In parallel execution mode, this method automatically deletes the test namespace to ensure isolation.

enabled()

default boolean enabled()
Determines if this deployable is enabled based on the OpenShift configuration.
return
boolean
Returns true if OpenShift is configured, false otherwise.

priority()

default int priority()
Defines the deployment priority for OpenShift deployables.
return
int
default:"1"
Returns 1, giving OpenShift deployables lower priority than the default Deployable priority of 0.

Usage example

public class MyOpenshiftService implements OpenshiftDeployable, WithName {
    @Override
    public String name() {
        return "my-service";
    }

    @Override
    public void create() {
        // Create deployment, service, route, etc.
        OpenshiftClient.get().apps().deployments()
            .create(buildDeployment());
    }

    @Override
    public Predicate<Pod> podSelector() {
        return p -> OpenshiftClient.get().hasLabels(p, 
            Map.of("app", name()));
    }

    @Override
    public void openResources() {
        // Initialize OpenShift-aware clients
    }

    @Override
    public void closeResources() {
        // Clean up clients
    }
}

Implementation notes

Implementations must provide create(), podSelector(), and isDeployed(). Consider implementing WithName to get default implementations of podSelector() and isDeployed().
The interface handles deployment waiting and readiness checks automatically, reducing boilerplate in implementations.
The deploy() method will retry readiness checks 60 times with intervals based on waitTime() / 60. Ensure your waitTime() is appropriate for your service’s startup characteristics.
  • WithName - Provides default implementations of podSelector() and isDeployed() based on deployment name
  • WithLogs - Base interface for log retrieval
  • Deployable - Parent interface defining the core deployment lifecycle

Build docs developers (and LLMs) love