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