or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

client-setup.mdconfiguration-management.mdcore-resources.mdindex.mdmachine-management.mdmonitoring.mdmulticluster-management.mdoperator-management.mdsecurity-rbac.md

client-setup.mddocs/

0

# Client Configuration and Setup

1

2

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

3

4

## Capabilities

5

6

### OpenShift Client Creation

7

8

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

9

10

```java { .api }

11

/**

12

* Main OpenShift client interface providing access to all OpenShift-specific resources

13

* Extends KubernetesClient with OpenShift-specific operations

14

*/

15

public interface OpenShiftClient extends KubernetesClient {

16

String BASE_API_GROUP = "openshift.io";

17

18

/** Get OpenShift cluster URL */

19

URL getOpenshiftUrl();

20

21

/** Get Kubernetes version information */

22

VersionInfo getVersion();

23

24

/** Get OpenShift v3 version from version/openshift endpoint */

25

VersionInfo getOpenShiftV3Version();

26

27

/** Get OpenShift v4 server version */

28

String getOpenShiftV4Version();

29

30

/** Get current logged-in user (equivalent to 'oc whoami') */

31

User currentUser();

32

33

/** Check if cluster supports specific OpenShift API group */

34

boolean supportsOpenShiftAPIGroup(String apiGroup);

35

36

/** Configure request settings for operations */

37

FunctionCallable<NamespacedOpenShiftClient> withRequestConfig(RequestConfig requestConfig);

38

}

39

```

40

41

**Usage Examples:**

42

43

```java

44

import io.fabric8.openshift.client.OpenShiftClient;

45

import io.fabric8.kubernetes.client.KubernetesClientBuilder;

46

47

// Recommended: Create client using builder (auto-configures from kubeconfig/env)

48

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

49

// Use client

50

User user = client.currentUser();

51

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

52

}

53

54

// Legacy: Direct instantiation (deprecated but still available)

55

try (OpenShiftClient client = new DefaultOpenShiftClient()) {

56

String version = client.getOpenShiftV4Version();

57

System.out.println("OpenShift version: " + version);

58

}

59

```

60

61

### Namespace-aware Client

62

63

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

64

65

```java { .api }

66

/**

67

* Namespace-aware OpenShift client interface

68

* Combines OpenShiftClient and NamespacedKubernetesClient capabilities

69

*/

70

public interface NamespacedOpenShiftClient extends OpenShiftClient, NamespacedKubernetesClient {

71

/** Switch to operate in any namespace */

72

NamespacedOpenShiftClient inAnyNamespace();

73

74

/** Switch to operate in specific namespace */

75

NamespacedOpenShiftClient inNamespace(String namespace);

76

77

/** Configure request settings for operations */

78

FunctionCallable<NamespacedOpenShiftClient> withRequestConfig(RequestConfig requestConfig);

79

}

80

```

81

82

**Usage Examples:**

83

84

```java

85

// Work with namespace-scoped operations

86

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

87

// Switch to specific namespace

88

NamespacedOpenShiftClient namespacedClient = client.inNamespace("myproject");

89

90

// List builds in current namespace

91

BuildList builds = namespacedClient.builds().list();

92

93

// Switch to any namespace for cross-namespace operations

94

NamespacedOpenShiftClient anyNsClient = namespacedClient.inAnyNamespace();

95

ProjectList allProjects = anyNsClient.projects().list();

96

}

97

```

98

99

### OpenShift Configuration

100

101

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

102

103

