0
# OpenShift Client
1
2
OpenShift Client is a comprehensive Java library that provides fluent DSL access to OpenShift REST APIs. It extends the Kubernetes client with OpenShift-specific resources and operations, enabling programmatic interaction with OpenShift clusters through build management, template processing, project administration, and extensive API group operations covering configuration, monitoring, machine management, and operator lifecycle management.
3
4
## Package Information
5
6
- **Package Name**: openshift-client
7
- **Group ID**: io.fabric8
8
- **Language**: Java
9
- **Installation**:
10
```xml
11
<dependency>
12
<groupId>io.fabric8</groupId>
13
<artifactId>openshift-client</artifactId>
14
<version>7.3.1</version>
15
</dependency>
16
```
17
18
## Core Imports
19
20
```java
21
import io.fabric8.openshift.client.OpenShiftClient;
22
import io.fabric8.openshift.client.DefaultOpenShiftClient;
23
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
24
```
25
26
## Basic Usage
27
28
```java
29
import io.fabric8.openshift.client.OpenShiftClient;
30
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
31
32
// Create OpenShift client (recommended approach)
33
try (OpenShiftClient client = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class)) {
34
// Get current user (equivalent to 'oc whoami')
35
User currentUser = client.currentUser();
36
System.out.println("Current user: " + currentUser.getMetadata().getName());
37
38
// List projects
39
ProjectList projects = client.projects().list();
40
for (Project project : projects.getItems()) {
41
System.out.println("Project: " + project.getMetadata().getName());
42
}
43
44
// Create a build from BuildConfig
45
BuildConfig buildConfig = client.buildConfigs()
46
.inNamespace("myproject")
47
.withName("myapp")
48
.get();
49
if (buildConfig != null) {
50
Build build = client.buildConfigs()
51
.inNamespace("myproject")
52
.withName("myapp")
53
.instantiate(new BuildRequestBuilder().build());
54
}
55
}
56
```
57
58
## Architecture
59
60
OpenShift Client is built on several key components:
61
62
- **Client Interfaces**: `OpenShiftClient` provides the main API surface, extending `KubernetesClient` with OpenShift-specific operations
63
- **DSL Pattern**: Fluent domain-specific language for resource operations using method chaining and type-safe builders
64
- **Resource Operations**: Standard CRUD operations through `MixedOperation` (namespace-scoped) and `NonNamespaceOperation` (cluster-scoped) interfaces
65
- **API Group Organization**: Structured access to OpenShift's extensive API groups covering configuration, operators, monitoring, machine management, and more
66
- **Extension Architecture**: Pluggable extension system allowing adaptation between Kubernetes and OpenShift clients
67
- **Configuration System**: `OpenShiftConfig` extends Kubernetes configuration with OpenShift-specific settings like build timeouts and API versioning
68
69
## Capabilities
70
71
### Client Configuration and Setup
72
73
Core client creation, configuration management, and connection setup for OpenShift clusters. Includes authentication, SSL configuration, and namespace management.
74
75
```java { .api }
76
public interface OpenShiftClient extends KubernetesClient {
77
URL getOpenshiftUrl();
78
VersionInfo getOpenShiftV3Version();
79
String getOpenShiftV4Version();
80
User currentUser();
81
boolean supportsOpenShiftAPIGroup(String apiGroup);
82
FunctionCallable<NamespacedOpenShiftClient> withRequestConfig(RequestConfig requestConfig);
83
84
// API Group Access Methods
85
OpenShiftConfigAPIGroupDSL config();
86
OpenShiftConsoleAPIGroupDSL console();
87
OpenShiftAutoscalingAPIGroupDSL openShiftAutoscaling();
88
OpenShiftHiveAPIGroupDSL hive();
89
OpenShiftOperatorAPIGroupDSL operator();
90
OpenShiftOperatorHubAPIGroupDSL operatorHub();
91
MachineConfigurationAPIGroupDSL machineConfigurations();
92
OpenShiftMachineAPIGroupDSL machine();
93
OpenShiftMonitoringAPIGroupDSL monitoring();
94
OpenShiftQuotaAPIGroupDSL quotas();
95
OpenShiftTunedAPIGroupDSL tuned();
96
OpenShiftWhereaboutsAPIGroupDSL whereabouts();
97
OpenShiftStorageVersionMigratorApiGroupDSL kubeStorageVersionMigrator();
98
}
99
100
public class OpenShiftConfig extends Config {
101
public OpenShiftConfig(Config kubernetesConfig);
102
public String getOapiVersion();
103
public String getOpenShiftUrl();
104
public long getBuildTimeout();
105
public static OpenShiftConfig wrap(Config config);
106
}
107
```
108
109
[Client Setup](./client-setup.md)
110
111
### Core OpenShift Resources
112
113
Essential OpenShift resources including builds, images, routes, templates, and projects. These resources provide the fundamental OpenShift functionality beyond standard Kubernetes.
114
115
```java { .api }
116
// Build Management
117
MixedOperation<Build, BuildList, BuildResource> builds();
118
MixedOperation<BuildConfig, BuildConfigList, BuildConfigResource<BuildConfig, Void, Build>> buildConfigs();
119
120
// Image Management
121
NonNamespaceOperation<Image, ImageList, Resource<Image>> images();
122
MixedOperation<ImageStream, ImageStreamList, Resource<ImageStream>> imageStreams();
123
MixedOperation<ImageStreamTag, ImageStreamTagList, Resource<ImageStreamTag>> imageStreamTags();
124
125
// Application Resources
126
MixedOperation<DeploymentConfig, DeploymentConfigList, DeployableScalableResource<DeploymentConfig>> deploymentConfigs();
127
MixedOperation<Route, RouteList, Resource<Route>> routes();
128
ParameterMixedOperation<Template, TemplateList, TemplateResource> templates();
129
130
// Project Management
131
ProjectOperation projects();
132
ProjectRequestOperation projectrequests();
133
```
134
135
[Core Resources](./core-resources.md)
136
137
### Security and Access Control
138
139
Comprehensive RBAC and security management including roles, users, groups, OAuth, and access reviews. Covers both namespace-scoped and cluster-scoped security resources.
140
141
```java { .api }
142
// User and Group Management
143
NonNamespaceOperation<User, UserList, Resource<User>> users();
144
NonNamespaceOperation<Group, GroupList, Resource<Group>> groups();
145
NonNamespaceOperation<Identity, IdentityList, Resource<Identity>> identities();
146
147
// RBAC Resources
148
MixedOperation<Role, RoleList, Resource<Role>> roles();
149
MixedOperation<RoleBinding, RoleBindingList, Resource<RoleBinding>> roleBindings();
150
NonNamespaceOperation<ClusterRole, ClusterRoleList, Resource<ClusterRole>> clusterRoles();
151
MixedOperation<ClusterRoleBinding, ClusterRoleBindingList, Resource<ClusterRoleBinding>> clusterRoleBindings();
152
153
// Security Context and Constraints
154
NonNamespaceOperation<SecurityContextConstraints, SecurityContextConstraintsList, Resource<SecurityContextConstraints>> securityContextConstraints();
155
156
// Access Reviews
157
InOutCreateable<SubjectAccessReview, SubjectAccessReviewResponse> subjectAccessReviews();
158
NamespacedInOutCreateable<LocalSubjectAccessReview, SubjectAccessReviewResponse> localSubjectAccessReviews();
159
```
160
161
[Security and RBAC](./security-rbac.md)
162
163
### Cluster Configuration Management
164
165
OpenShift cluster configuration through the config.openshift.io API group. Manages cluster-wide settings for authentication, networking, builds, DNS, ingress, and feature gates.
166
167
```java { .api }
168
OpenShiftConfigAPIGroupDSL config();
169
170
interface OpenShiftConfigAPIGroupDSL {
171
NonNamespaceOperation<APIServer, APIServerList, Resource<APIServer>> apiServers();
172
NonNamespaceOperation<Authentication, AuthenticationList, Resource<Authentication>> authentications();
173
NonNamespaceOperation<Build, BuildList, Resource<Build>> builds();
174
NonNamespaceOperation<ClusterOperator, ClusterOperatorList, Resource<ClusterOperator>> clusterOperators();
175
NonNamespaceOperation<ClusterVersion, ClusterVersionList, Resource<ClusterVersion>> clusterVersions();
176
NonNamespaceOperation<DNS, DNSList, Resource<DNS>> dnses();
177
NonNamespaceOperation<FeatureGate, FeatureGateList, Resource<FeatureGate>> featureGates();
178
NonNamespaceOperation<Network, NetworkList, Resource<Network>> networks();
179
NonNamespaceOperation<OAuth, OAuthList, Resource<OAuth>> oAuths();
180
}
181
```
182
183
[Configuration Management](./configuration-management.md)
184
185
### Operator and Lifecycle Management
186
187
Comprehensive operator management through multiple API groups including Operator Lifecycle Manager (OLM), OpenShift operators, and OperatorHub integration.
188
189
```java { .api }
190
OpenShiftOperatorAPIGroupDSL operator();
191
OpenShiftOperatorHubAPIGroupDSL operatorHub();
192
193
interface OpenShiftOperatorHubAPIGroupDSL {
194
MixedOperation<CatalogSource, CatalogSourceList, Resource<CatalogSource>> catalogSources();
195
MixedOperation<ClusterServiceVersion, ClusterServiceVersionList, Resource<ClusterServiceVersion>> clusterServiceVersions();
196
MixedOperation<InstallPlan, InstallPlanList, Resource<InstallPlan>> installPlans();
197
MixedOperation<Subscription, SubscriptionList, Resource<Subscription>> subscriptions();
198
NonNamespaceOperation<Operator, OperatorList, Resource<Operator>> operators();
199
}
200
```
201
202
[Operator Management](./operator-management.md)
203
204
### Machine and Node Management
205
206
Machine lifecycle management and node configuration through machine.openshift.io and machineconfiguration.openshift.io API groups.
207
208
```java { .api }
209
OpenShiftMachineAPIGroupDSL machine();
210
MachineConfigurationAPIGroupDSL machineConfigurations();
211
212
interface MachineConfigurationAPIGroupDSL {
213
NonNamespaceOperation<MachineConfig, MachineConfigList, Resource<MachineConfig>> machineConfigs();
214
NonNamespaceOperation<MachineConfigPool, MachineConfigPoolList, Resource<MachineConfigPool>> machineConfigPools();
215
NonNamespaceOperation<KubeletConfig, KubeletConfigList, Resource<KubeletConfig>> kubeletConfigs();
216
NonNamespaceOperation<ContainerRuntimeConfig, ContainerRuntimeConfigList, Resource<ContainerRuntimeConfig>> containerRuntimeConfigs();
217
}
218
```
219
220
[Machine Management](./machine-management.md)
221
222
### Monitoring and Observability
223
224
Prometheus-based monitoring stack management through the monitoring.coreos.com API group. Includes Prometheus, Alertmanager, and monitoring configuration.
225
226
```java { .api }
227
OpenShiftMonitoringAPIGroupDSL monitoring();
228
229
interface OpenShiftMonitoringAPIGroupDSL {
230
NonNamespaceOperation<Prometheus, PrometheusList, Resource<Prometheus>> prometheuses();
231
NonNamespaceOperation<Alertmanager, AlertmanagerList, Resource<Alertmanager>> alertmanagers();
232
NonNamespaceOperation<PrometheusRule, PrometheusRuleList, Resource<PrometheusRule>> prometheusRules();
233
MixedOperation<ServiceMonitor, ServiceMonitorList, Resource<ServiceMonitor>> serviceMonitors();
234
MixedOperation<PodMonitor, PodMonitorList, Resource<PodMonitor>> podMonitors();
235
}
236
```
237
238
[Monitoring](./monitoring.md)
239
240
### Multi-cluster Management
241
242
Hive-based multi-cluster management for provisioning, configuring, and managing multiple OpenShift clusters through the hive.openshift.io API group.
243
244
```java { .api }
245
OpenShiftHiveAPIGroupDSL hive();
246
247
interface OpenShiftHiveAPIGroupDSL {
248
NonNamespaceOperation<ClusterDeployment, ClusterDeploymentList, Resource<ClusterDeployment>> clusterDeployments();
249
NonNamespaceOperation<ClusterImageSet, ClusterImageSetList, Resource<ClusterImageSet>> clusterImageSets();
250
NonNamespaceOperation<ClusterPool, ClusterPoolList, Resource<ClusterPool>> clusterPools();
251
MixedOperation<MachinePool, MachinePoolList, Resource<MachinePool>> machinePools();
252
NonNamespaceOperation<SyncSet, SyncSetList, Resource<SyncSet>> syncSets();
253
}
254
```
255
256
[Multi-cluster Management](./multicluster-management.md)
257
258
## Core Types
259
260
```java { .api }
261
// Main Client Interfaces
262
public interface OpenShiftClient extends KubernetesClient { }
263
public interface NamespacedOpenShiftClient extends OpenShiftClient, NamespacedKubernetesClient { }
264
265
// Configuration
266
public class OpenShiftConfig extends Config {
267
public static final Long DEFAULT_BUILD_TIMEOUT = 5 * 60 * 1000L;
268
public static final String BASE_API_GROUP = "openshift.io";
269
}
270
271
// Exception Types
272
public class OpenShiftNotAvailableException extends RuntimeException { }
273
274
// Utility Types
275
public class ParameterValue {
276
public static ParameterValue pair(String name, String value);
277
}
278
```