Search in sources :

Example 1 with OperationContext

use of io.fabric8.kubernetes.client.dsl.internal.OperationContext 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 OperationContext

use of io.fabric8.kubernetes.client.dsl.internal.OperationContext 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 OperationContext

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

the class BaseOperationTest method testSimpleFieldQueryParamConcatenation.

@Test
void testSimpleFieldQueryParamConcatenation() {
    Map<String, String> fieldsMap = new HashMap<>();
    fieldsMap.put("yesKey1", "yesValue1");
    fieldsMap.put("yesKey2", "yesValue2");
    PodOperationsImpl operation = new PodOperationsImpl(new PodOperationContext(), new OperationContext());
    operation = (PodOperationsImpl) operation.withFields(fieldsMap).withField("yesKey2", "overrideValue2").withoutField("noKey1", "noValue1").withoutField("noKey2", "noValue2");
    final String fieldQueryParam = operation.getFieldQueryParam();
    // Use contains to not be depending on map key/value pair ordering
    assertThat(fieldQueryParam, containsString("yesKey1=yesValue1"));
    assertThat(fieldQueryParam, containsString("yesKey2=overrideValue2"));
    assertThat(fieldQueryParam, containsString("noKey1!=noValue1"));
    assertThat(fieldQueryParam, containsString("noKey2!=noValue2"));
}
Also used : OperationContext(io.fabric8.kubernetes.client.dsl.internal.OperationContext) PodOperationContext(io.fabric8.kubernetes.client.dsl.internal.PodOperationContext) HashMap(java.util.HashMap) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PodOperationsImpl(io.fabric8.kubernetes.client.dsl.internal.core.v1.PodOperationsImpl) PodOperationContext(io.fabric8.kubernetes.client.dsl.internal.PodOperationContext) Test(org.junit.jupiter.api.Test)

Example 4 with OperationContext

use of io.fabric8.kubernetes.client.dsl.internal.OperationContext 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 5 with OperationContext

use of io.fabric8.kubernetes.client.dsl.internal.OperationContext 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)

Aggregations

Test (org.junit.jupiter.api.Test)28 OperationContext (io.fabric8.kubernetes.client.dsl.internal.OperationContext)20 PodOperationContext (io.fabric8.kubernetes.client.dsl.internal.PodOperationContext)14 BaseOperation (io.fabric8.kubernetes.client.dsl.internal.BaseOperation)9 Pod (io.fabric8.kubernetes.api.model.Pod)8 DisplayName (org.junit.jupiter.api.DisplayName)8 WatchEvent (io.fabric8.kubernetes.api.model.WatchEvent)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)6 Resource (io.fabric8.kubernetes.client.dsl.Resource)6 OpenShiftConfigBuilder (io.fabric8.openshift.client.OpenShiftConfigBuilder)6 PodList (io.fabric8.kubernetes.api.model.PodList)5 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 PodOperationsImpl (io.fabric8.kubernetes.client.dsl.internal.core.v1.PodOperationsImpl)4 HttpClient (io.fabric8.kubernetes.client.http.HttpClient)4 CronTab (io.fabric8.kubernetes.client.mock.crd.CronTab)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 KubernetesClientTimeoutException (io.fabric8.kubernetes.client.KubernetesClientTimeoutException)3 URL (java.net.URL)3 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)2