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