use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class GenericKubernetesApiTest method setup.
@Before
public void setup() throws IOException {
ApiClient apiClient = new ClientBuilder().setBasePath("http://localhost:" + 8181).build();
jobClient = new GenericKubernetesApi<>(V1Job.class, V1JobList.class, "batch", "v1", "jobs", apiClient);
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class ConfigTest method testDefaultClientKubeConfig.
@Test
public void testDefaultClientKubeConfig() {
try {
String path = withEnvironmentVariable("KUBECONFIG", configFile.getCanonicalPath()).execute(() -> {
ApiClient client = Config.defaultClient();
return client.getBasePath();
});
assertEquals("http://kubeconfig.dir.com", path);
} catch (Exception ex) {
ex.printStackTrace();
fail("Unexpected exception: " + ex);
}
}
use of io.kubernetes.client.openapi.ApiClient in project pravega by pravega.
the class K8sClient method initializeApiClient.
/**
* Create an instance of K8 api client and initialize with the KUBERNETES config. The config used follows the below pattern.
* 1. If $KUBECONFIG is defined, use that config file.
* 2. If $HOME/.kube/config can be found, use that.
* 3. If the in-cluster service account can be found, assume in cluster config.
* 4. Default to localhost:8080 as a last resort.
*/
private ApiClient initializeApiClient() {
ApiClient client;
try {
log.debug("Initialize KUBERNETES api client");
client = Config.defaultClient();
// this can be set to true enable http dump.
client.setDebugging(false);
client.setHttpClient(client.getHttpClient().newBuilder().readTimeout(DEFAULT_TIMEOUT_MINUTES, TimeUnit.MINUTES).build());
Configuration.setDefaultApiClient(client);
Runtime.getRuntime().addShutdownHook(new Thread(this::close));
} catch (IOException e) {
throw new TestFrameworkException(ConnectionFailed, "Connection to the k8 cluster failed, ensure .kube/config is configured correctly.", e);
}
return client;
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class ClientBuilderTest method testDefaultClientWithNoFiles.
@Test
public void testDefaultClientWithNoFiles() throws Exception {
String path = withEnvironmentVariable("HOME", "/non-existent").and("HOMEDRIVE", null).and("USERPROFILE", null).and("KUBECONFIG", null).execute(() -> {
final ApiClient client = ClientBuilder.defaultClient();
return client.getBasePath();
});
assertEquals("http://localhost:8080", path);
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class ClientBuilderTest method testDefaultClientReadsKubeConfig.
@Test
public void testDefaultClientReadsKubeConfig() throws Exception {
String path = withEnvironmentVariable("KUBECONFIG", KUBECONFIG_FILE_PATH).execute(() -> {
final ApiClient client = ClientBuilder.defaultClient();
return client.getBasePath();
});
assertEquals("http://kubeconfig.dir.com", path);
}
Aggregations