Search in sources :

Example 16 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta 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 17 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta 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 18 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta 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 19 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta 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 20 with V1ObjectMeta

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

the class DynamicKubernetesApiTest method testListNamespaceShouldWork.

@Test
public void testListNamespaceShouldWork() throws ApiException {
    V1NamespaceList expectedList = new V1NamespaceList().addItemsItem(new V1Namespace().metadata(new V1ObjectMeta().name("foo1"))).addItemsItem(new V1Namespace().metadata(new V1ObjectMeta().name("foo2")));
    wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(apiClient.getJSON().serialize(expectedList))));
    DynamicKubernetesApi api = new DynamicKubernetesApi("", "v1", "namespaces", apiClient);
    DynamicKubernetesListObject listObj = api.list().throwsApiException().getObject();
    assertEquals(expectedList.getItems().size(), listObj.getItems().size());
    wireMockRule.verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces")));
}
Also used : V1NamespaceList(io.kubernetes.client.openapi.models.V1NamespaceList) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Namespace(io.kubernetes.client.openapi.models.V1Namespace) Test(org.junit.Test)

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