Search in sources :

Example 11 with Gateway

use of me.snowdrop.istio.api.networking.v1alpha3.Gateway in project kubernetes by ballerinax.

the class IstioGatewayTest method emptyAnnoForEndpointTest.

/**
 * Build bal file with istio gateway annotation with no values for endpoint.
 *
 * @throws IOException               Error when loading the generated yaml.
 * @throws InterruptedException      Error when compiling the ballerina file.
 * @throws KubernetesPluginException Error when deleting the generated artifacts folder.
 */
@Test(groups = { "istio" })
public void emptyAnnoForEndpointTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "empty_annotation_ep.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate gateway yaml
    File gatewayFile = KUBERNETES_TARGET_PATH.resolve("empty_annotation_ep_istio_gateway.yaml").toFile();
    Assert.assertTrue(gatewayFile.exists());
    Gateway gateway = KubernetesTestUtils.loadYaml(gatewayFile);
    Assert.assertNotNull(gateway.getMetadata());
    Assert.assertEquals(gateway.getMetadata().getName(), "helloep-istio-gw", "Invalid gateway name");
    Assert.assertNotNull(gateway.getSpec());
    Assert.assertEquals(gateway.getSpec().getSelector().get(KubernetesConstants.ISTIO_GATEWAY_SELECTOR), "ingressgateway", "Invalid selector.");
    Assert.assertNotNull(gateway.getSpec().getServers());
    Assert.assertEquals(gateway.getSpec().getServers().size(), 1);
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getNumber().intValue(), 80, "Invalid port number.");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getName(), "http", "Invalid port name.");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getProtocol(), "HTTP", "Invalid port protocol.");
    Assert.assertNotNull(gateway.getSpec().getServers().get(0).getHosts());
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getHosts().size(), 1);
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getHosts().get(0), "*", "* host not included");
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Also used : Gateway(me.snowdrop.istio.api.networking.v1alpha3.Gateway) File(java.io.File) Test(org.testng.annotations.Test)

Example 12 with Gateway

use of me.snowdrop.istio.api.networking.v1alpha3.Gateway in project kubernetes by ballerinax.

the class IstioGatewayTest method noSelectorTest.

/**
 * Build bal file with no selector istio gateway annotations.
 *
 * @throws IOException          Error when loading the generated yaml.
 * @throws InterruptedException Error when compiling the ballerina file.
 */
@Test(groups = { "istio" })
public void noSelectorTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "no_selector.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate gateway yaml
    File gatewayFile = KUBERNETES_TARGET_PATH.resolve("no_selector_istio_gateway.yaml").toFile();
    Assert.assertTrue(gatewayFile.exists());
    Gateway gateway = KubernetesTestUtils.loadYaml(gatewayFile);
    Assert.assertNotNull(gateway.getSpec());
    Assert.assertNotNull(gateway.getSpec().getSelector());
    Assert.assertEquals(gateway.getSpec().getSelector().get(KubernetesConstants.ISTIO_GATEWAY_SELECTOR), "ingressgateway", "Invalid selector.");
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Also used : Gateway(me.snowdrop.istio.api.networking.v1alpha3.Gateway) File(java.io.File) Test(org.testng.annotations.Test)

Example 13 with Gateway

use of me.snowdrop.istio.api.networking.v1alpha3.Gateway in project kubernetes by ballerinax.

the class IstioGatewayTest method tlsSimpleTest.

/**
 * Build bal file with istio gateway annotation having simple mode TLS.
 *
 * @throws IOException               Error when loading the generated yaml.
 * @throws InterruptedException      Error when compiling the ballerina file.
 * @throws KubernetesPluginException Error when deleting the generated artifacts folder.
 */
@Test(groups = { "istio" })
public void tlsSimpleTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "tls_simple.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate gateway yaml
    File gatewayFile = KUBERNETES_TARGET_PATH.resolve("tls_simple_istio_gateway.yaml").toFile();
    Assert.assertTrue(gatewayFile.exists());
    Gateway gateway = KubernetesTestUtils.loadYaml(gatewayFile);
    Assert.assertNotNull(gateway.getMetadata());
    Assert.assertEquals(gateway.getMetadata().getName(), "my-gateway", "Invalid gateway name");
    Assert.assertNotNull(gateway.getSpec());
    Assert.assertEquals(gateway.getSpec().getSelector().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), "my-gateway-controller", "Invalid selector.");
    Assert.assertNotNull(gateway.getSpec().getServers());
    Assert.assertEquals(gateway.getSpec().getServers().size(), 1);
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getNumber().intValue(), 443, "Invalid port number.");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getName(), "https", "Invalid port name.");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getProtocol(), "HTTPS", "Invalid port protocol.");
    Assert.assertNotNull(gateway.getSpec().getServers().get(0).getHosts());
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getHosts().size(), 1);
    Assert.assertTrue(gateway.getSpec().getServers().get(0).getHosts().contains("httpbin.example.com"), "httpbin.example.com host not included");
    Assert.assertNotNull(gateway.getSpec().getServers().get(0).getTls());
    Assert.assertFalse(gateway.getSpec().getServers().get(0).getTls().getHttpsRedirect(), "Invalid tls httpsRedirect value");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getTls().getMode().name(), "SIMPLE", "Invalid tls mode value");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getTls().getServerCertificate(), "/etc/istio/ingressgateway-certs/tls.crt", "Invalid tls serverCertificate value");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getTls().getPrivateKey(), "/etc/istio/ingressgateway-certs/tls.key", "Invalid tls privateKey value");
    Assert.assertNull(gateway.getSpec().getServers().get(0).getTls().getCaCertificates(), "Unexpected tls caCertificates value found.");
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Also used : Gateway(me.snowdrop.istio.api.networking.v1alpha3.Gateway) File(java.io.File) Test(org.testng.annotations.Test)

