use of org.ballerinax.kubernetes.models.ProbeModel in project kubernetes by ballerinax.
the class KubernetesHPAGeneratorTests method testHPAGenerate.
@Test
public void testHPAGenerate() {
DeploymentModel deploymentModel = new DeploymentModel();
deploymentModel.setName(deploymentName);
Map<String, String> labels = new HashMap<>();
labels.put(KubernetesConstants.KUBERNETES_SELECTOR_KEY, selector);
deploymentModel.addPort(9090);
deploymentModel.addPort(9091);
deploymentModel.addPort(9092);
deploymentModel.setLabels(labels);
ProbeModel probeModel = new ProbeModel();
probeModel.setPort(9090);
deploymentModel.setLivenessProbe(probeModel);
deploymentModel.setSingleYAML(false);
Map<String, EnvVarValueModel> env = new HashMap<>();
EnvVarValueModel testEnvVar = new EnvVarValueModel("ENV");
env.put("ENV_VAR", testEnvVar);
deploymentModel.setEnv(env);
PodAutoscalerModel podAutoscalerModel = new PodAutoscalerModel();
podAutoscalerModel.setName(hpaName);
podAutoscalerModel.setCpuPercentage(cpuPercentage);
podAutoscalerModel.setMaxReplicas(maxReplicas);
podAutoscalerModel.setMinReplicas(minReplicas);
podAutoscalerModel.setDeployment(deploymentName);
podAutoscalerModel.setLabels(labels);
deploymentModel.setPodAutoscalerModel(podAutoscalerModel);
dataHolder.setPodAutoscalerModel(podAutoscalerModel);
dataHolder.setDeploymentModel(deploymentModel);
try {
new HPAHandler().createArtifacts();
File tempFile = dataHolder.getK8sArtifactOutputPath().resolve("hello_hpa.yaml").toFile();
Assert.assertTrue(tempFile.exists());
assertGeneratedYAML(tempFile);
tempFile.deleteOnExit();
} catch (IOException e) {
Assert.fail("Unable to write to file");
} catch (KubernetesPluginException e) {
Assert.fail("Unable to generate yaml from service");
}
}
use of org.ballerinax.kubernetes.models.ProbeModel in project kubernetes by ballerinax.
the class DeploymentAnnotationProcessor method parseProbeConfiguration.
/**
* Parse probe configuration from a record.
*
* @param probeValue Probe configuration record.
* @return Parse probe model.
* @throws KubernetesPluginException When an unknown field is found.
*/
private ProbeModel parseProbeConfiguration(BLangExpression probeValue) throws KubernetesPluginException {
if ((probeValue instanceof BLangSimpleVarRef || probeValue instanceof BLangLiteral) && getBooleanValue(probeValue)) {
return new ProbeModel();
} else {
if (probeValue instanceof BLangRecordLiteral) {
List<BLangRecordLiteral.BLangRecordKeyValueField> buildExtensionRecord = convertRecordFields(((BLangRecordLiteral) probeValue).getFields());
ProbeModel probeModel = new ProbeModel();
for (BLangRecordLiteral.BLangRecordKeyValueField probeField : buildExtensionRecord) {
ProbeConfiguration probeConfiguration = ProbeConfiguration.valueOf(probeField.getKey().toString());
switch(probeConfiguration) {
case port:
probeModel.setPort(getIntValue(probeField.getValue()));
break;
case initialDelaySeconds:
probeModel.setInitialDelaySeconds(getIntValue(probeField.getValue()));
break;
case periodSeconds:
probeModel.setPeriodSeconds(getIntValue(probeField.getValue()));
break;
default:
throw new KubernetesPluginException("unknown probe field found: " + probeField.getKey().toString());
}
}
return probeModel;
}
}
return null;
}
use of org.ballerinax.kubernetes.models.ProbeModel in project kubernetes by ballerinax.
the class KubernetesDeploymentGeneratorTests method testDeploymentGeneration.
@Test
public void testDeploymentGeneration() {
DeploymentModel deploymentModel = new DeploymentModel();
deploymentModel.setName(deploymentName);
Map<String, String> labels = new HashMap<>();
labels.put(KubernetesConstants.KUBERNETES_SELECTOR_KEY, selector);
deploymentModel.addPort(9090);
deploymentModel.addPort(9091);
deploymentModel.addPort(9092);
deploymentModel.setLabels(labels);
deploymentModel.setImage(imageName);
deploymentModel.setImagePullPolicy(imagePullPolicy);
ProbeModel probeModel = new ProbeModel();
probeModel.setPort(9090);
deploymentModel.setLivenessProbe(probeModel);
deploymentModel.setSingleYAML(false);
Map<String, EnvVarValueModel> env = new HashMap<>();
EnvVarValueModel testEnvVar = new EnvVarValueModel("ENV");
env.put("ENV_VAR", testEnvVar);
deploymentModel.setEnv(env);
deploymentModel.setReplicas(replicas);
dataHolder.setDeploymentModel(deploymentModel);
try {
new DeploymentHandler().createArtifacts();
File tempFile = dataHolder.getK8sArtifactOutputPath().resolve("hello_deployment.yaml").toFile();
Assert.assertTrue(tempFile.exists());
testGeneratedYAML(tempFile);
tempFile.deleteOnExit();
} catch (IOException e) {
Assert.fail("Unable to write to file");
} catch (KubernetesPluginException e) {
Assert.fail("Unable to generate yaml from service");
}
}
Aggregations