use of io.fabric8.kubernetes.api.model.apps.DeploymentBuilder in project kubernetes by ballerinax.
the class DeploymentHandler method generate.
/**
* Generate kubernetes deployment definition from annotation.
*
* @param deploymentModel @{@link DeploymentModel} definition
* @throws KubernetesPluginException If an error occurs while generating artifact.
*/
private void generate(DeploymentModel deploymentModel) throws KubernetesPluginException {
List<ContainerPort> containerPorts = null;
if (deploymentModel.getPorts() != null) {
containerPorts = populatePorts(deploymentModel.getPorts());
}
Container container = generateContainer(deploymentModel, containerPorts);
Deployment deployment = new DeploymentBuilder().withNewMetadata().withName(deploymentModel.getName()).withLabels(deploymentModel.getLabels()).withAnnotations(deploymentModel.getAnnotations()).withNamespace(dataHolder.getNamespace()).endMetadata().withNewSpec().withNewSelector().withMatchLabels(deploymentModel.getLabels()).endSelector().withStrategy(deploymentModel.getStrategy()).withReplicas(deploymentModel.getReplicas()).withNewTemplate().withNewMetadata().addToLabels(deploymentModel.getLabels()).addToAnnotations(deploymentModel.getPodAnnotations()).endMetadata().withNewSpec().withServiceAccountName(deploymentModel.getServiceAccountName()).withContainers(container).withImagePullSecrets(getImagePullSecrets(deploymentModel)).withInitContainers(generateInitContainer(deploymentModel)).withVolumes(populateVolume(deploymentModel)).withTolerations(populatePodTolerations(deploymentModel.getPodTolerations())).withNodeSelector(deploymentModel.getNodeSelector()).endSpec().endTemplate().endSpec().build();
try {
String deploymentContent = SerializationUtils.dumpWithoutRuntimeStateAsYaml(deployment);
KubernetesUtils.writeToFile(deploymentContent, DEPLOYMENT_FILE_POSTFIX + YAML);
} catch (IOException e) {
String errorMessage = "error while generating yaml file for deployment: " + deploymentModel.getName();
throw new KubernetesPluginException(errorMessage, e);
}
}
Aggregations