Search in sources :

Example 11 with KubernetesPluginException

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);
    }
}
Also used : IOException(java.io.IOException) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) PersistentVolumeClaimHandler(org.ballerinax.kubernetes.handlers.PersistentVolumeClaimHandler)

Example 12 with KubernetesPluginException

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);
    }
}
Also used : IngressHandler(org.ballerinax.kubernetes.handlers.IngressHandler) IOException(java.io.IOException) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException)

Example 13 with KubernetesPluginException

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);
    }
}
Also used : SecretHandler(org.ballerinax.kubernetes.handlers.SecretHandler) IOException(java.io.IOException) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException)

Example 14 with KubernetesPluginException

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);
    }
}
Also used : DeploymentHandler(org.ballerinax.kubernetes.handlers.DeploymentHandler) IOException(java.io.IOException) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException)

Example 15 with KubernetesPluginException

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);
    }
}
Also used : HPAHandler(org.ballerinax.kubernetes.handlers.HPAHandler) IOException(java.io.IOException) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) PodAutoscalerModel(org.ballerinax.kubernetes.models.PodAutoscalerModel)

Aggregations

KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)20 IOException (java.io.IOException)13 HashMap (java.util.HashMap)6 File (java.io.File)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ServiceModel (org.ballerinax.kubernetes.models.ServiceModel)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)2 DeploymentHandler (org.ballerinax.kubernetes.handlers.DeploymentHandler)2 IngressHandler (org.ballerinax.kubernetes.handlers.IngressHandler)2 ServiceHandler (org.ballerinax.kubernetes.handlers.ServiceHandler)2 DeploymentModel (org.ballerinax.kubernetes.models.DeploymentModel)2 IngressModel (org.ballerinax.kubernetes.models.IngressModel)2 SecretModel (org.ballerinax.kubernetes.models.SecretModel)2 Container (io.fabric8.kubernetes.api.model.Container)1 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)1 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)1 PersistentVolumeClaimBuilder (io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1