The OpenshiftConfiguration class provides configuration for OpenShift cluster connections, namespace management, and deployment strategies. All configuration is done through system properties.
Property constants
Basic OpenShift settings
Enable OpenShift deployment for tests
Use Microshift instead of full OpenShift
Username for OpenShift authentication
Password for OpenShift authentication
HTTPS proxy for OpenShift API requests
Namespace configuration
OpenShift namespace/project name. If not set, a random namespace with prefix tnb-test- will be generated
openshift.namespace.autoset
Automatically set the namespace without user confirmation
openshift.namespace.delete
Delete the namespace after test completion. Automatically true if namespace is auto-generated or parallel mode is enabled
Kubeconfig
Path to kubeconfig file for OpenShift authentication. Takes precedence over kubeconfig
Alternative path to kubeconfig file
Deployment configuration
openshift.deployment.label
Label used to identify application deployments
openshift.deploy.strategy
Deployment strategy to use (e.g., jkube, s2i)
XTF integration
xtf.openshift.master.kubeconfig
Kubeconfig path for XTF (eXtended Test Framework) integration
OpenShift URL for XTF integration
Public methods
Cluster connection
public static boolean isOpenshift()
Returns true if OpenShift deployment is enabled via test.use.openshift.
public static boolean isMicroshift()
Returns true if Microshift is being used instead of OpenShift.
public static String openshiftUrl()
Returns the OpenShift cluster API URL.
public static String openshiftUsername()
Returns the username for authentication (default: “admin”).
public static String openshiftPassword()
Returns the password for authentication (default: “admin”).
public static String openshiftHttpsProxy()
Returns the HTTPS proxy for OpenShift API requests, or null if not configured.
Namespace management
@Deprecated
public static String openshiftNamespace()
Returns the OpenShift namespace. If not configured, generates a random namespace with prefix tnb-test-. In parallel mode, appends a random suffix to the configured namespace.
This method is deprecated and should only be used when initializing the OpenShift client. Use OpenshiftClient.get().getNamespace() to get the current namespace.
public static boolean openshiftNamespaceAutoSet()
Returns true if namespace should be set automatically.
public static boolean openshiftNamespaceDelete()
Returns true if the namespace should be deleted after tests. Always true if the namespace was auto-generated or parallel mode is enabled.
Kubeconfig
public static Path openshiftKubeconfig()
Returns the path to the kubeconfig file, checking openshift.kubeconfig first, then kubeconfig. Returns null if neither is set.
Deployment
public static String openshiftDeploymentLabel()
Returns the label used for deployment identification (default: “app”).
public static String getDeployStrategy()
Returns the deployment strategy (default: “jkube”).
XTF integration
public static String xtfOpenshiftKubeconfig()
public static String xtfOpenshiftUrl()
Returns XTF-specific configuration values.
Usage examples
Basic OpenShift connection
mvn test \
-Dtest.use.openshift=true \
-Dopenshift.url=https://api.ocp.example.com:6443 \
-Dopenshift.username=developer \
-Dopenshift.password=mypassword
Using kubeconfig
mvn test \
-Dtest.use.openshift=true \
-Dopenshift.kubeconfig=/home/user/.kube/config
When using kubeconfig, username and password are not required. The client will use the current context from the kubeconfig file.
Custom namespace with cleanup
mvn test \
-Dtest.use.openshift=true \
-Dopenshift.namespace=my-test-project \
-Dopenshift.namespace.delete=true
Auto-generated namespace
mvn test \
-Dtest.use.openshift=true
When no namespace is specified, TNB generates a random namespace with format tnb-test-XXXXXXXX and automatically deletes it after test completion.
Parallel execution with namespace isolation
mvn test \
-Dtest.use.openshift=true \
-Dtest.parallel=true \
-Dopenshift.namespace=myapp-tests
In parallel mode, each test run appends a random 8-character suffix to the namespace name to prevent conflicts.
Microshift configuration
mvn test \
-Dtest.use.microshift=true \
-Dopenshift.url=https://localhost:6443 \
-Dopenshift.kubeconfig=/var/lib/microshift/resources/kubeadmin/kubeconfig
Using HTTPS proxy
mvn test \
-Dtest.use.openshift=true \
-Dopenshift.url=https://api.ocp.example.com:6443 \
-Dopenshift.https.proxy=http://proxy.example.com:8080
Custom deployment strategy
mvn test \
-Dtest.use.openshift=true \
-Dopenshift.deploy.strategy=s2i
Access in Java code
import software.tnb.common.config.OpenshiftConfiguration;
public class MyTest {
@Test
public void testOpenshiftDeployment() {
if (OpenshiftConfiguration.isOpenshift()) {
String url = OpenshiftConfiguration.openshiftUrl();
String strategy = OpenshiftConfiguration.getDeployStrategy();
System.out.println("Deploying to: " + url);
System.out.println("Using strategy: " + strategy);
if (OpenshiftConfiguration.openshiftNamespaceDelete()) {
System.out.println("Namespace will be cleaned up after tests");
}
}
}
}
Complete example with all options
Using credentials
Using kubeconfig
mvn test \
-Dtest.use.openshift=true \
-Dopenshift.url=https://api.ocp4.example.com:6443 \
-Dopenshift.username=testuser \
-Dopenshift.password=secret123 \
-Dopenshift.namespace=tnb-integration-tests \
-Dopenshift.namespace.delete=true \
-Dopenshift.deploy.strategy=jkube \
-Dopenshift.deployment.label=app.kubernetes.io/name
mvn test \
-Dtest.use.openshift=true \
-Dopenshift.kubeconfig=~/.kube/ocp-cluster \
-Dopenshift.namespace=tnb-integration-tests \
-Dopenshift.namespace.autoset=true \
-Dopenshift.deploy.strategy=jkube