Search in sources :

Example 31 with ApiClient

use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.

the class ConfigTest method testDefaultClientNothingPresent.

@Test
public void testDefaultClientNothingPresent() {
    try {
        String path = withEnvironmentVariable("HOME", "/non-existent").and("HOMEDRIVE", null).and("USERPROFILE", null).execute(() -> {
            ApiClient client = Config.defaultClient();
            return client.getBasePath();
        });
        assertEquals("http://localhost:8080", path);
    } catch (Exception ex) {
        fail("Unexpected exception: " + ex);
    }
}
Also used : ApiClient(io.kubernetes.client.openapi.ApiClient) IOException(java.io.IOException) Test(org.junit.Test)

Example 32 with ApiClient

use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.

the class ConfigTest method testDefaultClientHomeDir.

@Test
public void testDefaultClientHomeDir() {
    try {
        String path = withEnvironmentVariable("HOME", dir.getCanonicalPath()).execute(() -> {
            ApiClient client = Config.defaultClient();
            return client.getBasePath();
        });
        assertEquals("http://home.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 33 with ApiClient

use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.

the class ConfigTest method testDefaultClientPrecedence.

@Test
public void testDefaultClientPrecedence() {
    try {
        String path = withEnvironmentVariable("HOME", dir.getCanonicalPath()).and("KUBECONFIG", configFile.getCanonicalPath()).execute(() -> {
            ApiClient client = Config.defaultClient();
            return client.getBasePath();
        });
        // $KUBECONFIG should take precedence over $HOME/.kube/config
        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 34 with ApiClient

use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.

the class GenericKubernetesApiForCoreApiTest method setup.

@Before
public void setup() throws IOException {
    ApiClient apiClient = new ClientBuilder().setBasePath("http://localhost:" + 8181).build();
    podClient = new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient);
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiClient(io.kubernetes.client.openapi.ApiClient) ClientBuilder(io.kubernetes.client.util.ClientBuilder) Before(org.junit.Before)

Example 35 with ApiClient

use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.

the class GenericKubernetesApiForCoreApiTest method testReadTimeoutShouldThrowException.

@Test
public void testReadTimeoutShouldThrowException() {
    ApiClient apiClient = new ClientBuilder().setBasePath("http://localhost:" + 8181).build();
    apiClient.setHttpClient(apiClient.getHttpClient().newBuilder().readTimeout(1, // timeout everytime
    TimeUnit.MILLISECONDS).build());
    stubFor(get(urlEqualTo("/api/v1/namespaces/foo/pods/test")).willReturn(aResponse().withFixedDelay(99999).withStatus(200).withBody("")));
    podClient = new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient);
    try {
        KubernetesApiResponse<V1Pod> response = podClient.get("foo", "test");
    } catch (Throwable t) {
        assertTrue(t.getCause() instanceof SocketTimeoutException);
        return;
    }
    fail("no exception happened");
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) SocketTimeoutException(java.net.SocketTimeoutException) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiClient(io.kubernetes.client.openapi.ApiClient) ClientBuilder(io.kubernetes.client.util.ClientBuilder) 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