Search in sources :

Example 26 with V1Pod

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

the class GenericKubernetesApiForCoreApiTest method patchNamespacedPodReturningObject.

@Test
public void patchNamespacedPodReturningObject() {
    V1Patch v1Patch = new V1Patch("{}");
    V1Pod foo1 = new V1Pod().kind("Pod").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
    stubFor(patch(urlEqualTo("/api/v1/namespaces/default/pods/foo1")).withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH)).willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
    KubernetesApiResponse<V1Pod> podPatchResp = podClient.patch("default", "foo1", V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, v1Patch);
    assertTrue(podPatchResp.isSuccess());
    assertEquals(foo1, podPatchResp.getObject());
    assertNull(podPatchResp.getStatus());
    verify(1, patchRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods/foo1")));
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Patch(io.kubernetes.client.custom.V1Patch) V1Pod(io.kubernetes.client.openapi.models.V1Pod) Test(org.junit.Test)

Example 27 with V1Pod

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

the class GenericKubernetesApiForCoreApiTest method deleteNamespacedPodReturningDeletedObject.

@Test
public void deleteNamespacedPodReturningDeletedObject() {
    V1Pod foo1 = new V1Pod().kind("Pod").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
    stubFor(delete(urlEqualTo("/api/v1/namespaces/default/pods/foo1")).willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
    KubernetesApiResponse<V1Pod> deletePodResp = podClient.delete("default", "foo1");
    assertTrue(deletePodResp.isSuccess());
    assertEquals(foo1, deletePodResp.getObject());
    assertNull(deletePodResp.getStatus());
    verify(1, deleteRequestedFor(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 28 with V1Pod

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

the class GenericKubernetesApiForCoreApiTest method patchNamespacedPodWithApiPrefix.

@Test
public void patchNamespacedPodWithApiPrefix() {
    V1Patch v1Patch = new V1Patch("{}");
    V1Pod foo1 = new V1Pod().kind("Pod").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
    // add api prefix
    String prefix = "/k8s/clusters/c-7q988";
    stubFor(patch(urlEqualTo(prefix + "/api/v1/namespaces/default/pods/foo1")).withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH)).willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
    GenericKubernetesApi<V1Pod, V1PodList> rancherPodClient = new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", new ClientBuilder().setBasePath("http://localhost:" + 8181 + prefix).build());
    KubernetesApiResponse<V1Pod> podPatchResp = rancherPodClient.patch("default", "foo1", V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, v1Patch);
    assertTrue(podPatchResp.isSuccess());
    assertEquals(foo1, podPatchResp.getObject());
    assertNull(podPatchResp.getStatus());
    verify(1, patchRequestedFor(urlPathEqualTo(prefix + "/api/v1/namespaces/default/pods/foo1")));
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Patch(io.kubernetes.client.custom.V1Patch) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ClientBuilder(io.kubernetes.client.util.ClientBuilder) Test(org.junit.Test)

Example 29 with V1Pod

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

the class GenericKubernetesApiForCoreApiTest method updateNamespacedPodReturningObject.

@Test
public void updateNamespacedPodReturningObject() {
    V1Pod foo1 = new V1Pod().kind("Pod").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
    stubFor(put(urlEqualTo("/api/v1/namespaces/default/pods/foo1")).willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
    KubernetesApiResponse<V1Pod> podListResp = podClient.update(foo1);
    assertTrue(podListResp.isSuccess());
    assertEquals(foo1, podListResp.getObject());
    assertNull(podListResp.getStatus());
    verify(1, putRequestedFor(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 30 with V1Pod

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

the class LabelsTest method testAddMultipleLabels.

@Test
public void testAddMultipleLabels() {
    V1Pod pod = new V1Pod().metadata(new V1ObjectMeta());
    Map<String, String> newLabels = new HashMap<>();
    newLabels.put("foo1", "bar1");
    newLabels.put("foo2", "bar2");
    Labels.addLabels(pod, newLabels);
    assertEquals(pod.getMetadata().getLabels().get("foo1"), "bar1");
    assertEquals(pod.getMetadata().getLabels().get("foo2"), "bar2");
}
Also used : HashMap(java.util.HashMap) 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)99 Test (org.junit.Test)55 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)38 V1PodList (io.kubernetes.client.openapi.models.V1PodList)33 Type (java.lang.reflect.Type)22 ApiException (io.kubernetes.client.openapi.ApiException)20 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)17 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)15 ApiClient (io.kubernetes.client.openapi.ApiClient)12 Watch (io.kubernetes.client.util.Watch)10 V1Status (io.kubernetes.client.openapi.models.V1Status)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 V1Container (io.kubernetes.client.openapi.models.V1Container)4