Search in sources :

Example 36 with ApiClient

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

the class GenericKubernetesGetApiTest method setup.

@Before
public void setup() {
    ApiClient apiClient = new ClientBuilder().setBasePath("http://localhost:" + 8181).build();
    jobClient = new GenericKubernetesApi<>(V1Job.class, V1JobList.class, "batch", "v1", "jobs", apiClient);
    fooClient = new GenericKubernetesApi<>(FooCustomResource.class, FooCustomResourceList.class, "example.io", "v1", "foos", 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 37 with ApiClient

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

the class GenericKubernetesApiTest 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("/apis/batch/v1/namespaces/foo/jobs/test")).willReturn(aResponse().withFixedDelay(99999).withStatus(200).withBody("")));
    jobClient = new GenericKubernetesApi<>(V1Job.class, V1JobList.class, "batch", "v1", "jobs", apiClient);
    try {
        KubernetesApiResponse<V1Job> response = jobClient.get("foo", "test");
    } catch (Throwable t) {
        assertTrue(t.getCause() instanceof SocketTimeoutException);
        return;
    }
    fail("no exception happened");
}
Also used : V1Job(io.kubernetes.client.openapi.models.V1Job) SocketTimeoutException(java.net.SocketTimeoutException) V1JobList(io.kubernetes.client.openapi.models.V1JobList) ApiClient(io.kubernetes.client.openapi.ApiClient) ClientBuilder(io.kubernetes.client.util.ClientBuilder) Test(org.junit.Test)

Example 38 with ApiClient

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

the class KubernetesApiResponseTest method setup.

@Before
public void setup() throws IOException {
    ApiClient apiClient = new ClientBuilder().setBasePath("http://localhost:" + 8485).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 39 with ApiClient

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

the class ClientBuilderTest method testDefaultClientUTF8EncodedConfig.

@Test
public void testDefaultClientUTF8EncodedConfig() throws Exception {
    String path = withEnvironmentVariable("KUBECONFIG", KUBECONFIG_UTF8_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)

Example 40 with ApiClient

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

the class ClientBuilderTest method testKubeconfigDisablesVerifySsl.

@Test
public void testKubeconfigDisablesVerifySsl() throws Exception {
    boolean isVerifyingSsl = withEnvironmentVariable("KUBECONFIG", KUBECONFIG_HTTP_FILE_PATH).execute(() -> {
        final ApiClient client = ClientBuilder.standard().build();
        return client.isVerifyingSsl();
    });
    assertThat(isVerifyingSsl, is(false));
}
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