use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class DynamicKubernetesTypeAdaptorFactoryTest method testSingleDynamicObjectRoundTrip.
@Test
public void testSingleDynamicObjectRoundTrip() {
KubernetesObject dynamicObj = gson.fromJson(jsonContent, KubernetesObject.class);
assertTrue(dynamicObj instanceof DynamicKubernetesObject);
assertEquals("v1", dynamicObj.getApiVersion());
assertEquals("Namespace", dynamicObj.getKind());
assertEquals(new V1ObjectMeta().name("foo"), dynamicObj.getMetadata());
String dumped = gson.toJson(dynamicObj);
assertEquals(jsonContent, dumped);
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class LabelsTest method testAddLabels.
@Test
public void testAddLabels() {
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta());
Labels.addLabels(pod, "foo", "bar");
assertEquals(pod.getMetadata().getLabels().get("foo"), "bar");
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class DefaultSharedIndexInformerWireMockTest method testAllNamespacedPodInformerTransformFailure.
@Test
public void testAllNamespacedPodInformerTransformFailure() 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)));
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) -> {
throw new ObjectTransformException("test transform failure");
});
AtomicBoolean foundExistingPod = 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);
}
}
@Override
public void onUpdate(V1Pod oldObj, V1Pod newObj) {
}
@Override
public void onDelete(V1Pod obj, boolean deletedFinalStateUnknown) {
}
});
factory.startAllRegisteredInformers();
Thread.sleep(1000);
// cannot find the pod due to transform failure
assertFalse(foundExistingPod.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();
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class DefaultSharedIndexInformerWireMockTest method testNamespacedPodInformerNormalBehavior.
@Test
public void testNamespacedPodInformerNormalBehavior() 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/namespaces/" + namespace + "/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)));
stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/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.listNamespacedPodCall(namespace, 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);
AtomicBoolean foundExistingPod = 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);
}
}
@Override
public void onUpdate(V1Pod oldObj, V1Pod newObj) {
}
@Override
public void onDelete(V1Pod obj, boolean deletedFinalStateUnknown) {
}
});
factory.startAllRegisteredInformers();
Thread.sleep(1000);
assertEquals(true, foundExistingPod.get());
assertEquals(endRV, podInformer.lastSyncResourceVersion());
verify(1, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods")).withQueryParam("watch", equalTo("false")));
verify(moreThan(1), getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods")).withQueryParam("watch", equalTo("true")));
factory.stopAllRegisteredInformers();
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class CacheTest method data.
@Parameterized.Parameters
public static Collection data() {
V1Pod normalPod = new V1Pod();
V1ObjectMeta normalPodMeta = new V1ObjectMeta();
normalPodMeta.setName("foo");
normalPodMeta.setNamespace("default");
normalPod.setMetadata(normalPodMeta);
V1Pod missingNamespacePod = new V1Pod();
V1ObjectMeta missingNamespacePodMeta = new V1ObjectMeta();
missingNamespacePodMeta.setName("foo");
missingNamespacePodMeta.setNamespace(null);
missingNamespacePod.setMetadata(missingNamespacePodMeta);
V1Pod missingNamePod = new V1Pod();
V1ObjectMeta missingNamePodMeta = new V1ObjectMeta();
missingNamePodMeta.setName(null);
missingNamePodMeta.setNamespace("default");
missingNamePod.setMetadata(missingNamePodMeta);
return Arrays.asList(new Object[][] { { normalPod, "io.kubernetes.client.openapi.models.V1Pod" }, { missingNamespacePod, "io.kubernetes.client.openapi.models.V1Pod" }, { missingNamePod, "io.kubernetes.client.openapi.models.V1Pod" }, { null, "null" } });
}
Aggregations