Example 14 with Gateway

use of me.snowdrop.istio.api.networking.v1alpha3.Gateway in project kubernetes by ballerinax.

the class IstioGatewayGeneratorTests method testSimpleGateway.

@Test
public void testSimpleGateway() {
    IstioGatewayModel istioGatewayModel = new IstioGatewayModel();
    istioGatewayModel.setName("my-gateway");
    Map<String, String> selectors = new LinkedHashMap<>();
    selectors.put(KubernetesConstants.KUBERNETES_SELECTOR_KEY, "my-gatweway-controller");
    istioGatewayModel.setSelector(selectors);
    List<IstioServerModel> serverModels = new LinkedList<>();
    // First server
    IstioServerModel serverModel = new IstioServerModel();
    IstioPortModel portModel = new IstioPortModel();
    portModel.setNumber(80);
    portModel.setProtocol("HTTP");
    portModel.setName("http");
    serverModel.setPort(portModel);
    List<String> hostModels = new LinkedList<>();
    hostModels.add("uk.bookinfo.com");
    hostModels.add("eu.bookinfo.com");
    serverModel.setHosts(hostModels);
    IstioServerModel.TLSOptions tlsOptions = new IstioServerModel.TLSOptions();
    tlsOptions.setHttpsRedirect(true);
    serverModel.setTls(tlsOptions);
    serverModels.add(serverModel);
    istioGatewayModel.setServers(serverModels);
    dataHolder.addIstioGatewayModel("sample-svc", istioGatewayModel);
    try {
        new IstioGatewayHandler().createArtifacts();
        File gwYaml = dataHolder.getK8sArtifactOutputPath().resolve("hello" + ISTIO_GATEWAY_FILE_POSTFIX + YAML).toFile();
        Gateway gateway = Utils.loadYaml(gwYaml);
        // metadata
        Assert.assertNotNull(gateway.getMetadata());
        Assert.assertEquals(gateway.getMetadata().getName(), "my-gateway");
        Assert.assertNotNull(gateway.getSpec());
        Assert.assertEquals(gateway.getSpec().getSelector().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), "my-gatweway-controller");
        Assert.assertEquals(gateway.getSpec().getServers().size(), 1);
        Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getNumber().intValue(), 80);
        Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getProtocol(), "HTTP");
        Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getName(), "http");
        Assert.assertEquals(gateway.getSpec().getServers().get(0).getHosts().size(), 2);
        Assert.assertEquals(gateway.getSpec().getServers().get(0).getHosts().get(0), "uk.bookinfo.com");
        Assert.assertEquals(gateway.getSpec().getServers().get(0).getHosts().get(1), "eu.bookinfo.com");
        Assert.assertNotNull(gateway.getSpec().getServers().get(0).getTls());
        Assert.assertTrue(gateway.getSpec().getServers().get(0).getTls().getHttpsRedirect());
        gwYaml.deleteOnExit();
    } catch (IOException e) {
        Assert.fail("Unable to write to file: " + e.getMessage());
    } catch (KubernetesPluginException e) {
        Assert.fail("Unable to generate yaml: " + e.getMessage());
    }
}
Also used : IstioGatewayHandler(org.ballerinax.kubernetes.handlers.istio.IstioGatewayHandler) IstioGatewayModel(org.ballerinax.kubernetes.models.istio.IstioGatewayModel) IstioServerModel(org.ballerinax.kubernetes.models.istio.IstioServerModel) IOException(java.io.IOException) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) IstioPortModel(org.ballerinax.kubernetes.models.istio.IstioPortModel) Gateway(me.snowdrop.istio.api.networking.v1alpha3.Gateway) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

Gateway (me.snowdrop.istio.api.networking.v1alpha3.Gateway)10 Test (org.testng.annotations.Test)10 File (java.io.File)9 Gateway (org.eclipse.bpmn2.Gateway)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)2 BoundaryEvent (org.eclipse.bpmn2.BoundaryEvent)2 CallActivity (org.eclipse.bpmn2.CallActivity)2 EndEvent (org.eclipse.bpmn2.EndEvent)2 ExclusiveGateway (org.eclipse.bpmn2.ExclusiveGateway)2 FlowElement (org.eclipse.bpmn2.FlowElement)2 FlowElementsContainer (org.eclipse.bpmn2.FlowElementsContainer)2 InclusiveGateway (org.eclipse.bpmn2.InclusiveGateway)2 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)2 Point (org.eclipse.dd.dc.Point)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1