use of io.kubernetes.client.openapi.models.V1ListMeta in project java by kubernetes-client.
the class SharedInformerFactoryTest method testClusterScopedNewInformerUsingGenericApi.
@Test
public void testClusterScopedNewInformerUsingGenericApi() {
SharedInformerFactory factory = new SharedInformerFactory();
SharedInformer<V1Pod> podInformer = factory.sharedIndexInformerFor(genericKubernetesApi, V1Pod.class, 0);
assertThat(podInformer).isNotNull();
when(genericKubernetesApi.list(any(ListOptions.class))).thenReturn(new KubernetesApiResponse<V1PodList>(new V1PodList().metadata(new V1ListMeta().resourceVersion("0"))));
factory.startAllRegisteredInformers();
await().timeout(Duration.ofSeconds(2)).until(podInformer::hasSynced);
verify(genericKubernetesApi, atLeastOnce()).list(any(ListOptions.class));
}
use of io.kubernetes.client.openapi.models.V1ListMeta in project java by kubernetes-client.
the class SharedInformerFactoryTest method testNamespaceScopedNewInformerUsingGenericApi.
@Test
public void testNamespaceScopedNewInformerUsingGenericApi() {
SharedInformerFactory factory = new SharedInformerFactory();
SharedInformer<V1Pod> podInformer = factory.sharedIndexInformerFor(genericKubernetesApi, V1Pod.class, 0, "default");
assertThat(podInformer).isNotNull();
when(genericKubernetesApi.list(eq("default"), any(ListOptions.class))).thenReturn(new KubernetesApiResponse<V1PodList>(new V1PodList().metadata(new V1ListMeta().resourceVersion("0"))));
factory.startAllRegisteredInformers();
await().timeout(Duration.ofSeconds(2)).until(podInformer::hasSynced);
verify(genericKubernetesApi, atLeastOnce()).list(eq("default"), any(ListOptions.class));
}
use of io.kubernetes.client.openapi.models.V1ListMeta in project java by kubernetes-client.
the class DefaultControllerBuilderTest method testBuildWatchEventNotificationShouldWork.
@Test
public void testBuildWatchEventNotificationShouldWork() throws InterruptedException {
V1PodList podList = new V1PodList().metadata(new V1ListMeta().resourceVersion("0")).items(Arrays.asList(new V1Pod().metadata(new V1ObjectMeta().name("test-pod1")).spec(new V1PodSpec().hostname("hostname1"))));
stubFor(get(urlPathEqualTo("/api/v1/pods")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(new JSON().serialize(podList))));
CoreV1Api api = new CoreV1Api(client);
SharedIndexInformer<V1Pod> podInformer = informerFactory.sharedIndexInformerFor((CallGeneratorParams params) -> {
return api.listPodForAllNamespacesCall(null, null, null, null, null, null, params.resourceVersion, null, params.timeoutSeconds, params.watch, null);
}, V1Pod.class, V1PodList.class);
List<Request> keyFuncReceivingRequests = new ArrayList<>();
Function<V1Pod, Request> podKeyFunc = (V1Pod pod) -> {
// twisting pod name key
Request request = new Request(pod.getSpec().getHostname() + "/" + pod.getMetadata().getName());
keyFuncReceivingRequests.add(request);
return request;
};
List<Request> controllerReceivingRequests = new ArrayList<>();
final Semaphore latch = new Semaphore(1);
latch.acquire();
final Controller testController = ControllerBuilder.defaultBuilder(informerFactory).withReconciler(new Reconciler() {
@Override
public Result reconcile(Request request) {
controllerReceivingRequests.add(request);
latch.release();
return new Result(false);
}
}).watch((workQueue) -> ControllerBuilder.controllerWatchBuilder(V1Pod.class, workQueue).withWorkQueueKeyFunc(podKeyFunc).build()).build();
controllerThead.submit(testController::run);
informerFactory.startAllRegisteredInformers();
// Wait for the request to be processed.
latch.acquire(1);
Request expectedRequest = new Request("hostname1/test-pod1");
assertEquals(1, keyFuncReceivingRequests.size());
assertEquals(expectedRequest, keyFuncReceivingRequests.get(0));
assertEquals(1, controllerReceivingRequests.size());
assertEquals(expectedRequest, controllerReceivingRequests.get(0));
}
use of io.kubernetes.client.openapi.models.V1ListMeta in project java by kubernetes-client.
the class GenericKubernetesApiForCoreApiTest method listClusterPodReturningObject.
@Test
public void listClusterPodReturningObject() {
V1PodList podList = new V1PodList().kind("PodList").metadata(new V1ListMeta());
stubFor(get(urlPathEqualTo("/api/v1/pods")).willReturn(aResponse().withStatus(200).withBody(json.serialize(podList))));
KubernetesApiResponse<V1PodList> podListResp = podClient.list();
assertTrue(podListResp.isSuccess());
assertEquals(podList, podListResp.getObject());
assertNull(podListResp.getStatus());
verify(1, getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("false")));
}
use of io.kubernetes.client.openapi.models.V1ListMeta in project java by kubernetes-client.
the class GenericKubernetesApiTest method listClusterJobReturningObject.
@Test
public void listClusterJobReturningObject() {
V1JobList jobList = new V1JobList().kind("JobList").metadata(new V1ListMeta());
stubFor(get(urlPathEqualTo("/apis/batch/v1/jobs")).willReturn(aResponse().withStatus(200).withBody(json.serialize(jobList))));
KubernetesApiResponse<V1JobList> jobListResp = jobClient.list();
assertTrue(jobListResp.isSuccess());
assertEquals(jobList, jobListResp.getObject());
assertNull(jobListResp.getStatus());
verify(1, getRequestedFor(urlPathEqualTo("/apis/batch/v1/jobs")));
}
Aggregations