use of io.kubernetes.client.openapi.models.V1Pod 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.V1Pod 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.V1Pod in project java by kubernetes-client.
the class CachesTest method testDefaultNamespaceNameKey.
@Test
public void testDefaultNamespaceNameKey() {
String testName = "test-name";
String testNamespace = "test-namespace";
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(testName).namespace(testNamespace));
assertEquals(testNamespace + "/" + testName, Caches.metaNamespaceKeyFunc(pod));
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class DeltaFIFOTest method testDeltaFIFOBasic.
@Test
public void testDeltaFIFOBasic() throws InterruptedException {
Deque<MutablePair<DeltaFIFO.DeltaType, KubernetesObject>> receivingDeltas = new LinkedList<>();
V1Pod foo1 = new V1Pod().metadata(new V1ObjectMeta().name("foo1").namespace("default"));
Cache cache = new Cache();
DeltaFIFO deltaFIFO = new DeltaFIFO(Caches::deletionHandlingMetaNamespaceKeyFunc, cache);
MutablePair<DeltaFIFO.DeltaType, KubernetesObject> receivingDelta;
// basic add operation
deltaFIFO.add(foo1);
cache.add(foo1);
deltaFIFO.pop((deltas) -> {
MutablePair<DeltaFIFO.DeltaType, KubernetesObject> delta = deltas.peekFirst();
receivingDeltas.add(delta);
});
receivingDelta = receivingDeltas.peekFirst();
receivingDeltas.removeFirst();
assertEquals(foo1, receivingDelta.getRight());
assertEquals(DeltaFIFO.DeltaType.Added, receivingDelta.getLeft());
// basic update operation
deltaFIFO.update(foo1);
cache.update(foo1);
deltaFIFO.pop((deltas) -> {
MutablePair<DeltaFIFO.DeltaType, KubernetesObject> delta = deltas.peekFirst();
receivingDeltas.add(delta);
});
receivingDelta = receivingDeltas.peekFirst();
receivingDeltas.removeFirst();
assertEquals(foo1, receivingDelta.getRight());
assertEquals(DeltaFIFO.DeltaType.Updated, receivingDelta.getLeft());
// basic delete operation
deltaFIFO.delete(foo1);
cache.delete(foo1);
deltaFIFO.pop((deltas) -> {
MutablePair<DeltaFIFO.DeltaType, KubernetesObject> delta = deltas.peekFirst();
receivingDeltas.add(delta);
});
receivingDelta = receivingDeltas.peekFirst();
receivingDeltas.removeFirst();
assertEquals(foo1, receivingDelta.getRight());
assertEquals(DeltaFIFO.DeltaType.Deleted, receivingDelta.getLeft());
// basic sync operation
deltaFIFO.replace(Arrays.asList(foo1), "0");
cache.replace(Arrays.asList(foo1), "0");
deltaFIFO.pop((deltas) -> {
MutablePair<DeltaFIFO.DeltaType, KubernetesObject> delta = deltas.peekFirst();
receivingDeltas.add(delta);
});
receivingDelta = receivingDeltas.peekFirst();
receivingDeltas.removeFirst();
assertEquals(foo1, receivingDelta.getRight());
assertEquals(DeltaFIFO.DeltaType.Sync, receivingDelta.getLeft());
}
use of io.kubernetes.client.openapi.models.V1Pod in project pravega by pravega.
the class K8sClient method createAWatchAndReturnOnTermination.
/**
* Create a Watch for a pod and return once the pod has terminated.
* @param namespace Namespace.
* @param podName Name of the pod.
* @return V1ContainerStateTerminated.
*/
@SneakyThrows({ ApiException.class, IOException.class })
private Optional<V1ContainerStateTerminated> createAWatchAndReturnOnTermination(String namespace, String podName) {
log.debug("Creating a watch for pod {}/{}", namespace, podName);
CoreV1Api api = new CoreV1Api();
K8AsyncCallback<V1ServiceAccount> callback = new K8AsyncCallback<>("createAWatchAndReturnOnTermination-" + podName);
@Cleanup Watch<V1Pod> watch = Watch.createWatch(client, api.listNamespacedPodCall(namespace, PRETTY_PRINT, ALLOW_WATCH_BOOKMARKS, null, null, "POD_NAME=" + podName, null, null, null, Boolean.TRUE, callback), new TypeToken<Watch.Response<V1Pod>>() {
}.getType());
for (Watch.Response<V1Pod> v1PodResponse : watch) {
List<V1ContainerStatus> containerStatuses = v1PodResponse.object.getStatus().getContainerStatuses();
log.debug("Container status for the pod {} is {}", podName, containerStatuses);
if (containerStatuses == null || containerStatuses.size() == 0) {
log.debug("Container status is not part of the pod {}/{}, wait for the next update from KUBERNETES Cluster", namespace, podName);
continue;
}
// We check only the first container as there is only one container in the pod.
V1ContainerState containerStatus = containerStatuses.get(0).getState();
log.debug("Current container status is {}", containerStatus);
if (containerStatus.getTerminated() != null) {
log.info("Pod {}/{} has terminated", namespace, podName);
return Optional.of(containerStatus.getTerminated());
}
}
return Optional.empty();
}
Aggregations