Search in sources :

Example 1 with BaseOperation

use of io.fabric8.kubernetes.client.dsl.internal.BaseOperation in project kubernetes-client by fabric8io.

the class BaseOperationTest method testGetWriteOperationUrlWithDryRunDisabled.

@Test
void testGetWriteOperationUrlWithDryRunDisabled() throws MalformedURLException {
    // Given
    BaseOperation baseOp = new BaseOperation(new OperationContext().withConfig(new ConfigBuilder().withMasterUrl("https://172.17.0.2:8443").build()).withPlural("pods"));
    baseOp.setType(Pod.class);
    baseOp.setListType(PodList.class);
    // When
    URL result = baseOp.getResourceURLForWriteOperation(new URL("https://172.17.0.2:8443/api/v1/namespaces/ns1/pods/foo"));
    // Then
    assertNotNull(result);
    assertEquals("https://172.17.0.2:8443/api/v1/namespaces/ns1/pods/foo", result.toString());
}
Also used : OperationContext(io.fabric8.kubernetes.client.dsl.internal.OperationContext) PodOperationContext(io.fabric8.kubernetes.client.dsl.internal.PodOperationContext) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) BaseOperation(io.fabric8.kubernetes.client.dsl.internal.BaseOperation) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 2 with BaseOperation

use of io.fabric8.kubernetes.client.dsl.internal.BaseOperation in project kubernetes-client by fabric8io.

the class BaseOperationTest method testHttpRetryWithLessFailuresThanRetries.

@Test
void testHttpRetryWithLessFailuresThanRetries() throws MalformedURLException, IOException {
    final AtomicInteger httpExecutionCounter = new AtomicInteger(0);
    HttpClient mockClient = newHttpClientWithSomeFailures(httpExecutionCounter, 2);
    BaseOperation<Pod, PodList, Resource<Pod>> baseOp = new BaseOperation(new OperationContext().withConfig(new ConfigBuilder().withMasterUrl("https://172.17.0.2:8443").withRequestRetryBackoffLimit(3).build()).withPlural("pods").withName("test-pod").withHttpClient(mockClient));
    baseOp.setType(Pod.class);
    // When
    Pod result = baseOp.get();
    // Then
    assertNotNull(result);
    assertEquals(3, httpExecutionCounter.get(), "Expected 3 calls: 2 failures and 1 success!");
}
Also used : OperationContext(io.fabric8.kubernetes.client.dsl.internal.OperationContext) PodOperationContext(io.fabric8.kubernetes.client.dsl.internal.PodOperationContext) PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpClient(io.fabric8.kubernetes.client.http.HttpClient) Resource(io.fabric8.kubernetes.client.dsl.Resource) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) BaseOperation(io.fabric8.kubernetes.client.dsl.internal.BaseOperation) Test(org.junit.jupiter.api.Test)

Example 3 with BaseOperation

use of io.fabric8.kubernetes.client.dsl.internal.BaseOperation in project kubernetes-client by fabric8io.

the class BaseOperationTest method testChainingGracePeriodAndPropagationPolicy.

@Test
void testChainingGracePeriodAndPropagationPolicy() {
    final BaseOperation operation = new BaseOperation(new OperationContext());
    EditReplacePatchDeletable<?> operationWithPropagationPolicy = operation.withPropagationPolicy(DeletionPropagation.FOREGROUND);
    assertThat(operationWithPropagationPolicy, is(notNullValue()));
    assertNotNull(operationWithPropagationPolicy.withGracePeriod(10));
}
Also used : OperationContext(io.fabric8.kubernetes.client.dsl.internal.OperationContext) PodOperationContext(io.fabric8.kubernetes.client.dsl.internal.PodOperationContext) BaseOperation(io.fabric8.kubernetes.client.dsl.internal.BaseOperation) Test(org.junit.jupiter.api.Test)

Example 4 with BaseOperation

use of io.fabric8.kubernetes.client.dsl.internal.BaseOperation in project kubernetes-client by fabric8io.

the class BaseOperationTest method testNoHttpRetryWithDefaultConfig.

