or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/maven-io-fabric8--kubernetes-client-project

Java client for Kubernetes and OpenShift providing access to full REST APIs via a fluent DSL

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.fabric8/kubernetes-client-project@6.13.x

To install, run

npx @tessl/cli install tessl/maven-io-fabric8--kubernetes-client-project@6.13.0

0

# Fabric8 Kubernetes & OpenShift Java Client

1

2

The Fabric8 Kubernetes Client provides comprehensive access to both Kubernetes and OpenShift REST APIs through a fluent DSL. It supports both programmatic configuration and automatic configuration from multiple sources including kubeconfig files, service accounts, and environment variables.

3

4

## Package Information

5

6

- **Package Name**: io.fabric8:kubernetes-client-project

7

- **Package Type**: Maven

8

- **Language**: Java

9

- **Installation**: Add to your `pom.xml`:

10

11

```xml

12

<dependency>

13

<groupId>io.fabric8</groupId>

14

<artifactId>kubernetes-client</artifactId>

15

<version>6.13.5</version>

16

</dependency>

17

```

18

19

For OpenShift-specific features:

20

21

```xml

22

<dependency>

23

<groupId>io.fabric8</groupId>

24

<artifactId>openshift-client</artifactId>

25

<version>6.13.5</version>

26

</dependency>

27

```

28

29

Or with Gradle:

30

31

```gradle

32

implementation 'io.fabric8:kubernetes-client:6.13.5'

33

// For OpenShift features:

34

implementation 'io.fabric8:openshift-client:6.13.5'

35

```

36

37

## Core Imports

38

39

```java { .api }

40

import io.fabric8.kubernetes.client.KubernetesClient;

41

import io.fabric8.kubernetes.client.KubernetesClientBuilder;

42

import io.fabric8.openshift.client.OpenShiftClient;

43

import io.fabric8.openshift.client.OpenShiftConfig;

44

import io.fabric8.openshift.client.OpenShiftConfigBuilder;

45

import io.fabric8.openshift.client.NamespacedOpenShiftClient;

46

```

47

48

Resource model imports:

49

50

```java { .api }

51

import io.fabric8.openshift.api.model.*;

52

import io.fabric8.kubernetes.client.dsl.Resource;

53

import io.fabric8.kubernetes.client.dsl.MixedOperation;

54

```

55

56

## Basic Usage

57

58

```java

59

import io.fabric8.kubernetes.client.KubernetesClientBuilder;

60

import io.fabric8.openshift.client.OpenShiftClient;

61

62

// Create OpenShift client using default configuration (kubeconfig, service account, etc.)

63

try (OpenShiftClient client = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class)) {

64

// Get cluster information

65

System.out.println("OpenShift URL: " + client.getOpenshiftUrl());

66

System.out.println("Current user: " + client.currentUser().getMetadata().getName());

67

68

// List all projects

69

client.projects().list().getItems().forEach(project ->

70

System.out.println("Project: " + project.getMetadata().getName()));

71

72

// Work with builds in a specific namespace

73

client.inNamespace("my-project").builds().list().getItems().forEach(build ->

74

System.out.println("Build: " + build.getMetadata().getName()));

75

}

76

```

77

78

## Capabilities

79

80

### Client Configuration and Creation

81

82

Configure OpenShift client with custom settings, authentication, and connection options.

83

84

```java { .api }

85

// Method 1: Using OpenShiftConfig with KubernetesClientBuilder

86

OpenShiftConfig config = new OpenShiftConfigBuilder()

87

.withMasterUrl("https://api.openshift-cluster.example.com:6443")

88

.withOauthToken("your-token")

89

.withNamespace("default")

90

.withTrustCerts(true)

91

.build();

92

93

OpenShiftClient client = new KubernetesClientBuilder()

94

.withConfig(config)

95

.build()

96

.adapt(OpenShiftClient.class);

97

98

// Method 2: Using ConfigBuilder with KubernetesClientBuilder

99

Config config = new ConfigBuilder()

100

.withMasterUrl("https://api.openshift-cluster.example.com:6443")

101

.withOauthToken("your-token")

102

.build();

103

104

OpenShiftClient client = new KubernetesClientBuilder()

105

.withConfig(config)

106

.build()

107

.adapt(OpenShiftClient.class);

108

```

109

110

[Client Configuration and Creation](./client-configuration.md)

111

112

### Build Operations

113

114

Manage OpenShift builds and build configurations, including binary builds, webhook triggers, and log streaming.

115

116

