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);
}
}
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();
}
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();
}
Aggregations