@Test
void testNoHttpRetryWithDefaultConfig() throws MalformedURLException, IOException {
    final AtomicInteger httpExecutionCounter = new AtomicInteger(0);
    HttpClient mockClient = newHttpClientWithSomeFailures(httpExecutionCounter, 1000);
    BaseOperation<Pod, PodList, Resource<Pod>> baseOp = new BaseOperation(new OperationContext().withConfig(new ConfigBuilder().withMasterUrl("https://172.17.0.2:8443").build()).withPlural("pods").withName("test-pod").withHttpClient(mockClient));
    baseOp.setType(Pod.class);
    // When
    Exception exception = assertThrows(KubernetesClientException.class, () -> {
        Pod result = baseOp.get();
    });
    // Then
    assertTrue(exception.getCause().getMessage().contains("For example java.net.ConnectException"), "As the first failure is an IOException the message of the causedBy expected to contain the given text: 'For example java.net.ConnectException'!");
    assertEquals(1, httpExecutionCounter.get());
}
Also used : OperationContext(io.fabric8.kubernetes.client.dsl.internal.OperationContext) PodOperationContext(io.fabric8.kubernetes.client.dsl.internal.PodOperationContext) PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpClient(io.fabric8.kubernetes.client.http.HttpClient) Resource(io.fabric8.kubernetes.client.dsl.Resource) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) BaseOperation(io.fabric8.kubernetes.client.dsl.internal.BaseOperation) KubernetesClientTimeoutException(io.fabric8.kubernetes.client.KubernetesClientTimeoutException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 5 with BaseOperation

use of io.fabric8.kubernetes.client.dsl.internal.BaseOperation in project kubernetes-client by fabric8io.

the class BaseOperationTest method testWaitUntilFailureCompletion.

@Test
void testWaitUntilFailureCompletion() throws MalformedURLException, IOException {
    final AtomicInteger httpExecutionCounter = new AtomicInteger(0);
    HttpClient mockClient = newHttpClientWithSomeFailures(httpExecutionCounter, 2);
    CompletableFuture<List<Pod>> future = new CompletableFuture<>();
    BaseOperation<Pod, PodList, Resource<Pod>> baseOp = new BaseOperation(new OperationContext().withConfig(new ConfigBuilder().withMasterUrl("https://172.17.0.2:8443").build()).withPlural("pods").withName("test-pod").withHttpClient(mockClient)) {

        @Override
        public CompletableFuture<List<Pod>> informOnCondition(Predicate condition) {
            return future;
        }
    };
    baseOp.setType(Pod.class);
    // When
    try {
        baseOp.waitUntilCondition(Objects::isNull, 1, TimeUnit.MILLISECONDS);
        fail("should timeout");
    } catch (KubernetesClientTimeoutException e) {
    }
    // Then
    assertTrue(future.isCancelled());
}
Also used : OperationContext(io.fabric8.kubernetes.client.dsl.internal.OperationContext) PodOperationContext(io.fabric8.kubernetes.client.dsl.internal.PodOperationContext) PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) Resource(io.fabric8.kubernetes.client.dsl.Resource) BaseOperation(io.fabric8.kubernetes.client.dsl.internal.BaseOperation) Predicate(java.util.function.Predicate) KubernetesClientTimeoutException(io.fabric8.kubernetes.client.KubernetesClientTimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpClient(io.fabric8.kubernetes.client.http.HttpClient) Objects(java.util.Objects) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) List(java.util.List) PodList(io.fabric8.kubernetes.api.model.PodList) Test(org.junit.jupiter.api.Test)

Aggregations

BaseOperation (io.fabric8.kubernetes.client.dsl.internal.BaseOperation)9 OperationContext (io.fabric8.kubernetes.client.dsl.internal.OperationContext)9 PodOperationContext (io.fabric8.kubernetes.client.dsl.internal.PodOperationContext)9 Test (org.junit.jupiter.api.Test)9 ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)6 BaseOperation (io.fabric8.kubernetes.client.dsl.base.BaseOperation)6 Pod (io.fabric8.kubernetes.api.model.Pod)5 PodList (io.fabric8.kubernetes.api.model.PodList)5 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)5 Resource (io.fabric8.kubernetes.client.dsl.Resource)5 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)5 HttpClient (io.fabric8.kubernetes.client.http.HttpClient)4 URL (java.net.URL)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 KubernetesClientTimeoutException (io.fabric8.kubernetes.client.KubernetesClientTimeoutException)3 Test (org.junit.Test)3 API (org.wso2.carbon.apimgt.core.models.API)3 Service (io.fabric8.kubernetes.api.model.Service)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 IOException (java.io.IOException)2