use of com.liveperson.ephemerals.deploy.Deployment in project ephemerals by LivePersonInc.
the class DefaultKubernetesDeploymentStrategy method pod.
@Override
public PodSpec pod(Deployment deployment) {
PodSpecBuilder podSpec = new PodSpecBuilder();
ContainerizedDeploymentUnit deploymentUnit = (ContainerizedDeploymentUnit) deployment.getDeploymentUnit();
List<ContainerPort> containerPortList = deployment.getDeploymentUnit().getPorts().stream().map(port -> new ContainerPortBuilder().withContainerPort(port.getPort()).withName(port.getName()).build()).collect(Collectors.toList());
Probe healthProbe = null;
Probe readinessProbe = null;
if (deploymentUnit.getHealthProbe() != null) {
healthProbe = DefaultKubernetesDeploymentStrategy.probe(deploymentUnit.getHealthProbe());
}
if (deploymentUnit.getReadinessProbe() != null) {
readinessProbe = DefaultKubernetesDeploymentStrategy.probe(deploymentUnit.getReadinessProbe());
}
ContainerBuilder containerBuilder = new ContainerBuilder();
if (healthProbe != null) {
containerBuilder.withLivenessProbe(healthProbe);
}
if (readinessProbe != null) {
containerBuilder.withReadinessProbe(readinessProbe);
}
Container container = containerBuilder.withName(deployment.getId()).withPorts(containerPortList).withImage(deploymentUnit.getImage()).withEnv(envVars(deploymentUnit.getEnvVars())).withResources(new ResourceRequirementsBuilder().addToLimits("cpu", new QuantityBuilder().withAmount(String.valueOf(deploymentUnit.getCpu() * 1000) + "m").build()).addToLimits("memory", new QuantityBuilder().withAmount(String.valueOf(deploymentUnit.getMem()) + "Mi").build()).build()).build();
container.setVolumeMounts(deploymentUnit.getVolumes().entrySet().stream().map(pair -> new VolumeMountBuilder().withName(pair.getKey().getName()).withMountPath(pair.getKey().getMountPath()).build()).collect(Collectors.toList()));
podSpec.addToContainers(container);
podSpec.withVolumes(deploymentUnit.getVolumes().entrySet().stream().filter(pair -> pair != null).map(pair -> {
Volume volume = volume(pair.getValue());
volume.setName(pair.getKey().getName());
return volume;
}).collect(Collectors.toList()));
return podSpec.build();
}
Aggregations