```java { .api }

117

Build build = client.builds()

118

.inNamespace("my-project")

119

.withName("my-app-1")

120

.get();

121

122

String buildLog = client.builds()

123

.inNamespace("my-project")

124

.withName("my-app-1")

125

.getLog();

126

```

127

128

[Build Operations](./build-operations.md)

129

130

### Deployment Operations

131

132

Work with OpenShift DeploymentConfigs including scaling, rollouts, and pod operations.

133

134

```java { .api }

135

DeploymentConfig dc = client.deploymentConfigs()

136

.inNamespace("my-project")

137

.withName("my-app")

138

.scale(3);

139

140

List<Pod> pods = client.deploymentConfigs()

141

.inNamespace("my-project")

142

.withName("my-app")

143

.getPods();

144

```

145

146

[Deployment Operations](./deployment-operations.md)

147

148

### Image Operations

149

150

Manage container images, image streams, image stream tags, and image imports.

151

152

```java { .api }

153

ImageStream imageStream = client.imageStreams()

154

.inNamespace("my-project")

155

.withName("my-app")

156

.get();

157

158

ImageStreamImport importResult = client.imageStreamImports()

159

.inNamespace("my-project")

160

.create(imageStreamImport);

161

```

162

163

[Image Operations](./image-operations.md)

164

165

### Network Operations

166

167

Configure OpenShift routes, network policies, and cluster networking.

168

169

```java { .api }

170

Route route = client.routes()

171

.inNamespace("my-project")

172

.withName("my-app")

173

.get();

174

175

String routeUrl = "https://" + route.getSpec().getHost();

176

```

177

178

[Network Operations](./network-operations.md)

179

180

### Template Operations

181

182

Process OpenShift templates with parameters and instantiate applications.

183

184

```java { .api }

185

Template template = client.templates()

186

.inNamespace("my-project")

187

.withName("my-template")

188

.withParameters("PARAM_NAME", "param-value")

189

.process();

190

```

191

192

[Template Operations](./template-operations.md)

193

194

### Project Operations

195

196

Create and manage OpenShift projects with role bindings and quotas.

197

198

```java { .api }

199

Project project = client.projects()

200

.createProjectAndRoleBindings("new-project",

201

"Project description", "display-name", "admin-user");

202

```

203

204

[Project Operations](./project-operations.md)

205

206

### User and Security Operations

207

208

Manage users, groups, roles, role bindings, and security context constraints.

209

210

```java { .api }

211

User currentUser = client.currentUser();

212

213

List<Role> roles = client.roles()

214

.inNamespace("my-project")

215

.list().getItems();

216

```

217

218

[User and Security Operations](./user-security.md)

219

220

### API Group Operations

221

222

Access specialized OpenShift API groups for configuration, operators, monitoring, and more.

223

224

```java { .api }

225

// Access config API group (config.openshift.io)

226

ClusterVersion clusterVersion = client.config().clusterVersions()

227

.withName("version")

228

.get();

229

230

// Access monitoring API group (monitoring.coreos.com)

231

ServiceMonitor monitor = client.monitoring().serviceMonitors()

232

.inNamespace("my-project")

233

.withName("my-monitor")

234

.get();

235

```

236

237

[API Group Operations](./api-group-operations.md)

238

239

### OAuth and Authentication Operations

240

241

Manage OpenShift OAuth tokens, clients, and access tokens for authentication.

242

243

```java { .api }

244

// OAuth access tokens

245

List<OAuthAccessToken> tokens = client.oAuthAccessTokens().list().getItems();

246

247

// OAuth clients

248

OAuthClient oauthClient = client.oAuthClients()

249

.withName("my-oauth-client")

250

.get();

251

252

// User OAuth access tokens

253

List<UserOAuthAccessToken> userTokens = client.userOAuthAccessTokens()

254

.list().getItems();

255

```

256

257

### Identity and User Management Operations

258

259

Manage OpenShift identities, users, and user identity mappings.

260

261

```java { .api }

262

// Get current user

263

User currentUser = client.currentUser();

264

265

// List users

266

List<User> users = client.users().list().getItems();

267

268

// List identities

269

List<Identity> identities = client.identities().list().getItems();

270

271

// Create user identity mapping

272

UserIdentityMapping mapping = client.userIdentityMappings()

273

.create(userIdentityMapping);

274

```

275

276

### Cluster-Level Network Operations

277

278

Manage cluster-wide networking resources including cluster networks and host subnets.

279

280

