Search in sources :

Example 26 with ApiClient

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);
}
Also used : V1Job(io.kubernetes.client.openapi.models.V1Job) V1JobList(io.kubernetes.client.openapi.models.V1JobList) ApiClient(io.kubernetes.client.openapi.ApiClient) ClientBuilder(io.kubernetes.client.util.ClientBuilder) Before(org.junit.Before)

Example 27 with 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);
    }
}
Also used : ApiClient(io.kubernetes.client.openapi.ApiClient) IOException(java.io.IOException) Test(org.junit.Test)

Example 28 with ApiClient

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;
}
Also used : TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) IOException(java.io.IOException) ApiClient(io.kubernetes.client.openapi.ApiClient)

Example 29 with ApiClient

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);
}
Also used : ApiClient(io.kubernetes.client.openapi.ApiClient) Test(org.junit.Test)

Example 30 with ApiClient

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);
}
Also used : ApiClient(io.kubernetes.client.openapi.ApiClient) Test(org.junit.Test)

Aggregations

ApiClient (io.kubernetes.client.openapi.ApiClient)61 Test (org.junit.Test)28 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)13 V1Pod (io.kubernetes.client.openapi.models.V1Pod)12 IOException (java.io.IOException)11 V1PodList (io.kubernetes.client.openapi.models.V1PodList)9 ClientBuilder (io.kubernetes.client.util.ClientBuilder)6 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)5 Before (org.junit.Before)5 ApiException (io.kubernetes.client.openapi.ApiException)4 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)3 V1Job (io.kubernetes.client.openapi.models.V1Job)3 V1JobList (io.kubernetes.client.openapi.models.V1JobList)3 V1Namespace (io.kubernetes.client.openapi.models.V1Namespace)3 OkHttpClient (okhttp3.OkHttpClient)3 NodeMetrics (io.kubernetes.client.custom.NodeMetrics)2 PodMetrics (io.kubernetes.client.custom.PodMetrics)2 V1Patch (io.kubernetes.client.custom.V1Patch)2 LeaderElectionConfig (io.kubernetes.client.extended.leaderelection.LeaderElectionConfig)2 LeaderElector (io.kubernetes.client.extended.leaderelection.LeaderElector)2