Search in sources :

Example 56 with V1Pod

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

the class CopyTest method testUrl.

@Test
public void testUrl() throws IOException, ApiException, InterruptedException {
    Copy copy = new Copy(client);
    V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(podName).namespace(namespace));
    wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/exec")).willReturn(aResponse().withStatus(404).withHeader("Content-Type", "application/json").withBody("{}")));
    try {
        InputStream inputStream = copy.copyFileFromPod(pod, "container", "/some/path/to/file");
        // block until the connection is established
        inputStream.read();
        inputStream.close();
    } catch (IOException | ApiException | IllegalStateException e) {
        e.printStackTrace();
    }
    wireMockRule.verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/exec")).withQueryParam("stdin", equalTo("false")).withQueryParam("stdout", equalTo("true")).withQueryParam("stderr", equalTo("true")).withQueryParam("tty", equalTo("false")).withQueryParam("command", new AnythingPattern()));
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) InputStream(java.io.InputStream) AnythingPattern(com.github.tomakehurst.wiremock.matching.AnythingPattern) V1Pod(io.kubernetes.client.openapi.models.V1Pod) IOException(java.io.IOException) ApiException(io.kubernetes.client.openapi.ApiException) Test(org.junit.Test)

Example 57 with V1Pod

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

the class PortForwardTest method testUrl.

@Test
public void testUrl() throws IOException, ApiException, InterruptedException {
    PortForward forward = new PortForward(client);
    V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(podName).namespace(namespace));
    wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/portforward")).willReturn(aResponse().withStatus(404).withHeader("Content-Type", "application/json").withBody("{}")));
    int portNumber = 8080;
    List<Integer> ports = new ArrayList<>();
    ports.add(portNumber);
    assertThrows(ApiException.class, () -> {
        InputStream inputStream = forward.forward(pod, ports).getInputStream(portNumber);
        // block until the connection is established
        inputStream.read();
        inputStream.close();
    });
    wireMockRule.verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/portforward")).withQueryParam("ports", equalTo(Integer.toString(portNumber))));
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) V1Pod(io.kubernetes.client.openapi.models.V1Pod) Test(org.junit.Test)

Example 58 with V1Pod

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

the class CachesTest method testDefaultNamespaceIndex.

@Test
public void testDefaultNamespaceIndex() {
    String testName = "test-name";
    String testNamespace = "test-namespace";
    V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(testName).namespace(testNamespace));
    List<String> indices = Caches.metaNamespaceIndexFunc(pod);
    assertEquals(pod.getMetadata().getNamespace(), indices.get(0));
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) Test(org.junit.Test)

Example 59 with V1Pod

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

the class DeltaFIFOTest method testDeltaFIFOResync.

@Test
public void testDeltaFIFOResync() {
    V1Pod foo1 = new V1Pod().metadata(new V1ObjectMeta().name("foo1").namespace("default"));
    Cache cache = new Cache();
    DeltaFIFO deltaFIFO = new DeltaFIFO(Caches::deletionHandlingMetaNamespaceKeyFunc, cache);
    // sync after add
    cache.add(foo1);
    deltaFIFO.resync();
    Deque<MutablePair<DeltaFIFO.DeltaType, KubernetesObject>> deltas = deltaFIFO.getItems().get(Caches.deletionHandlingMetaNamespaceKeyFunc(foo1));
    assertEquals(1, deltas.size());
    assertEquals(foo1, deltas.peekLast().getRight());
    assertEquals(DeltaFIFO.DeltaType.Sync, deltas.peekLast().getLeft());
}
Also used : MutablePair(org.apache.commons.lang3.tuple.MutablePair) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) Test(org.junit.Test)

Example 60 with V1Pod

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

the class DeltaFIFOTest method testDeltaFIFOReplaceWithDeleteDeltaIn.

@Test
public void testDeltaFIFOReplaceWithDeleteDeltaIn() throws InterruptedException {
    V1Pod oldPod = new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo1"));
    V1Pod newPod = new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo2"));
    Cache mockCache = mock(Cache.class);
    doReturn(oldPod).when(mockCache).getByKey(Caches.deletionHandlingMetaNamespaceKeyFunc(oldPod));
    DeltaFIFO deltaFIFO = new DeltaFIFO(Caches::deletionHandlingMetaNamespaceKeyFunc, mockCache);
    deltaFIFO.delete(oldPod);
    deltaFIFO.replace(Arrays.asList(newPod), "0");
    deltaFIFO.pop((deltas) -> {
        assertEquals(DeltaFIFO.DeltaType.Deleted, deltas.getFirst().getLeft());
        assertEquals(oldPod, deltas.getFirst().getRight());
    });
    deltaFIFO.pop((deltas) -> {
        assertEquals(DeltaFIFO.DeltaType.Sync, deltas.getFirst().getLeft());
        assertEquals(newPod, deltas.getFirst().getRight());
    });
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) Test(org.junit.Test)

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