Skip to main content
TNB supports multiple deployment strategies for OpenShift, each optimized for different use cases and workflows.

Overview

Deployment strategies are defined in the OpenshiftDeployStrategyType enum:
public enum OpenshiftDeployStrategyType {
    JKUBE,
    DEVFILE,
    BINARY,
    CUSTOM,
    JKUBE_EXT_REPO
}

Selecting a strategy

Set the deployment strategy using the openshift.deploy.strategy system property:
-Dopenshift.deploy.strategy=JKUBE
If not specified, TNB selects a default strategy based on the product type.

Strategy types

JKube strategy

The Eclipse JKube Maven plugin strategy is the standard approach for OpenShift deployments.
Type
OpenshiftDeployStrategyType
JKUBE
Supported products
ProductType[]
CAMEL_SPRINGBOOT

How it works

1

Build the project

Runs Maven with clean install goals.
2

Deploy to OpenShift

Executes JKube’s openshift goal to create OpenShift resources and deploy.
3

Create TNB deployment

Optionally creates TNB-specific deployment resources.

Usage

import software.tnb.product.integration.builder.IntegrationBuilder;

IntegrationBuilder ib = new IntegrationBuilder("jkube-deployment")
    .fromRouteBuilder(routeBuilder)
    .dependencies("timer", "log");

product.createIntegration(ib);

Configuration

# System properties
-Dopenshift.deploy.strategy=JKUBE
-Dopenshift.url=https://api.openshift.example.com:6443
-Dopenshift.namespace=my-project

JKube with external repository

Similar to JKube but pushes the container image to an external registry.
Type
OpenshiftDeployStrategyType
JKUBE_EXT_REPO
Supported products
ProductType[]
All products

Use case

When your OpenShift cluster requires images from a specific external registry (e.g., Quay.io, Docker Hub).

Configuration

-Dopenshift.deploy.strategy=JKUBE_EXT_REPO
-Dexternal.registry.url=quay.io/myorg
-Dexternal.registry.username=myuser
-Dexternal.registry.password=mypassword

Binary strategy

Uses OpenShift’s Binary Source-to-Image (S2I) builds.
Type
OpenshiftDeployStrategyType
BINARY
Supported products
ProductType[]
CAMEL_SPRINGBOOT

How it works

1

Copy resources

Copies resources to ocp/deployments/data directory.
2

Build JAR

Runs Maven clean package with openshift profile.
3

Copy JAR

Copies the generated JAR to ocp/deployments.
4

Create build config

Creates a new build using oc new-build --binary.
5

Start build

Starts the build with oc start-build --from-dir.
6

Create deployment

Creates the deployment with oc new-app.
7

Expose route

Exposes the service with oc expose svc.

Key implementation details

@AutoService(OpenshiftDeployStrategy.class)
public class BinaryStrategy extends OpenshiftBaseDeployer {
    @Override
    public void doDeploy() {
        // Create new build
        binary.execute("new-build", "--binary=true",
            String.format("--name=%s", name),
            String.format("--image=%s", SpringBootConfiguration.openshiftBaseImage()),
            String.format("--labels=%s=%s", OpenshiftConfiguration.openshiftDeploymentLabel(), name)
        );
        
        // Start build
        binary.execute("start-build", name,
            String.format("--from-dir=%s", baseDirectory.resolve("ocp").toAbsolutePath()),
            "--follow"
        );
        
        // Create deployment
        binary.execute("new-app", name,
            String.format("--labels=%s=%s", OpenshiftConfiguration.openshiftDeploymentLabel(), name),
            String.format("--env=JAVA_OPTS_APPEND=%s", getPropertiesForJVM(integrationBuilder)),
            "--allow-missing-imagestream-tags=true"
        );
        
        // Expose service
        binary.execute("expose", String.format("svc/%s", name),
            String.format("--labels=%s=%s", OpenshiftConfiguration.openshiftDeploymentLabel(), name)
        );
    }
}

Usage

-Dopenshift.deploy.strategy=BINARY

Devfile strategy

Uses OpenShift Dev Spaces / ODO with devfile-based deployments.
Type
OpenshiftDeployStrategyType
DEVFILE
Supported products
ProductType[]
CAMEL_SPRINGBOOT

How it works

1

Copy resources

Copies project resources to devfile-resources directory.
2

Copy devfile

Copies the devfile.yaml for Java Spring Boot UBI8.
3

Copy Dockerfile

Copies the Dockerfile for the build.
4

Configure ODO

Sets ODO preferences and environment variables.
5

Deploy with ODO

Executes odo deploy with configured variables.

Environment variables

The strategy configures several environment variables:
  • MAVEN_MIRROR_URL: Maven repository mirror
  • JAVA_OPTS_APPEND: JVM options from integration builder
  • MAVEN_ARGS_APPEND: Maven arguments
  • SUB_FOLDER: Subfolder for multi-module projects
  • APP: Application name
  • IMAGE_REGISTRY: Container registry URL

Usage

# Install ODO CLI
-Dodo.path=/usr/local/bin/odo

# Set strategy
-Dopenshift.deploy.strategy=DEVFILE

Key implementation details