```java { .api }

104

/**

105

* OpenShift-specific configuration class

106

* Extends Kubernetes Config with OpenShift-specific settings

107

*/

108

public class OpenShiftConfig extends Config {

109

/** Default build timeout (5 minutes) */

110

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

111

112

/** System property keys */

113

public static final String KUBERNETES_OAPI_VERSION_SYSTEM_PROPERTY = "kubernetes.oapi.version";

114

public static final String OPENSHIFT_URL_SYSTEM_PROPERTY = "openshift.url";

115

public static final String OPENSHIFT_BUILD_TIMEOUT_SYSTEM_PROPERTY = "openshift.build.timeout";

116

117

/** Create OpenShift config from Kubernetes config */

118

public OpenShiftConfig(Config kubernetesConfig);

119

120

/** Create OpenShift config with specific URL */

121

public OpenShiftConfig(Config kubernetesConfig, String openShiftUrl);

122

123

/** Get OpenShift API version (default: "v1") */

124

public String getOapiVersion();

125

126

/** Set OpenShift API version */

127

public void setOapiVersion(String oapiVersion);

128

129

/** Get OpenShift cluster URL */

130

public String getOpenShiftUrl();

131

132

/** Set OpenShift cluster URL */

133

public void setOpenShiftUrl(String openShiftUrl);

134

135

/** Get build timeout in milliseconds */

136

public long getBuildTimeout();

137

138

/** Set build timeout in milliseconds */

139

public void setBuildTimeout(long buildTimeout);

140

141

/** Check if API group validation is disabled */

142

public boolean isDisableApiGroupCheck();

143

144

/** Set API group validation flag */

145

public void setDisableApiGroupCheck(boolean disableApiGroupCheck);

146

147

/** Wrap Kubernetes config as OpenShift config */

148

public static OpenShiftConfig wrap(Config config);

149

}

150

```

151

152

**Usage Examples:**

153

154

```java

155

import io.fabric8.openshift.client.OpenShiftConfig;

156

import io.fabric8.kubernetes.client.Config;

157

import io.fabric8.kubernetes.client.ConfigBuilder;

158

159

// Create OpenShift config from Kubernetes config

160

Config k8sConfig = new ConfigBuilder()

161

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

162

.withOauthToken("my-token")

163

.build();

164

165

OpenShiftConfig osConfig = new OpenShiftConfig(k8sConfig);

166

167

// Customize OpenShift-specific settings

168

osConfig.setBuildTimeout(10 * 60 * 1000L); // 10 minutes

169

osConfig.setOapiVersion("v1");

170

171

// Use config with client

172

try (OpenShiftClient client = new DefaultOpenShiftClient(osConfig)) {

173

// Client operations

174

}

175

```

176

177

### Configuration Builder

178

179

Builder pattern for constructing OpenShift configurations with fluent API.

180

181

```java { .api }

182

/**

183

* Builder for OpenShiftConfig with fluent API

184

* Generated builder providing type-safe configuration construction

185

*/

186

public class OpenShiftConfigBuilder {

187

public OpenShiftConfigBuilder();

188

public OpenShiftConfigBuilder withOpenShiftUrl(String openShiftUrl);

189

public OpenShiftConfigBuilder withOapiVersion(String oapiVersion);

190

public OpenShiftConfigBuilder withBuildTimeout(Long buildTimeout);

191

public OpenShiftConfigBuilder withDisableApiGroupCheck(Boolean disableApiGroupCheck);

192

public OpenShiftConfig build();

193

}

194

```

195

196

**Usage Examples:**

197

198

```java

199

import io.fabric8.openshift.client.OpenShiftConfigBuilder;

200

201

// Build configuration using fluent API

202

OpenShiftConfig config = new OpenShiftConfigBuilder()

203

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

204

.withOauthToken("my-token")

205

.withOpenShiftUrl("https://api.my-cluster.com:6443/oapi/v1")

206

.withBuildTimeout(15 * 60 * 1000L) // 15 minutes

207

.withDisableApiGroupCheck(false)

208

.build();

209

210

try (OpenShiftClient client = new DefaultOpenShiftClient(config)) {

211

// Use configured client

212

}

213

```

214

215

### Legacy Client (Deprecated)

216

217

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

218

219

