private void discoverHostAliases() { List<HostAlias> configuredHostAliases = zaleniumPod.getSpec().getHostAliases(); if (!configuredHostAliases.isEmpty()) { hostAliases = configuredHostAliases; } }
private void discoverNodeSelector() { final Map<String, String> configuredNodeSelector = zaleniumPod.getSpec().getNodeSelector(); if (configuredNodeSelector != null && !configuredNodeSelector.isEmpty()) { nodeSelector = configuredNodeSelector; } }
private void discoverTolerations() { final List<Toleration> configuredTolerations = zaleniumPod.getSpec().getTolerations(); if (configuredTolerations != null && !configuredTolerations.isEmpty()) { tolerations = configuredTolerations; } }
private void discoverFolderMounts() { List<VolumeMount> volumeMounts = zaleniumPod.getSpec().getContainers().get(0).getVolumeMounts(); List<VolumeMount> validMounts = new ArrayList<>(); volumeMounts.stream() .filter(volumeMount -> !Arrays.asList(PROTECTED_NODE_MOUNT_POINTS).contains(volumeMount.getMountPath())) .forEach(validMounts::add); // Look through the volume mounts to see if the shared folder is mounted if (!validMounts.isEmpty()) { List<Volume> volumes = zaleniumPod.getSpec().getVolumes(); for (VolumeMount validMount : validMounts) { volumes.stream() .filter(volume -> validMount.getName().equalsIgnoreCase(volume.getName())) .findFirst() .ifPresent(volume -> mountedSharedFoldersMap.put(validMount, volume)); } } }
@Override public void contribute(Builder builder) { try { Pod current = utils.currentPod().get(); Map<String, Object> details = new HashMap<>(); if (current != null) { details.put("inside", true); details.put("namespace", current.getMetadata().getNamespace()); details.put("podName", current.getMetadata().getName()); details.put("podIp", current.getStatus().getPodIP()); details.put("serviceAccount", current.getSpec().getServiceAccountName()); details.put("nodeName", current.getSpec().getNodeName()); details.put("hostIp", current.getStatus().getHostIP()); } else { details.put("inside", false); } builder.withDetail("kubernetes", details); } catch (Exception e) { LOG.warn("Failed to get pod details", e); } } }
List<EnvVar> podEnvironmentVariables = currentPod.getSpec().getContainers().get(0).getEnv(); Optional<EnvVar> noVncPort = podEnvironmentVariables.stream().filter(env -> "NOVNC_PORT".equals(env.getName())).findFirst();
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { try { Pod current = utils.currentPod().get(); if (current != null) { builder.up().withDetail("inside", true) .withDetail("namespace", current.getMetadata().getNamespace()) .withDetail("podName", current.getMetadata().getName()) .withDetail("podIp", current.getStatus().getPodIP()) .withDetail("serviceAccount", current.getSpec().getServiceAccountName()) .withDetail("nodeName", current.getSpec().getNodeName()) .withDetail("hostIp", current.getStatus().getHostIP()); } else { builder.up().withDetail("inside", false); } } catch (Exception e) { builder.down(e); } } }
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { try { Pod current = utils.currentPod().get(); if (current != null) { builder.up() .withDetail("inside", true) .withDetail("namespace", current.getMetadata().getNamespace()) .withDetail("podName", current.getMetadata().getName()) .withDetail("podIp", current.getStatus().getPodIP()) .withDetail("serviceAccount", current.getSpec().getServiceAccountName()) .withDetail("nodeName", current.getSpec().getNodeName()) .withDetail("hostIp", current.getStatus().getHostIP()); } else { builder.up() .withDetail("inside", false); } } catch (Exception e) { builder.down(e); } } }
public static List<Container> getContainers(Pod pod) { if (pod != null) { PodSpec podSpec = pod.getSpec(); return getContainers(podSpec); } return Collections.EMPTY_LIST; }
public List<String> getPodContainerNames(String podName) { return kubernetesClient .pods() .inNamespace(environment.getKubernetesNamespace()) .withName(podName) .get() .getSpec() .getContainers() .stream() .map(Container::getName) .collect(Collectors.toList()); }
@Override public String call() throws Exception { System.out.println("Updating pod " + pod); PodSpec desiredState = pod.getSpec(); Objects.notNull(desiredState, "desiredState"); PodStatus currentState = NodeHelper.getOrCreatetStatus(pod); List<Container> containers = KubernetesHelper.getContainers(pod); model.updatePod(podId, pod); return NodeHelper.createMissingContainers(processManager, model, pod, currentState, containers); } });
/*** * Returns list of running containers in pod * @param podName name of pod * @return list of containers */ public List<Container> getContainersFromPod(String podName) { return client.pods().inNamespace(globalNamespace).withName(podName).get().getSpec().getContainers(); }
@Test public void testOverridesFromYaml() throws Exception { PodTemplate template = new PodTemplate(); template.setYaml(new String(IOUtils.toByteArray(getClass().getResourceAsStream("pod-overrides.yaml")))); setupStubs(); Pod pod = new PodTemplateBuilder(template).withSlave(slave).build(); Map<String, Container> containers = pod.getSpec().getContainers().stream() .collect(Collectors.toMap(Container::getName, Function.identity())); assertEquals(1, containers.size()); validateJnlpContainer(containers.get("jnlp"), slave); }
public PodFluentImpl(Pod instance){ this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); }
public PodBuilder(Pod instance,Boolean validationEnabled){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); this.validationEnabled = validationEnabled; }
public PodBuilder( Pod instance ){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); }
public PodBuilder( PodFluent<?> fluent , Pod instance ){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); } public PodBuilder( Pod instance ){
public PodBuilder(PodFluent<?> fluent,Pod instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); this.validationEnabled = validationEnabled; } public PodBuilder(Pod instance){
public Pod(io.fabric8.kubernetes.api.model.Pod pod) { this.name = pod.getMetadata().getName(); if (pod.getMetadata().getAnnotations() != null) { this.annotations.putAll(pod.getMetadata().getAnnotations()); } this.kind = pod.getKind(); this.host = pod.getStatus().getPodIP(); this.phase = pod.getStatus().getPhase(); this.ready = getReadyCondition(pod.getStatus().getConditions()); this.portMap = getPortMap(pod.getSpec().getContainers()); }
@Override Pod applyResource(Pod original, Pod current) { return client .pods() .inNamespace(getNamespace()) .withName(current.getMetadata().getName()) .edit() .withMetadata(current.getMetadata()) .withSpec(current.getSpec()) .done(); }