CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-fabric8--openshift-client

Java client library for OpenShift REST APIs, providing fluent DSL access to OpenShift resources and operations.

Pending
Overview
Eval results
Files

client-setup.mddocs/

Client Configuration and Setup

Core client creation, configuration management, and connection setup for OpenShift clusters. Includes authentication, SSL configuration, namespace management, and version detection.

Capabilities

OpenShift Client Creation

Create OpenShift client instances with various configuration options. The recommended approach uses KubernetesClientBuilder with adaptation to OpenShiftClient.

/**
 * Main OpenShift client interface providing access to all OpenShift-specific resources
 * Extends KubernetesClient with OpenShift-specific operations
 */
public interface OpenShiftClient extends KubernetesClient {
    String BASE_API_GROUP = "openshift.io";
    
    /** Get OpenShift cluster URL */
    URL getOpenshiftUrl();
    
    /** Get Kubernetes version information */
    VersionInfo getVersion();
    
    /** Get OpenShift v3 version from version/openshift endpoint */
    VersionInfo getOpenShiftV3Version();
    
    /** Get OpenShift v4 server version */
    String getOpenShiftV4Version();
    
    /** Get current logged-in user (equivalent to 'oc whoami') */
    User currentUser();
    
    /** Check if cluster supports specific OpenShift API group */
    boolean supportsOpenShiftAPIGroup(String apiGroup);
    
    /** Configure request settings for operations */
    FunctionCallable<NamespacedOpenShiftClient> withRequestConfig(RequestConfig requestConfig);
}

Usage Examples:

import io.fabric8.openshift.client.OpenShiftClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;

// Recommended: Create client using builder (auto-configures from kubeconfig/env)
try (OpenShiftClient client = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class)) {
    // Use client
    User user = client.currentUser();
    System.out.println("Current user: " + user.getMetadata().getName());
}

// Legacy: Direct instantiation (deprecated but still available)
try (OpenShiftClient client = new DefaultOpenShiftClient()) {
    String version = client.getOpenShiftV4Version();
    System.out.println("OpenShift version: " + version);
}

Namespace-aware Client

OpenShift client with namespace context management for namespace-scoped operations.

/**
 * Namespace-aware OpenShift client interface
 * Combines OpenShiftClient and NamespacedKubernetesClient capabilities
 */
public interface NamespacedOpenShiftClient extends OpenShiftClient, NamespacedKubernetesClient {
    /** Switch to operate in any namespace */
    NamespacedOpenShiftClient inAnyNamespace();
    
    /** Switch to operate in specific namespace */
    NamespacedOpenShiftClient inNamespace(String namespace);
    
    /** Configure request settings for operations */
    FunctionCallable<NamespacedOpenShiftClient> withRequestConfig(RequestConfig requestConfig);
}

Usage Examples:

// Work with namespace-scoped operations
try (NamespacedOpenShiftClient client = new KubernetesClientBuilder().build().adapt(NamespacedOpenShiftClient.class)) {
    // Switch to specific namespace
    NamespacedOpenShiftClient namespacedClient = client.inNamespace("myproject");
    
    // List builds in current namespace
    BuildList builds = namespacedClient.builds().list();
    
    // Switch to any namespace for cross-namespace operations
    NamespacedOpenShiftClient anyNsClient = namespacedClient.inAnyNamespace();
    ProjectList allProjects = anyNsClient.projects().list();
}

OpenShift Configuration

OpenShift-specific configuration extending Kubernetes configuration with build timeouts, API versioning, and URL settings.

/**
 * OpenShift-specific configuration class
 * Extends Kubernetes Config with OpenShift-specific settings
 */
public class OpenShiftConfig extends Config {
    /** Default build timeout (5 minutes) */
    public static final Long DEFAULT_BUILD_TIMEOUT = 5 * 60 * 1000L;
    
    /** System property keys */
    public static final String KUBERNETES_OAPI_VERSION_SYSTEM_PROPERTY = "kubernetes.oapi.version";
    public static final String OPENSHIFT_URL_SYSTEM_PROPERTY = "openshift.url";
    public static final String OPENSHIFT_BUILD_TIMEOUT_SYSTEM_PROPERTY = "openshift.build.timeout";
    
    /** Create OpenShift config from Kubernetes config */
    public OpenShiftConfig(Config kubernetesConfig);
    
    /** Create OpenShift config with specific URL */
    public OpenShiftConfig(Config kubernetesConfig, String openShiftUrl);
    
    /** Get OpenShift API version (default: "v1") */
    public String getOapiVersion();
    
    /** Set OpenShift API version */
    public void setOapiVersion(String oapiVersion);
    
    /** Get OpenShift cluster URL */
    public String getOpenShiftUrl();
    
    /** Set OpenShift cluster URL */
    public void setOpenShiftUrl(String openShiftUrl);
    
    /** Get build timeout in milliseconds */
    public long getBuildTimeout();
    
    /** Set build timeout in milliseconds */
    public void setBuildTimeout(long buildTimeout);
    
    /** Check if API group validation is disabled */
    public boolean isDisableApiGroupCheck();
    
    /** Set API group validation flag */
    public void setDisableApiGroupCheck(boolean disableApiGroupCheck);
    
    /** Wrap Kubernetes config as OpenShift config */
    public static OpenShiftConfig wrap(Config config);
}

Usage Examples:

import io.fabric8.openshift.client.OpenShiftConfig;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;

// Create OpenShift config from Kubernetes config
Config k8sConfig = new ConfigBuilder()
    .withMasterUrl("https://api.my-cluster.com:6443")
    .withOauthToken("my-token")
    .build();

OpenShiftConfig osConfig = new OpenShiftConfig(k8sConfig);