```java { .api }

220

/**

221

* Default OpenShift client implementation (deprecated)

222

* @deprecated Use KubernetesClientBuilder().build().adapt(OpenShiftClient.class) instead

223

*/

224

@Deprecated

225

public class DefaultOpenShiftClient extends NamespacedOpenShiftClientAdapter {

226

public static final String OPENSHIFT_VERSION_ENDPOINT = "version/openshift";

227

228

/** Default constructor with auto-configuration */

229

public DefaultOpenShiftClient();

230

231

/** Constructor with master URL */

232

public DefaultOpenShiftClient(String masterUrl);

233

234

/** Constructor with Kubernetes config */

235

public DefaultOpenShiftClient(Config config);

236

237

/** Constructor with OpenShift config */

238

public DefaultOpenShiftClient(OpenShiftConfig config);

239

240

/** Constructor with custom HTTP client and config */

241

public DefaultOpenShiftClient(HttpClient httpClient, OpenShiftConfig config);

242

}

243

```

244

245

### Environment Configuration

246

247

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

248

249

**Kubernetes Environment Variables:**

250

- `KUBERNETES_MASTER` / `kubernetes.master` - Kubernetes master URL

251

- `KUBERNETES_NAMESPACE` / `kubernetes.namespace` - Default namespace

252

- `KUBERNETES_AUTH_TOKEN` / `kubernetes.auth.token` - Authentication token

253

- `KUBECONFIG` / `kubeconfig` - Path to kubeconfig file

254

255

**OpenShift-Specific Environment Variables:**

256

- `OPENSHIFT_URL` / `openshift.url` - OpenShift API URL (overrides derived URL)

257

- `KUBERNETES_OAPI_VERSION` / `kubernetes.oapi.version` - OpenShift API version

258

- `OPENSHIFT_BUILD_TIMEOUT` / `openshift.build.timeout` - Build operation timeout

259

260

### Request Configuration

261

262

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

263

264

```java { .api }

265

/**

266

* Configure request settings for client operations

267

*/

268

public interface FunctionCallable<T> extends Callable<T> {

269

T call();

270

}

271

```

272

273

**Usage Examples:**

274

275

```java

276

import io.fabric8.kubernetes.client.RequestConfig;

277

import io.fabric8.kubernetes.client.RequestConfigBuilder;

278

279

// Configure request settings

280

RequestConfig requestConfig = new RequestConfigBuilder()

281

.withRequestTimeout(30000) // 30 seconds

282

.withConnectionTimeout(10000) // 10 seconds

283

.withRequestRetryBackoffLimit(3)

284

.build();

285

286

// Apply to client operations

287

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

288

NamespacedOpenShiftClient configuredClient = client.withRequestConfig(requestConfig).call();

289

290

// Operations use the configured request settings

291

BuildList builds = configuredClient.builds().list();

292

}

293

```

294

295

### Version and Capability Detection

296

297

Detect OpenShift cluster capabilities and version information for compatibility checks.

298

299

**Usage Examples:**

300

301

```java

302

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

303

// Check OpenShift availability and version

304

try {

305

VersionInfo osVersion = client.getOpenShiftV3Version();

306

String v4Version = client.getOpenShiftV4Version();

307

System.out.println("OpenShift v3 info: " + osVersion);

308

System.out.println("OpenShift v4 version: " + v4Version);

309

} catch (Exception e) {

310

System.out.println("OpenShift version detection failed: " + e.getMessage());

311

}

312

313

// Check API group support

314

boolean supportsBuilds = client.supportsOpenShiftAPIGroup("build.openshift.io");

315

boolean supportsImages = client.supportsOpenShiftAPIGroup("image.openshift.io");

316

317

if (supportsBuilds) {

318

// Use build APIs

319

BuildList builds = client.builds().list();

320

}

321

322

// Get current user context

323

try {

324

User currentUser = client.currentUser();

325

System.out.println("Authenticated as: " + currentUser.getMetadata().getName());

326

327

// Check user groups

328

List<String> groups = currentUser.getGroups();

329

System.out.println("User groups: " + groups);

330

} catch (Exception e) {

331

System.out.println("Failed to get current user: " + e.getMessage());

332

}

333

}

334

```