use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class DynamicKubernetesApiTest method testUpdateNamespaceShouldWork.
@Test
public void testUpdateNamespaceShouldWork() throws ApiException {
V1Namespace updating = new V1Namespace().metadata(new V1ObjectMeta().name("foo1"));
wireMockRule.stubFor(put(urlPathEqualTo("/api/v1/namespaces/foo1")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(apiClient.getJSON().serialize(updating))));
DynamicKubernetesApi api = new DynamicKubernetesApi("", "v1", "namespaces", apiClient);
DynamicKubernetesObject updatingObj = Dynamics.newFromJson(apiClient.getJSON().serialize(updating));
DynamicKubernetesObject updatedObj = api.update(updatingObj).throwsApiException().getObject();
assertEquals(updatingObj, updatedObj);
wireMockRule.verify(putRequestedFor(urlPathEqualTo("/api/v1/namespaces/foo1")));
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class GenericKubernetesApiTest method deleteNamespacedJobReturningDeletedObject.
@Test
public void deleteNamespacedJobReturningDeletedObject() {
V1Job foo1 = new V1Job().kind("Job").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
stubFor(delete(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1")).willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
KubernetesApiResponse<V1Job> deleteJobResp = jobClient.delete("default", "foo1");
assertTrue(deleteJobResp.isSuccess());
assertEquals(foo1, deleteJobResp.getObject());
assertNull(deleteJobResp.getStatus());
verify(1, deleteRequestedFor(urlPathEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1")));
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class GenericKubernetesApiTest method updateStatusNamespacedJobReturningObject.
@Test
public void updateStatusNamespacedJobReturningObject() {
V1Job foo1 = new V1Job().kind("Job").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
foo1.setStatus(new V1JobStatus().failed(1));
stubFor(patch(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1/status")).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(foo1))));
KubernetesApiResponse<V1Job> jobListResp = jobClient.updateStatus(foo1, t -> t.getStatus());
assertTrue(jobListResp.isSuccess());
assertEquals(foo1, jobListResp.getObject());
assertNull(jobListResp.getStatus());
verify(1, patchRequestedFor(urlPathEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1/status")));
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta 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");
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class DefaultSharedIndexInformerWireMockTest method testAllNamespacedPodInformerNormalBehavior.
@Test
public void testAllNamespacedPodInformerNormalBehavior() throws InterruptedException {
CoreV1Api coreV1Api = new CoreV1Api(client);
String startRV = "1000";
String endRV = "1001";
V1PodList podList = new V1PodList().metadata(new V1ListMeta().resourceVersion(startRV)).items(Arrays.asList());
stubFor(get(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(new JSON().serialize(podList))));
Watch.Response<V1Pod> watchResponse = new Watch.Response<>(EventType.ADDED.name(), new V1Pod().metadata(new V1ObjectMeta().namespace(namespace).name(podName).resourceVersion(endRV).labels(Collections.singletonMap("foo", "bar")).annotations(Collections.singletonMap("foo", "bar"))));
stubFor(get(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("true")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(new JSON().serialize(watchResponse))));
SharedInformerFactory factory = new SharedInformerFactory();
SharedIndexInformer<V1Pod> podInformer = factory.sharedIndexInformerFor((CallGeneratorParams params) -> {
try {
return coreV1Api.listPodForAllNamespacesCall(null, null, null, null, null, null, params.resourceVersion, null, params.timeoutSeconds, params.watch, null);
} catch (ApiException e) {
throw new RuntimeException(e);
}
}, V1Pod.class, V1PodList.class);
podInformer.setTransform((obj) -> {
// deepcopy
String json = new JSON().serialize(obj);
V1Pod pod = new JSON().deserialize(json, V1Pod.class);
// remove pod annotations
pod.getMetadata().setAnnotations(null);
return pod;
});
AtomicBoolean foundExistingPod = new AtomicBoolean(false);
AtomicBoolean transformed = new AtomicBoolean(false);
AtomicBoolean setTransformAfterStarted = new AtomicBoolean(false);
podInformer.addEventHandler(new ResourceEventHandler<V1Pod>() {
@Override
public void onAdd(V1Pod obj) {
if (podName.equals(obj.getMetadata().getName()) && namespace.equals(obj.getMetadata().getNamespace())) {
foundExistingPod.set(true);
}
V1ObjectMeta metadata = obj.getMetadata();
// check if the object was transformed
if (metadata.getLabels().get("foo").equals("bar") && metadata.getAnnotations() == null) {
transformed.set(true);
}
}
@Override
public void onUpdate(V1Pod oldObj, V1Pod newObj) {
}
@Override
public void onDelete(V1Pod obj, boolean deletedFinalStateUnknown) {
}
});
factory.startAllRegisteredInformers();
Thread.sleep(1000);
// can not set transform func if the informer has started
try {
podInformer.setTransform((obj) -> new V1Pod());
setTransformAfterStarted.set(true);
} catch (IllegalStateException e) {
}
assertTrue(foundExistingPod.get());
assertTrue(transformed.get());
assertFalse(setTransformAfterStarted.get());
assertEquals(endRV, podInformer.lastSyncResourceVersion());
verify(1, getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("false")));
verify(moreThan(1), getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("true")));
factory.stopAllRegisteredInformers();
}
Aggregations