// Customize OpenShift-specific settings
osConfig.setBuildTimeout(10 * 60 * 1000L); // 10 minutes
osConfig.setOapiVersion("v1");

// Use config with client
try (OpenShiftClient client = new DefaultOpenShiftClient(osConfig)) {
    // Client operations
}

Configuration Builder

Builder pattern for constructing OpenShift configurations with fluent API.

/**
 * Builder for OpenShiftConfig with fluent API
 * Generated builder providing type-safe configuration construction
 */
public class OpenShiftConfigBuilder {
    public OpenShiftConfigBuilder();
    public OpenShiftConfigBuilder withOpenShiftUrl(String openShiftUrl);
    public OpenShiftConfigBuilder withOapiVersion(String oapiVersion);
    public OpenShiftConfigBuilder withBuildTimeout(Long buildTimeout);
    public OpenShiftConfigBuilder withDisableApiGroupCheck(Boolean disableApiGroupCheck);
    public OpenShiftConfig build();
}

Usage Examples:

import io.fabric8.openshift.client.OpenShiftConfigBuilder;

// Build configuration using fluent API
OpenShiftConfig config = new OpenShiftConfigBuilder()
    .withMasterUrl("https://api.my-cluster.com:6443")
    .withOauthToken("my-token")
    .withOpenShiftUrl("https://api.my-cluster.com:6443/oapi/v1")
    .withBuildTimeout(15 * 60 * 1000L) // 15 minutes
    .withDisableApiGroupCheck(false)
    .build();

try (OpenShiftClient client = new DefaultOpenShiftClient(config)) {
    // Use configured client
}

Legacy Client (Deprecated)

Direct instantiation of OpenShift client (deprecated in favor of KubernetesClientBuilder).

/**
 * Default OpenShift client implementation (deprecated)
 * @deprecated Use KubernetesClientBuilder().build().adapt(OpenShiftClient.class) instead
 */
@Deprecated
public class DefaultOpenShiftClient extends NamespacedOpenShiftClientAdapter {
    public static final String OPENSHIFT_VERSION_ENDPOINT = "version/openshift";
    
    /** Default constructor with auto-configuration */
    public DefaultOpenShiftClient();
    
    /** Constructor with master URL */
    public DefaultOpenShiftClient(String masterUrl);
    
    /** Constructor with Kubernetes config */
    public DefaultOpenShiftClient(Config config);
    
    /** Constructor with OpenShift config */
    public DefaultOpenShiftClient(OpenShiftConfig config);
    
    /** Constructor with custom HTTP client and config */
    public DefaultOpenShiftClient(HttpClient httpClient, OpenShiftConfig config);
}

Environment Configuration

OpenShift client respects standard Kubernetes environment variables plus OpenShift-specific settings:

Kubernetes Environment Variables:

  • KUBERNETES_MASTER / kubernetes.master - Kubernetes master URL
  • KUBERNETES_NAMESPACE / kubernetes.namespace - Default namespace
  • KUBERNETES_AUTH_TOKEN / kubernetes.auth.token - Authentication token
  • KUBECONFIG / kubeconfig - Path to kubeconfig file

OpenShift-Specific Environment Variables:

  • OPENSHIFT_URL / openshift.url - OpenShift API URL (overrides derived URL)
  • KUBERNETES_OAPI_VERSION / kubernetes.oapi.version - OpenShift API version
  • OPENSHIFT_BUILD_TIMEOUT / openshift.build.timeout - Build operation timeout

Request Configuration

Configure request-specific settings like timeouts, retries, and custom headers.

/**
 * Configure request settings for client operations
 */
public interface FunctionCallable<T> extends Callable<T> {
    T call();
}

Usage Examples:

import io.fabric8.kubernetes.client.RequestConfig;
import io.fabric8.kubernetes.client.RequestConfigBuilder;

// Configure request settings
RequestConfig requestConfig = new RequestConfigBuilder()
    .withRequestTimeout(30000) // 30 seconds
    .withConnectionTimeout(10000) // 10 seconds
    .withRequestRetryBackoffLimit(3)
    .build();

// Apply to client operations
try (OpenShiftClient client = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class)) {
    NamespacedOpenShiftClient configuredClient = client.withRequestConfig(requestConfig).call();
    
    // Operations use the configured request settings
    BuildList builds = configuredClient.builds().list();
}

Version and Capability Detection

Detect OpenShift cluster capabilities and version information for compatibility checks.

Usage Examples:

try (OpenShiftClient client = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class)) {
    // Check OpenShift availability and version
    try {
        VersionInfo osVersion = client.getOpenShiftV3Version();
        String v4Version = client.getOpenShiftV4Version();
        System.out.println("OpenShift v3 info: " + osVersion);
        System.out.println("OpenShift v4 version: " + v4Version);
    } catch (Exception e) {
        System.out.println("OpenShift version detection failed: " + e.getMessage());
    }
    
    // Check API group support
    boolean supportsBuilds = client.supportsOpenShiftAPIGroup("build.openshift.io");
    boolean supportsImages = client.supportsOpenShiftAPIGroup("image.openshift.io");
    
    if (supportsBuilds) {
        // Use build APIs
        BuildList builds = client.builds().list();
    }
    
    // Get current user context
    try {
        User currentUser = client.currentUser();
        System.out.println("Authenticated as: " + currentUser.getMetadata().getName());
        
        // Check user groups
        List<String> groups = currentUser.getGroups();
        System.out.println("User groups: " + groups);
    } catch (Exception e) {
        System.out.println("Failed to get current user: " + e.getMessage());
    }
}

Install with Tessl CLI

npx tessl i tessl/maven-io-fabric8--openshift-client

docs

client-setup.md

configuration-management.md

core-resources.md

index.md

machine-management.md

monitoring.md

multicluster-management.md

operator-management.md

security-rbac.md

tile.json