@Override
public void doDeploy() {
    try {
        login();
        List<String> envVars = new ArrayList<>();
        
        // Set ephemeral preference
        runOdoCmd(Arrays.asList("preference", "set", "Ephemeral", "true", "--force"), Phase.GENERATE);
        
        // Configure Maven mirror
        if (TestConfiguration.isMavenMirror()) {
            envVars.addAll(
                setEnvVar("MAVEN_MIRROR_URL", 
                    StringUtils.substringBefore(TestConfiguration.mavenRepository(), "@mirrorOf"))
            );
        }
        
        // Add JVM properties
        envVars.addAll(setEnvVar("JAVA_OPTS_APPEND", getPropertiesForJVM(integrationBuilder)));
        
        // Deploy
        ArrayList<String> devCommand = new ArrayList<>(List.of("deploy"));
        devCommand.addAll(envVars);
        runOdoCmd(devCommand, Phase.DEPLOY);
    } catch (IOException | InterruptedException e) {
        throw new RuntimeException(e);
    }
}

Custom strategy

Implement your own deployment strategy for special requirements.
Type
OpenshiftDeployStrategyType
CUSTOM
Supported products
ProductType[]
All products (depends on implementation)

Creating a custom strategy

1

Implement OpenshiftCustomDeployer

Create a class implementing the OpenshiftCustomDeployer interface.
2

Define deployment logic

Implement preDeploy(), doDeploy(), and undeploy() methods.
3

Register with integration builder

Use useOcpCustomStrategy() to register your deployer.

Example

import software.tnb.product.deploystrategy.impl.custom.OpenshiftCustomDeployer;
import software.tnb.product.integration.builder.IntegrationBuilder;

public class MyCustomDeployer implements OpenshiftCustomDeployer {
    @Override
    public void preDeploy() {
        // Pre-deployment setup
        LOG.info("Preparing custom deployment");
    }
    
    @Override
    public void doDeploy() {
        // Main deployment logic
        LOG.info("Executing custom deployment");
        // ... your deployment code ...
    }
    
    @Override
    public void undeploy() {
        // Cleanup
        LOG.info("Cleaning up custom deployment");
    }
}

// Usage
IntegrationBuilder ib = new IntegrationBuilder("custom-deploy")
    .fromRouteBuilder(routeBuilder)
    .useOcpCustomStrategy(new MyCustomDeployer());

Deployment phases

All deployment strategies follow a common lifecycle:
1

Pre-deploy

preDeploy(): Preparation tasks like copying resources, building JARs.
2

Deploy

doDeploy(): Main deployment to OpenShift cluster.
3

Wait for ready

Application waits until pods are running and ready.
4

Test execution

Your tests run against the deployed integration.
5

Undeploy

undeploy(): Cleanup of OpenShift resources.

Strategy selection logic

The OpenshiftDeployStrategyFactory selects strategies based on:
  1. Explicit openshift.deploy.strategy system property
  2. Product type compatibility
  3. Custom strategy from integration builder
  4. Default strategy for the product
public class OpenshiftDeployStrategyFactory {
    public static OpenshiftDeployStrategy getStrategy(
        ProductType productType,
        OpenshiftDeployStrategyType strategyType
    ) {
        // Find strategy matching product and type
        return strategies.stream()
            .filter(s -> Arrays.asList(s.products()).contains(productType))
            .filter(s -> s.deployType() == strategyType)
            .findFirst()
            .orElseThrow(() -> new IllegalArgumentException(
                "No strategy found for product " + productType + 
                " and strategy " + strategyType
            ));
    }
}

Logging and troubleshooting

Each strategy creates log files in the application location:
  • {integration-name}-build.log: Build phase logs
  • {integration-name}-deploy.log: Deployment phase logs
  • {integration-name}-undeploy.log: Undeployment phase logs
final BuildRequest.Builder requestBuilder = new BuildRequest.Builder()
    .withBaseDirectory(baseDirectory)
    .withArgs("clean", "package")
    .withProfiles("openshift")
    .withLogFile(TestConfiguration.appLocation().resolve(name + "-build.log"))
    .withLogMarker(LogStream.marker(name, Phase.BUILD));

Best practices

Use JKube for standard deployments

JKube is the most common and well-supported strategy for most use cases.

Use Binary for quick iterations

Binary strategy is faster for development cycles as it skips some build steps.

Use Devfile for Dev Spaces

Devfile strategy integrates with OpenShift Dev Spaces for cloud-native development.

Implement Custom for special requirements

Only implement custom strategies when built-in strategies don’t meet your needs.

Check logs for failures

Always check the generated log files when deployments fail.

Clean up resources

Ensure proper cleanup in undeploy() to avoid resource leaks.

Configuration reference

Common system properties

openshift.url
string
required
OpenShift cluster API URLExample: https://api.openshift.example.com:6443
openshift.deploy.strategy
OpenshiftDeployStrategyType
Deployment strategy to useValues: JKUBE, BINARY, DEVFILE, CUSTOM, JKUBE_EXT_REPO
openshift.namespace
string
Target namespace/project for deploymentDefault: Current namespace from kubeconfig
openshift.kubeconfig
path
Path to kubeconfig fileDefault: ~/.kube/config
openshift.deployment.label
string
Label applied to all created resourcesDefault: tnb-deployment

Strategy-specific properties

odo.path
path
Path to ODO CLI binary (for Devfile strategy)Default: odo (from PATH)
external.registry.url
string
External container registry URL (for JKUBE_EXT_REPO strategy)
external.registry.username
string
Registry username (for JKUBE_EXT_REPO strategy)
external.registry.password
string
Registry password (for JKUBE_EXT_REPO strategy)

Build docs developers (and LLMs) love