Search in sources :

Example 1 with ContainerizedDeploymentUnit

use of com.liveperson.ephemerals.deploy.unit.ContainerizedDeploymentUnit 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();
}
Also used : Probe(io.fabric8.kubernetes.api.model.Probe) Objects(java.util.Objects) List(java.util.List) com.liveperson.ephemerals.deploy.probe(com.liveperson.ephemerals.deploy.probe) Map(java.util.Map) io.fabric8.kubernetes.api.model(io.fabric8.kubernetes.api.model) DEPLOYMENT_LABEL_KEY(com.liveperson.ephemerals.provider.kubernetes.KubernetesDeploymentHandler.DEPLOYMENT_LABEL_KEY) Deployment(com.liveperson.ephemerals.deploy.Deployment) com.liveperson.ephemerals.deploy.volume(com.liveperson.ephemerals.deploy.volume) Collectors(java.util.stream.Collectors) ContainerizedDeploymentUnit(com.liveperson.ephemerals.deploy.unit.ContainerizedDeploymentUnit) Volume(io.fabric8.kubernetes.api.model.Volume) ContainerizedDeploymentUnit(com.liveperson.ephemerals.deploy.unit.ContainerizedDeploymentUnit) Probe(io.fabric8.kubernetes.api.model.Probe) Volume(io.fabric8.kubernetes.api.model.Volume)

Aggregations

Deployment (com.liveperson.ephemerals.deploy.Deployment)1 com.liveperson.ephemerals.deploy.probe (com.liveperson.ephemerals.deploy.probe)1 ContainerizedDeploymentUnit (com.liveperson.ephemerals.deploy.unit.ContainerizedDeploymentUnit)1 com.liveperson.ephemerals.deploy.volume (com.liveperson.ephemerals.deploy.volume)1 DEPLOYMENT_LABEL_KEY (com.liveperson.ephemerals.provider.kubernetes.KubernetesDeploymentHandler.DEPLOYMENT_LABEL_KEY)1 io.fabric8.kubernetes.api.model (io.fabric8.kubernetes.api.model)1 Probe (io.fabric8.kubernetes.api.model.Probe)1 Volume (io.fabric8.kubernetes.api.model.Volume)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1