use of org.ballerinax.kubernetes.handlers.IngressHandler in project kubernetes by ballerinax.
the class KubernetesIngressGeneratorTests method testIngressGenerator.
@Test
public void testIngressGenerator() {
IngressModel ingressModel = new IngressModel();
ingressModel.setName("MyIngress");
ingressModel.setHostname("abc.com");
ingressModel.setPath("/helloworld");
ingressModel.setServicePort(9090);
ingressModel.setIngressClass("nginx");
ingressModel.setServiceName("HelloWorldService");
Map<String, String> labels = new HashMap<>();
labels.put(KubernetesConstants.KUBERNETES_SELECTOR_KEY, "TestAPP");
ingressModel.setLabels(labels);
IngressHandler kubernetesIngressGenerator = new IngressHandler(ingressModel);
try {
String ingressYaml = kubernetesIngressGenerator.generate();
Assert.assertNotNull(ingressYaml);
File artifactLocation = new File("target/kubernetes");
artifactLocation.mkdir();
File tempFile = File.createTempFile("temp", ingressModel.getName() + ".yaml", artifactLocation);
KubernetesUtils.writeToFile(ingressYaml, tempFile.getPath());
log.info("Generated YAML: \n" + ingressYaml);
Assert.assertTrue(tempFile.exists());
// tempFile.deleteOnExit();
} catch (IOException e) {
Assert.fail("Unable to write to file");
} catch (KubernetesPluginException e) {
Assert.fail("Unable to generate yaml from ingress");
}
}
use of org.ballerinax.kubernetes.handlers.IngressHandler 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);
}
}
Aggregations