Search in sources :

Example 76 with V1Pod

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

the class ReflectorRunnableTest method testReflectorRunnableShouldPardonList410ApiException.

@Test
public void testReflectorRunnableShouldPardonList410ApiException() throws ApiException {
    ApiException expectedException = new ApiException(410, "noxu");
    AtomicReference<Throwable> actualException = new AtomicReference<>();
    when(listerWatcher.list(any())).thenThrow(expectedException);
    ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable = new ReflectorRunnable<>(V1Pod.class, listerWatcher, deltaFIFO, (apiType, t) -> {
        actualException.set(t);
    });
    try {
        Thread thread = new Thread(reflectorRunnable::run);
        thread.setDaemon(true);
        thread.start();
        Awaitility.await().atMost(Duration.ofSeconds(1)).pollInterval(Duration.ofMillis(100)).until(() -> {
            return reflectorRunnable.isLastSyncResourceVersionUnavailable();
        });
    } finally {
        reflectorRunnable.stop();
    }
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1Pod(io.kubernetes.client.openapi.models.V1Pod) AtomicReference(java.util.concurrent.atomic.AtomicReference) ApiException(io.kubernetes.client.openapi.ApiException) Test(org.junit.Test)

Example 77 with V1Pod

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

the class ReflectorRunnableTest method testReflectorListShouldHandleExpiredResourceVersion.

@Test
public void testReflectorListShouldHandleExpiredResourceVersion() throws ApiException {
    String expectedResourceVersion = "100";
    when(listerWatcher.list(any())).thenReturn(new V1PodList().metadata(new V1ListMeta().resourceVersion(expectedResourceVersion)));
    // constantly failing watches will make the reflector run only one time
    when(listerWatcher.watch(any())).thenThrow(new ApiException(HttpURLConnection.HTTP_GONE, ""));
    ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable = new ReflectorRunnable<>(V1Pod.class, listerWatcher, deltaFIFO);
    CompletableFuture<Void> future = CompletableFuture.runAsync(reflectorRunnable::run);
    Awaitility.await().atMost(Duration.ofSeconds(2)).pollInterval(Duration.ofMillis(100)).until(() -> future.isDone());
    assertFalse(future.isCompletedExceptionally());
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1Pod(io.kubernetes.client.openapi.models.V1Pod) V1ListMeta(io.kubernetes.client.openapi.models.V1ListMeta) ApiException(io.kubernetes.client.openapi.ApiException) Test(org.junit.Test)

Example 78 with V1Pod

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

the class ReflectorRunnableTest method testReflectorWatchConnectionCloseOnError.

@Test
public void testReflectorWatchConnectionCloseOnError() throws InterruptedException {
    Watchable<V1Pod> watch = new MockWatch<V1Pod>(new Watch.Response<V1Pod>(EventType.ERROR.name(), new V1Status().status("403")));
    ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable = new ReflectorRunnable<>(V1Pod.class, new ListerWatcher<V1Pod, V1PodList>() {

        @Override
        public V1PodList list(CallGeneratorParams params) throws ApiException {
            return new V1PodList().metadata(new V1ListMeta());
        }

        @Override
        public Watchable<V1Pod> watch(CallGeneratorParams params) throws ApiException {
            return watch;
        }
    }, deltaFIFO);
    try {
        Thread thread = new Thread(reflectorRunnable::run);
        thread.setDaemon(true);
        thread.start();
        Awaitility.await().atMost(Duration.ofSeconds(1)).pollInterval(Duration.ofMillis(100)).until(() -> ((MockWatch<V1Pod>) watch).isClosed());
    } finally {
        reflectorRunnable.stop();
    }
}
Also used : V1Status(io.kubernetes.client.openapi.models.V1Status) CallGeneratorParams(io.kubernetes.client.util.CallGeneratorParams) V1ListMeta(io.kubernetes.client.openapi.models.V1ListMeta) V1PodList(io.kubernetes.client.openapi.models.V1PodList) Watchable(io.kubernetes.client.util.Watchable) Watch(io.kubernetes.client.util.Watch) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiException(io.kubernetes.client.openapi.ApiException) Test(org.junit.Test)

Example 79 with V1Pod

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

the class ReflectorRunnableTest method testReflectorWatchShouldRelistUponExpiredWatchItem.

@Test
public void testReflectorWatchShouldRelistUponExpiredWatchItem() throws ApiException {
    String expectedResourceVersion = "100";
    Watchable<V1Pod> expiredWatchable = mock(Watchable.class);
    when(expiredWatchable.hasNext()).thenReturn(true);
    when(expiredWatchable.next()).thenReturn(new Watch.Response<>(EventType.ERROR.name(), new V1Status().code(HttpURLConnection.HTTP_GONE)));
    when(listerWatcher.list(any())).thenReturn(new V1PodList().metadata(new V1ListMeta().resourceVersion(expectedResourceVersion)));
    // constantly failing watches will make the reflector run only one time
    when(listerWatcher.watch(any())).thenReturn(expiredWatchable);
    ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable = new ReflectorRunnable<>(V1Pod.class, listerWatcher, deltaFIFO);
    CompletableFuture<Void> future = CompletableFuture.runAsync(reflectorRunnable::run);
    Awaitility.await().atMost(Duration.ofSeconds(2)).pollInterval(Duration.ofMillis(100)).until(() -> future.isDone());
    assertFalse(future.isCompletedExceptionally());
}
Also used : V1Status(io.kubernetes.client.openapi.models.V1Status) V1ListMeta(io.kubernetes.client.openapi.models.V1ListMeta) V1PodList(io.kubernetes.client.openapi.models.V1PodList) Watch(io.kubernetes.client.util.Watch) V1Pod(io.kubernetes.client.openapi.models.V1Pod) Test(org.junit.Test)

Example 80 with V1Pod

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

the class CoreV1Api method readNamespacedPodEphemeralcontainersAsync.

/**
 * (asynchronously) read ephemeralcontainers of the specified Pod
 *
 * @param name name of the Pod (required)
 * @param namespace object name and auth scope, such as for teams and projects (required)
 * @param pretty If &#39;true&#39;, then the output is pretty printed. (optional)
 * @param _callback The callback to be executed when the API call finishes
 * @return The request call
 * @throws ApiException If fail to process the API call, e.g. serializing the request body object
 * @http.response.details
 *     <table summary="Response Details" border="1">
 * <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
 * <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
 * <tr><td> 401 </td><td> Unauthorized </td><td>  -  </td></tr>
 * </table>
 */
public okhttp3.Call readNamespacedPodEphemeralcontainersAsync(String name, String namespace, String pretty, final ApiCallback<V1Pod> _callback) throws ApiException {
    okhttp3.Call localVarCall = readNamespacedPodEphemeralcontainersValidateBeforeCall(name, namespace, pretty, _callback);
    Type localVarReturnType = new TypeToken<V1Pod>() {
    }.getType();
    localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
    return localVarCall;
}
Also used : Type(java.lang.reflect.Type) V1Pod(io.kubernetes.client.openapi.models.V1Pod)

Aggregations

V1Pod (io.kubernetes.client.openapi.models.V1Pod)96 Test (org.junit.Test)55 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)38 V1PodList (io.kubernetes.client.openapi.models.V1PodList)31 Type (java.lang.reflect.Type)22 ApiException (io.kubernetes.client.openapi.ApiException)17 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)17 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)15 ApiClient (io.kubernetes.client.openapi.ApiClient)12 V1Status (io.kubernetes.client.openapi.models.V1Status)9 Watch (io.kubernetes.client.util.Watch)9 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)8 JSON (io.kubernetes.client.openapi.JSON)7 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)7 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)4 V1Patch (io.kubernetes.client.custom.V1Patch)4 V1PodBuilder (io.kubernetes.client.openapi.models.V1PodBuilder)4