use of io.kubernetes.client.openapi.models.V1Pod in project pravega by pravega.
the class K8SequentialExecutor method getTestPod.
private V1Pod getTestPod(String className, String methodName, String podName) {
log.info("Running test pod with security enabled :{}, transport enabled: {}", Utils.AUTH_ENABLED, Utils.TLS_AND_AUTH_ENABLED);
V1Pod pod = new V1PodBuilder().withNewMetadata().withName(podName).withNamespace(NAMESPACE).withLabels(ImmutableMap.of("POD_NAME", podName, "app", APP)).endMetadata().withNewSpec().withServiceAccountName(SERVICE_ACCOUNT).withAutomountServiceAccountToken(true).withVolumes(new V1VolumeBuilder().withName("task-pv-storage").withPersistentVolumeClaim(new V1PersistentVolumeClaimVolumeSourceBuilder().withClaimName("task-pv-claim").build()).build()).addNewContainer().withName(// container name is same as that of the pod.
podName).withImage(TEST_POD_IMAGE).withImagePullPolicy("IfNotPresent").withCommand("/bin/sh").withArgs("-c", "java" + getArgs() + " -cp /data/test-collection.jar io.pravega.test.system.SingleJUnitTestRunner " + className + "#" + methodName + /*+ " > server.log 2>&1 */
"; exit $?").withVolumeMounts(new V1VolumeMountBuilder().withMountPath("/data").withName("task-pv-storage").build()).endContainer().withRestartPolicy("Never").endSpec().build();
if (Utils.TLS_AND_AUTH_ENABLED) {
pod = new V1PodBuilder(pod).editSpec().withVolumes(new V1VolumeBuilder().withName("tls-certs").withSecret(new V1SecretVolumeSourceBuilder().withSecretName(Utils.TLS_SECRET_NAME).build()).build()).editContainer(0).withVolumeMounts(new V1VolumeMountBuilder().withMountPath(Utils.TLS_MOUNT_PATH).withName("tls-secret").build()).endContainer().endSpec().build();
}
return pod;
}
use of io.kubernetes.client.openapi.models.V1Pod 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.V1Pod in project java by kubernetes-client.
the class KubectlGetTest method testGetDefaultNamespacePods.
@Test
public void testGetDefaultNamespacePods() throws KubectlException {
V1PodList podList = new V1PodList().items(Arrays.asList(new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo1")), new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo2"))));
wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/default/pods")).willReturn(aResponse().withStatus(200).withBody(apiClient.getJSON().serialize(podList))));
List<V1Pod> pods = Kubectl.get(V1Pod.class).apiClient(apiClient).skipDiscovery().namespace("default").execute();
wireMockRule.verify(1, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods")));
assertEquals(2, pods.size());
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class KubectlGetTest method testGetDefaultNamespaceOnePodForbiddenShouldThrowException.
@Test
public void testGetDefaultNamespaceOnePodForbiddenShouldThrowException() {
wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/default/pods/foo1")).willReturn(aResponse().withStatus(403).withBody(apiClient.getJSON().serialize(new V1Status().code(403)))));
try {
V1Pod getPod = Kubectl.get(V1Pod.class).apiClient(apiClient).skipDiscovery().namespace(// no namespace specified
"default").name("foo1").execute();
} catch (KubectlException e) {
assertTrue(e.getCause() instanceof ApiException);
return;
} finally {
wireMockRule.verify(1, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods/foo1")));
}
fail();
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class KubectlDrain method doDrain.
private V1Node doDrain() throws KubectlException, ApiException, IOException {
CoreV1Api api = new CoreV1Api(apiClient);
V1Node node = performCordon();
V1PodList allPods = api.listPodForAllNamespaces(null, null, "spec.nodeName=" + node.getMetadata().getName(), null, null, null, null, null, null, null);
validatePods(allPods.getItems());
for (V1Pod pod : allPods.getItems()) {
deletePod(api, pod.getMetadata().getName(), pod.getMetadata().getNamespace());
}
return node;
}
Aggregations