public String deployPod(String name, String env, RCContext context) throws Exception { List<Container> containers = getContainers(name, context); PodSpec podSpec = new PodSpec(); podSpec.setContainers(containers); Map<String, String> podLabels = new HashMap<>(); podLabels.put("name", name + "-pod"); podLabels.putAll(context.getLabels()); ObjectMeta metadata = new ObjectMeta(); metadata.setName(name + "-pod"); metadata.setLabels(podLabels); mountSecret(podSpec, context.getMountSecret()); Pod pod = new Pod(); pod.setApiVersion(configuration.getApiVersion()); pod.setMetadata(metadata); pod.setSpec(podSpec); return client.pods().inNamespace(configuration.getNamespace()).create(pod).getMetadata().getName(); }
public static Binding toBinding(Pod pod) { Binding binding = null; if (pod.getStatus() != null && pod.getStatus().getHostIP() != null) { // Running // pod binding = new Binding(pod.getStatus().getHostIP()); } else { // Configured pod binding = new Binding(null); } for (Container container : pod.getSpec().getContainers()) { for (ContainerPort port : container.getPorts()) { binding.addPortBinding(port.getContainerPort(), port.getHostPort()); } } return binding; }
@Override public void eventReceived(Action action, Pod pod) { switch (action) { case ADDED: case MODIFIED: if (pod.getStatus().getPhase().equalsIgnoreCase("Running")) { addConsole(pod.getMetadata().getName()); } break; case DELETED: case ERROR: delConsole(pod.getMetadata().getName()); break; } }
protected String getName(Pod pod) { return pod.getMetadata().getName(); }
private Pod createStartablePod(Template<Pod> template, Map<String, String> defaultLabels) { Map<String, String> allLabels = new HashMap<String, String>(); allLabels.putAll(defaultLabels); allLabels.putAll(template.getTarget().getMetadata().getLabels()); Pod service = new PodBuilder() .withNewMetadataLike(template.getTarget().getMetadata()) .withLabels(allLabels) .endMetadata() .withNewSpecLike(template.getTarget().getSpec()) .endSpec() .build(); return service; }
@Override protected List<Container> getContainers() { return pod.getSpec().getContainers(); } }
@Override public void eventReceived(Action action, Pod pod) { switch (action) { case ADDED: case MODIFIED: if (pod.getStatus() != null && isRunning(pod.getStatus().getPhase()) && isReady( pod.getStatus())) { holder.compareAndSet(null, pod); latch.countDown(); } break; case DELETED: case ERROR: System.err.println("Unexpected action waiting for pod to start: " + action); holder.compareAndSet(null, pod); latch.countDown(); } }
@Before public void setup() throws Exception { final Pod pod = new Pod("v1", "Pod", new ObjectMeta(), new PodSpec(), null); final ResourceHolder resourceHolder = new ResourceHolder(pod); when(openShiftClient.build(anyObject())).thenReturn(resourceHolder); when(openShiftClient.getClientExt()).thenReturn(openShiftClientExt); when(openShiftClientExt.routes()).thenReturn(routeOperations); when(routeOperations.list()).thenReturn(new RouteList()); when(cubeOpenShiftConfiguration.isNamespaceCleanupEnabled()).thenReturn(true); buildablePodCube = injectorInst.get().inject(new BuildablePodCube(pod, openShiftClient, cubeOpenShiftConfiguration)); buildablePodCube.holder = resourceHolder; }
@Override public void eventReceived(Action action, Pod pod) { switch (action) { case ADDED: case MODIFIED: if (pod.getStatus().getPhase().equalsIgnoreCase("Running")) { addConsole(pod.getMetadata().getName()); } break; case DELETED: case ERROR: delConsole(pod.getMetadata().getName()); break; } }
private void destroyPod(Pod pod) throws Exception { if (configuration.isNamespaceCleanupEnabled()) { client.destroy(pod); } else { logger.info("Ignoring cleanup for pod " + pod.getMetadata().getName()); } }
@Override public <T extends HasMetadata> void onResourceNotReady(T resource) { try { PodList podList = podsOf(resource); if (podList == null) { return; } for (Pod pod : podList.getItems()) { //That should only happen in tests. if (pod.getSpec() == null || pod.getSpec().getContainers() == null) { continue; } displayPodEvents(pod); for (Container container : pod.getSpec().getContainers()) { displayContainerLogs(pod, container); } } } catch (Throwable t) { //ignore } }
protected boolean isReady(Pod pod) { PodStatus status = pod.getStatus(); if (pod.getMetadata().getDeletionTimestamp() == null) { if ("Running".equalsIgnoreCase(status.getPhase())) { List<PodCondition> conditions = status.getConditions(); if (conditions != null) { for (PodCondition condition : conditions) { if ("Ready".equalsIgnoreCase(condition.getType())) { return "True".equalsIgnoreCase(condition.getStatus()); } } } } } return false; } }
protected void displayPodEvents(Pod pod) { try { Map<String, String> fields = new HashMap<>(); fields.put("involvedObject.uid", pod.getMetadata().getUid()); fields.put("involvedObject.name", pod.getMetadata().getName()); fields.put("involvedObject.namespace", pod.getMetadata().getNamespace()); EventList eventList = client.events().inNamespace(pod.getMetadata().getNamespace()).withFields(fields).list(); if (eventList == null) { return; } logger.warn("Events of matching pod: [" + pod.getMetadata().getName() + "]"); for (Event event : eventList.getItems()) { logger.info(String.format("%s\t\t%s", event.getReason(), event.getMessage())); } } catch (Throwable t) { logger.error("Failed to read events, due to:" + t.getMessage()); } finally { logger.warn("---"); } }
@Override public <T extends HasMetadata> void onResourceNotReady(T resource) { try { PodList podList = podsOf(resource); if (podList == null) { return; } for (Pod pod : podList.getItems()) { //That should only happen in tests. if (pod.getSpec() == null || pod.getSpec().getContainers() == null) { continue; } displayPodEvents(pod); for (Container container : pod.getSpec().getContainers()) { displayContainerLogs(pod, container); } } } catch (Throwable t) { //ignore } }
public static boolean isRunning(Pod resource) throws Exception { return isRunning(resource.getStatus().getPhase()); }
for (Pod pod : podList.getItems()) { session.getLogger() .info("Pod: [" + pod.getMetadata().getName() + "] Status: [" + pod.getStatus().getPhase() + "]");
protected void displayPodEvents(Pod pod) { try { Map<String, String> fields = new HashMap<>(); fields.put("involvedObject.uid", pod.getMetadata().getUid()); fields.put("involvedObject.name", pod.getMetadata().getName()); fields.put("involvedObject.namespace", pod.getMetadata().getNamespace()); EventList eventList = client.events().inNamespace(pod.getMetadata().getNamespace()).withFields(fields).list(); if (eventList == null) { return; } logger.warn("Events of matching pod: [" + pod.getMetadata().getName() + "]"); for (Event event : eventList.getItems()) { logger.info(String.format("%s\t\t%s", event.getReason(), event.getMessage())); } } catch (Throwable t) { logger.error("Failed to read events, due to:" + t.getMessage()); } finally { logger.warn("---"); } }
for (Container container : resource.getSpec().getContainers()) { for (ContainerPort containerPort : container.getPorts()) { if (containerPort.getContainerPort() == null) {
for (Pod pod : podList.getItems()) { session.getLogger() .info("Pod: [" + pod.getMetadata().getName() + "] Status: [" + pod.getStatus().getPhase() + "]");