```java { .api }

281

// Cluster networks

282

List<ClusterNetwork> clusterNetworks = client.clusterNetworks()

283

.list().getItems();

284

285

// Host subnets

286

List<HostSubnet> hostSubnets = client.hostSubnets()

287

.list().getItems();

288

289

// Net namespaces

290

List<NetNamespace> netNamespaces = client.netNamespaces()

291

.list().getItems();

292

```

293

294

### Quota and Resource Management

295

296

Access OpenShift quota API group for advanced resource management.

297

298

```java { .api }

299

// Access quota API group resources

300

client.quotas().clusterResourceQuotas()

301

.list().getItems();

302

```

303

304

### Machine Configuration Operations

305

306

Manage OpenShift Machine Config Operator resources for cluster configuration.

307

308

```java { .api }

309

// Access machine configuration API group

310

client.machineConfigurations().machineConfigs()

311

.list().getItems();

312

313

// Machine API group

314

client.machine().machines()

315

.inNamespace("openshift-machine-api")

316

.list().getItems();

317

```

318

319

### Version and Cluster Information

320

321

Get OpenShift cluster version and cluster information.

322

323

```java { .api }

324

// Get OpenShift version

325

VersionInfo openshiftVersion = client.getOpenShiftV3Version();

326

String v4Version = client.getOpenShiftV4Version();

327

328

// Get cluster URL

329

URL openshiftUrl = client.getOpenshiftUrl();

330

331

// Check API group support

332

boolean supportsApiGroup = client.supportsOpenShiftAPIGroup("config.openshift.io");

333

```

334

335

### Authorization Reviews

336

337

Perform access reviews and security policy validations.

338

339

```java { .api }

340

SubjectAccessReviewResponse response = client.subjectAccessReviews()

341

.create(subjectAccessReview);

342

343

boolean canAccess = response.getAllowed();

344

```

345

346

[Authorization Reviews](./authorization-reviews.md)

347

348

## Architecture

349

350

The OpenShift client extends the Kubernetes client with OpenShift-specific functionality:

351

352

- **OpenShiftClient**: Main interface extending KubernetesClient

353

- **NamespacedOpenShiftClient**: Namespace-scoped operations

354

- **OpenShiftConfig**: Configuration with OpenShift-specific settings

355

- **Specialized DSL interfaces**: Custom operations for OpenShift resources

356

- **API Group DSLs**: Access to specialized OpenShift API groups

357

- **OAuth interceptor**: Automatic OpenShift authentication handling

358

359

## Types

360

361

### Core Client Types

362

363

