Search in sources :

Example 1 with HPAHandler

use of org.ballerinax.kubernetes.handlers.HPAHandler 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

IOException (java.io.IOException)1 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)1 HPAHandler (org.ballerinax.kubernetes.handlers.HPAHandler)1 PodAutoscalerModel (org.ballerinax.kubernetes.models.PodAutoscalerModel)1