Search in sources :

Example 11 with V1ObjectMeta

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

the class KubectlGetTest method testGetAllNodes.

@Test
public void testGetAllNodes() throws KubectlException {
    V1NodeList nodeList = new V1NodeList().items(Arrays.asList(new V1Node().metadata(new V1ObjectMeta().name("foo1")), new V1Node().metadata(new V1ObjectMeta().name("foo2"))));
    wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/nodes")).willReturn(aResponse().withStatus(200).withBody(apiClient.getJSON().serialize(nodeList))));
    List<V1Node> nodes = Kubectl.get(V1Node.class).apiClient(apiClient).skipDiscovery().execute();
    wireMockRule.verify(1, getRequestedFor(urlPathEqualTo("/api/v1/nodes")));
    assertEquals(2, nodes.size());
}
Also used : V1Node(io.kubernetes.client.openapi.models.V1Node) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1NodeList(io.kubernetes.client.openapi.models.V1NodeList) Test(org.junit.Test)

Example 12 with V1ObjectMeta

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

the class KubectlGetTest method testGetOneNode.

@Test
public void testGetOneNode() throws KubectlException {
    V1Node node = new V1Node().metadata(new V1ObjectMeta().name("foo1"));
    wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/nodes/foo1")).willReturn(aResponse().withStatus(200).withBody(apiClient.getJSON().serialize(node))));
    V1Node getNode = Kubectl.get(V1Node.class).apiClient(apiClient).skipDiscovery().name("foo1").execute();
    wireMockRule.verify(1, getRequestedFor(urlPathEqualTo("/api/v1/nodes/foo1")));
    assertEquals(node, getNode);
}
Also used : V1Node(io.kubernetes.client.openapi.models.V1Node) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) Test(org.junit.Test)

Example 13 with V1ObjectMeta

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

the class KubectlGetTest method testGetDefaultNamespaceOnePod.

@Test
public void testGetDefaultNamespaceOnePod() throws KubectlException {
    V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo1"));
    wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/default/pods/foo1")).willReturn(aResponse().withStatus(200).withBody(apiClient.getJSON().serialize(pod))));
    Kubectl.get(V1Pod.class).apiClient(apiClient).skipDiscovery().namespace("default").name("foo1").execute();
    Kubectl.get(V1Pod.class).apiClient(apiClient).skipDiscovery().name("foo1").namespace("default").execute();
    wireMockRule.verify(2, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods/foo1")));
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) Test(org.junit.Test)

Example 14 with V1ObjectMeta

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

the class KubectlGetTest method testGetAllNamespacePods.

@Test
public void testGetAllNamespacePods() throws KubectlException {
    V1PodList podList = new V1PodList().items(Arrays.asList(new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo1")), new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo2"))));
    wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/pods")).willReturn(aResponse().withStatus(200).withBody(apiClient.getJSON().serialize(podList))));
    List<V1Pod> pods = Kubectl.get(V1Pod.class).apiClient(apiClient).skipDiscovery().execute();
    wireMockRule.verify(1, getRequestedFor(urlPathEqualTo("/api/v1/pods")));
    assertEquals(2, pods.size());
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) Test(org.junit.Test)

Example 15 with V1ObjectMeta

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

the class KubernetesInformerCreatorTest method testInformerInjection.

@Test
public void testInformerInjection() throws InterruptedException {
    assertNotNull(podInformer);
    assertNotNull(configMapInformer);
    Semaphore getCount = new Semaphore(2);
    Semaphore watchCount = new Semaphore(2);
    Parameters getParams = new Parameters();
    Parameters watchParams = new Parameters();
    getParams.put("semaphore", getCount);
    watchParams.put("semaphore", watchCount);
    V1Pod foo1 = new V1Pod().kind("Pod").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
    V1ConfigMap bar1 = new V1ConfigMap().kind("ConfigMap").metadata(new V1ObjectMeta().namespace("default").name("bar1"));
    wireMockRule.stubFor(get(urlMatching("^/api/v1/pods.*")).withPostServeAction("semaphore", getParams).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1PodList().metadata(new V1ListMeta().resourceVersion("0")).items(Arrays.asList(foo1))))));
    wireMockRule.stubFor(get(urlMatching("^/api/v1/pods.*")).withPostServeAction("semaphore", watchParams).withQueryParam("watch", equalTo("true")).willReturn(aResponse().withStatus(200).withBody("{}")));
    wireMockRule.stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).withPostServeAction("semaphore", getParams).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList().metadata(new V1ListMeta().resourceVersion("0")).items(Arrays.asList(bar1))))));
    wireMockRule.stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).withPostServeAction("semaphore", watchParams).withQueryParam("watch", equalTo("true")).willReturn(aResponse().withStatus(200).withBody("{}")));
    // These will be released for each web call above.
    getCount.acquire(2);
    watchCount.acquire(2);
    informerFactory.startAllRegisteredInformers();
    // Wait for the GETs to complete and the watches to start.
    getCount.acquire(2);
    watchCount.acquire(2);
    verify(1, getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("false")));
    verify(getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("true")));
    verify(1, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")).withQueryParam("watch", equalTo("false")));
    verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")).withQueryParam("watch", equalTo("true")));
    assertEquals(1, new Lister<>(podInformer.getIndexer()).list().size());
    assertEquals(1, new Lister<>(configMapInformer.getIndexer()).list().size());
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) Parameters(com.github.tomakehurst.wiremock.extension.Parameters) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) JSON(io.kubernetes.client.openapi.JSON) Semaphore(java.util.concurrent.Semaphore) V1ConfigMapList(io.kubernetes.client.openapi.models.V1ConfigMapList) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) V1ListMeta(io.kubernetes.client.openapi.models.V1ListMeta) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)78 Test (org.junit.Test)49 V1Pod (io.kubernetes.client.openapi.models.V1Pod)37 HashMap (java.util.HashMap)14 ApiException (io.kubernetes.client.openapi.ApiException)11 V1PodList (io.kubernetes.client.openapi.models.V1PodList)11 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)10 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)8 V1Container (io.kubernetes.client.openapi.models.V1Container)7 ApiClient (io.kubernetes.client.openapi.ApiClient)6 JSON (io.kubernetes.client.openapi.JSON)6 V1Job (io.kubernetes.client.openapi.models.V1Job)6 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)6 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)6 V1Patch (io.kubernetes.client.custom.V1Patch)5 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)5 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)5 V1Service (io.kubernetes.client.openapi.models.V1Service)5 V1ServiceSpec (io.kubernetes.client.openapi.models.V1ServiceSpec)5 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)5