```java { .api }

364

public interface OpenShiftClient extends KubernetesClient, SupportTestingClient {

365

String BASE_API_GROUP = "openshift.io";

366

367

// Core OpenShift client methods

368

URL getOpenshiftUrl();

369

User currentUser();

370

boolean supportsOpenShiftAPIGroup(String apiGroup);

371

VersionInfo getOpenShiftV3Version();

372

String getOpenShiftV4Version();

373

374

// API Group DSLs

375

OpenShiftConfigAPIGroupDSL config();

376

OpenShiftConsoleAPIGroupDSL console();

377

OpenShiftClusterAutoscalingAPIGroupDSL clusterAutoscaling();

378

OpenShiftHiveAPIGroupDSL hive();

379

OpenShiftOperatorAPIGroupDSL operator();

380

OpenShiftOperatorHubAPIGroupDSL operatorHub();

381

OpenShiftMonitoringAPIGroupDSL monitoring();

382

MachineConfigurationAPIGroupDSL machineConfigurations();

383

OpenShiftMachineAPIGroupDSL machine();

384

OpenShiftQuotaAPIGroupDSL quotas();

385

OpenShiftTunedAPIGroupDSL tuned();

386

OpenShiftStorageVersionMigratorApiGroupDSL kubeStorageVersionMigrator();

387

OpenShiftWhereaboutsAPIGroupDSL whereabouts();

388

389

// Resource operations

390

MixedOperation<Build, BuildList, BuildResource> builds();

391

MixedOperation<BuildConfig, BuildConfigList, BuildConfigResource<BuildConfig, Void, Build>> buildConfigs();

392

MixedOperation<DeploymentConfig, DeploymentConfigList, DeployableScalableResource<DeploymentConfig>> deploymentConfigs();

393

MixedOperation<Route, RouteList, Resource<Route>> routes();

394

ParameterMixedOperation<Template, TemplateList, TemplateResource> templates();

395

MixedOperation<ImageStream, ImageStreamList, Resource<ImageStream>> imageStreams();

396

MixedOperation<ImageStreamTag, ImageStreamTagList, Resource<ImageStreamTag>> imageStreamTags();

397

398

// Project operations

399

ProjectOperation projects();

400

ProjectRequestOperation projectrequests();

401

402

// Security and RBAC

403

NonNamespaceOperation<SecurityContextConstraints, SecurityContextConstraintsList, Resource<SecurityContextConstraints>> securityContextConstraints();

404

MixedOperation<Role, RoleList, Resource<Role>> roles();

405

MixedOperation<RoleBinding, RoleBindingList, Resource<RoleBinding>> roleBindings();

406

NonNamespaceOperation<ClusterRole, ClusterRoleList, Resource<ClusterRole>> clusterRoles();

407

MixedOperation<ClusterRoleBinding, ClusterRoleBindingList, Resource<ClusterRoleBinding>> clusterRoleBindings();

408

409

// User and identity management

410

NonNamespaceOperation<User, UserList, Resource<User>> users();

411

NonNamespaceOperation<Group, GroupList, Resource<Group>> groups();

412

NonNamespaceOperation<Identity, IdentityList, Resource<Identity>> identities();

413

414

// OAuth operations

415

NonNamespaceOperation<OAuthAccessToken, OAuthAccessTokenList, Resource<OAuthAccessToken>> oAuthAccessTokens();

416

NonNamespaceOperation<OAuthClient, OAuthClientList, Resource<OAuthClient>> oAuthClients();

417

NonNamespaceOperation<UserOAuthAccessToken, UserOAuthAccessTokenList, Resource<UserOAuthAccessToken>> userOAuthAccessTokens();

418

419

// Network operations

420

NonNamespaceOperation<ClusterNetwork, ClusterNetworkList, Resource<ClusterNetwork>> clusterNetworks();

421

NonNamespaceOperation<HostSubnet, HostSubnetList, Resource<HostSubnet>> hostSubnets();

422

NonNamespaceOperation<NetNamespace, NetNamespaceList, Resource<NetNamespace>> netNamespaces();

423

MixedOperation<EgressNetworkPolicy, EgressNetworkPolicyList, Resource<EgressNetworkPolicy>> egressNetworkPolicies();

424

425

// Authorization reviews

426

InOutCreateable<SubjectAccessReview, SubjectAccessReviewResponse> subjectAccessReviews();

427

InOutCreateable<ResourceAccessReview, ResourceAccessReviewResponse> resourceAccessReviews();

428

NamespacedInOutCreateable<LocalSubjectAccessReview, SubjectAccessReviewResponse> localSubjectAccessReviews();

429

NamespacedInOutCreateable<LocalResourceAccessReview, ResourceAccessReviewResponse> localResourceAccessReviews();

430

}

431

432

public interface NamespacedOpenShiftClient extends OpenShiftClient, NamespacedKubernetesClient {

433

}

434

435

public class OpenShiftConfig extends Config {

436

public static final Long DEFAULT_BUILD_TIMEOUT = 5 * 60 * 1000L;

437

438

public String getOapiVersion();

439

public String getOpenShiftUrl();

440

public long getBuildTimeout();

441

public boolean isDisableApiGroupCheck();

442

}

443

```

444

445

### Configuration Builder

446

447

```java { .api }

448

public class OpenShiftConfigBuilder {

449

public OpenShiftConfigBuilder withMasterUrl(String masterUrl);

450

public OpenShiftConfigBuilder withOauthToken(String token);

451

public OpenShiftConfigBuilder withUsername(String username);

452

public OpenShiftConfigBuilder withPassword(String password);

453

public OpenShiftConfigBuilder withNamespace(String namespace);

454

public OpenShiftConfigBuilder withTrustCerts(boolean trustCerts);

455

public OpenShiftConfigBuilder withBuildTimeout(long timeout);

456

public OpenShiftConfig build();

457

}

458

```

459

460

### Client Creation Patterns

461

462

```java { .api }

463

// Recommended approach using KubernetesClientBuilder

464

OpenShiftClient client = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class);

465

466

// With custom configuration

467

OpenShiftClient client = new KubernetesClientBuilder()

468

.withConfig(config)

469

.build()

470

.adapt(OpenShiftClient.class);

471

472

// Legacy approach (deprecated)

473

@Deprecated

474

OpenShiftClient client = new DefaultOpenShiftClient();

475

@Deprecated

476

OpenShiftClient client = new DefaultOpenShiftClient(config);

477

```

478

```