Search in sources :

Example 1 with QuantityBuilder

use of io.fabric8.kubernetes.api.model.QuantityBuilder in project kubernetes by ballerinax.

the class PersistentVolumeClaimHandler method generate.

@Override
public String generate() throws KubernetesPluginException {
    Quantity quantity = new QuantityBuilder().withAmount(volumeClaimModel.getVolumeClaimSize()).build();
    Map<String, Quantity> requests = new HashMap<>();
    requests.put("storage", quantity);
    PersistentVolumeClaim secret = new PersistentVolumeClaimBuilder().withNewMetadata().withName(volumeClaimModel.getName()).endMetadata().withNewSpec().withAccessModes(volumeClaimModel.getAccessMode()).withNewResources().withRequests(requests).endResources().endSpec().build();
    try {
        return SerializationUtils.dumpWithoutRuntimeStateAsYaml(secret);
    } catch (JsonProcessingException e) {
        String errorMessage = "Error while parsing yaml file for volume claim: " + volumeClaimModel.getName();
        throw new KubernetesPluginException(errorMessage, e);
    }
}
Also used : QuantityBuilder(io.fabric8.kubernetes.api.model.QuantityBuilder) HashMap(java.util.HashMap) Quantity(io.fabric8.kubernetes.api.model.Quantity) PersistentVolumeClaimBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with QuantityBuilder

use of io.fabric8.kubernetes.api.model.QuantityBuilder in project halyard by spinnaker.

the class ResourceBuilder method buildResourceRequirements.

static ResourceRequirements buildResourceRequirements(String serviceName, DeploymentEnvironment deploymentEnvironment) {
    Map<String, Map> customSizing = deploymentEnvironment.getCustomSizing().get(serviceName);
    if (customSizing == null) {
        return null;
    }
    ResourceRequirementsBuilder resourceRequirementsBuilder = new ResourceRequirementsBuilder();
    if (customSizing.get("requests") != null) {
        resourceRequirementsBuilder.addToRequests("memory", new QuantityBuilder().withAmount(CustomSizing.stringOrNull(customSizing.get("requests").get("memory"))).build());
        resourceRequirementsBuilder.addToRequests("cpu", new QuantityBuilder().withAmount(CustomSizing.stringOrNull(customSizing.get("requests").get("cpu"))).build());
    }
    if (customSizing.get("limits") != null) {
        resourceRequirementsBuilder.addToLimits("memory", new QuantityBuilder().withAmount(CustomSizing.stringOrNull(customSizing.get("limits").get("memory"))).build());
        resourceRequirementsBuilder.addToLimits("cpu", new QuantityBuilder().withAmount(CustomSizing.stringOrNull(customSizing.get("limits").get("cpu"))).build());
    }
    return resourceRequirementsBuilder.build();
}
Also used : QuantityBuilder(io.fabric8.kubernetes.api.model.QuantityBuilder) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) Map(java.util.Map)

Example 3 with QuantityBuilder

use of io.fabric8.kubernetes.api.model.QuantityBuilder 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

QuantityBuilder (io.fabric8.kubernetes.api.model.QuantityBuilder)2 Map (java.util.Map)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 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 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)1 PersistentVolumeClaimBuilder (io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder)1 Probe (io.fabric8.kubernetes.api.model.Probe)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 ResourceRequirementsBuilder (io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder)1 Volume (io.fabric8.kubernetes.api.model.Volume)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)1