use of org.ballerinax.kubernetes.exceptions.KubernetesPluginException in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method generatePersistentVolumeClaim.
private void generatePersistentVolumeClaim(PersistentVolumeClaimModel volumeClaimModel, String balxFilePath, String outputDir) throws KubernetesPluginException {
String balxFileName = KubernetesUtils.extractBalxName(balxFilePath);
String configMapContent = new PersistentVolumeClaimHandler(volumeClaimModel).generate();
try {
KubernetesUtils.writeToFile(configMapContent, outputDir + File.separator + balxFileName + VOLUME_CLAIM_FILE_POSTFIX + YAML);
} catch (IOException e) {
throw new KubernetesPluginException("Error while writing volume claim content", e);
}
}
use of org.ballerinax.kubernetes.exceptions.KubernetesPluginException in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method generateIngress.
private void generateIngress(IngressModel ingressModel, String balxFilePath, String outputDir) throws KubernetesPluginException {
String balxFileName = KubernetesUtils.extractBalxName(balxFilePath);
ingressModel.addLabel(KubernetesConstants.KUBERNETES_SELECTOR_KEY, balxFileName);
String serviceContent = new IngressHandler(ingressModel).generate();
try {
KubernetesUtils.writeToFile(serviceContent, outputDir + File.separator + balxFileName + INGRESS_FILE_POSTFIX + YAML);
} catch (IOException e) {
throw new KubernetesPluginException("Error while writing ingress content", e);
}
}
use of org.ballerinax.kubernetes.exceptions.KubernetesPluginException in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method generateSecrets.
private void generateSecrets(SecretModel secretModel, String balxFilePath, String outputDir) throws KubernetesPluginException {
String balxFileName = KubernetesUtils.extractBalxName(balxFilePath);
String secretContent = new SecretHandler(secretModel).generate();
try {
KubernetesUtils.writeToFile(secretContent, outputDir + File.separator + balxFileName + SECRET_FILE_POSTFIX + YAML);
} catch (IOException e) {
throw new KubernetesPluginException("Error while writing secret content", e);
}
}
use of org.ballerinax.kubernetes.exceptions.KubernetesPluginException in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method generateDeployment.
private void generateDeployment(DeploymentModel deploymentModel, String balxFilePath, String outputDir) throws KubernetesPluginException {
String balxFileName = KubernetesUtils.extractBalxName(balxFilePath);
if (deploymentModel.getName() == null) {
deploymentModel.setName(getValidName(balxFileName) + DEPLOYMENT_POSTFIX);
}
if (deploymentModel.getImage() == null) {
deploymentModel.setImage(balxFileName + DOCKER_LATEST_TAG);
}
deploymentModel.addLabel(KubernetesConstants.KUBERNETES_SELECTOR_KEY, balxFileName);
if ("enable".equals(deploymentModel.getEnableLiveness()) && deploymentModel.getLivenessPort() == 0) {
// set first port as liveness port
deploymentModel.setLivenessPort(deploymentModel.getPorts().iterator().next());
}
String deploymentContent = new DeploymentHandler(deploymentModel).generate();
try {
KubernetesUtils.writeToFile(deploymentContent, outputDir + File.separator + balxFileName + DEPLOYMENT_FILE_POSTFIX + YAML);
// generate dockerfile and docker image
generateDocker(deploymentModel, balxFilePath, outputDir + File.separator + DOCKER);
// generate HPA
generatePodAutoscaler(deploymentModel, balxFilePath, outputDir);
} catch (IOException e) {
throw new KubernetesPluginException("Error while writing deployment content", e);
}
}
use of org.ballerinax.kubernetes.exceptions.KubernetesPluginException in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method generatePodAutoscaler.
private void generatePodAutoscaler(DeploymentModel deploymentModel, String balxFilePath, String outputDir) throws KubernetesPluginException {
PodAutoscalerModel podAutoscalerModel = deploymentModel.getPodAutoscalerModel();
if (podAutoscalerModel == null) {
return;
}
String balxFileName = KubernetesUtils.extractBalxName(balxFilePath);
podAutoscalerModel.addLabel(KubernetesConstants.KUBERNETES_SELECTOR_KEY, balxFileName);
podAutoscalerModel.setDeployment(deploymentModel.getName());
if (podAutoscalerModel.getMaxReplicas() == 0) {
podAutoscalerModel.setMaxReplicas(deploymentModel.getReplicas() + 1);
}
if (podAutoscalerModel.getMinReplicas() == 0) {
podAutoscalerModel.setMinReplicas(deploymentModel.getReplicas());
}
if (podAutoscalerModel.getName() == null || podAutoscalerModel.getName().length() == 0) {
podAutoscalerModel.setName(getValidName(balxFileName) + HPA_POSTFIX);
}
String serviceContent = new HPAHandler(podAutoscalerModel).generate();
try {
out.println();
KubernetesUtils.writeToFile(serviceContent, outputDir + File.separator + balxFileName + HPA_FILE_POSTFIX + YAML);
out.print("@kubernetes:HPA \t\t\t - complete 1/1");
} catch (IOException e) {
throw new KubernetesPluginException("Error while writing HPA content", e);
}
}
Aggregations