Search in sources :

Example 1 with IngressHandler

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");
    }
}
Also used : IngressModel(org.ballerinax.kubernetes.models.IngressModel) HashMap(java.util.HashMap) IngressHandler(org.ballerinax.kubernetes.handlers.IngressHandler) IOException(java.io.IOException) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) File(java.io.File) Test(org.junit.Test)

Example 2 with IngressHandler

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

Aggregations

IOException (java.io.IOException)2 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)2 IngressHandler (org.ballerinax.kubernetes.handlers.IngressHandler)2 File (java.io.File)1 HashMap (java.util.HashMap)1 IngressModel (org.ballerinax.kubernetes.models.IngressModel)1 Test (org.junit.Test)1