Search in sources :

Example 1 with IstioGatewayHandler

use of org.ballerinax.kubernetes.handlers.istio.IstioGatewayHandler in project kubernetes by ballerinax.

the class ArtifactManager method createArtifacts.

/**
 * Generate kubernetes artifacts.
 *
 * @throws KubernetesPluginException if an error occurs while generating artifacts
 */
void createArtifacts() throws KubernetesPluginException {
    // add default kubernetes instructions.
    setDefaultKubernetesInstructions();
    OUT.println("\nGenerating artifacts...");
    if (kubernetesDataHolder.getJobModel() != null) {
        new JobHandler().createArtifacts();
        new DockerHandler().createArtifacts();
    } else {
        new ServiceHandler().createArtifacts();
        new IngressHandler().createArtifacts();
        new SecretHandler().createArtifacts();
        new PersistentVolumeClaimHandler().createArtifacts();
        new ResourceQuotaHandler().createArtifacts();
        new ConfigMapHandler().createArtifacts();
        new DeploymentHandler().createArtifacts();
        new HPAHandler().createArtifacts();
        new DockerHandler().createArtifacts();
        new HelmChartHandler().createArtifacts();
        new IstioGatewayHandler().createArtifacts();
        new IstioVirtualServiceHandler().createArtifacts();
        if (kubernetesDataHolder.getOpenShiftBuildExtensionModel() != null || kubernetesDataHolder.getOpenShiftRouteModels().size() > 0) {
            // Clean all instructions
            instructions.clear();
            new OpenShiftBuildConfigHandler().createArtifacts();
            new OpenShiftImageStreamHandler().createArtifacts();
            new OpenShiftRouteHandler().createArtifacts();
        }
    }
    printInstructions();
}
Also used : ResourceQuotaHandler(org.ballerinax.kubernetes.handlers.ResourceQuotaHandler) OpenShiftRouteHandler(org.ballerinax.kubernetes.handlers.openshift.OpenShiftRouteHandler) IstioVirtualServiceHandler(org.ballerinax.kubernetes.handlers.istio.IstioVirtualServiceHandler) ServiceHandler(org.ballerinax.kubernetes.handlers.ServiceHandler) IstioGatewayHandler(org.ballerinax.kubernetes.handlers.istio.IstioGatewayHandler) OpenShiftBuildConfigHandler(org.ballerinax.kubernetes.handlers.openshift.OpenShiftBuildConfigHandler) IngressHandler(org.ballerinax.kubernetes.handlers.IngressHandler) DeploymentHandler(org.ballerinax.kubernetes.handlers.DeploymentHandler) IstioVirtualServiceHandler(org.ballerinax.kubernetes.handlers.istio.IstioVirtualServiceHandler) DockerHandler(org.ballerinax.kubernetes.handlers.DockerHandler) HPAHandler(org.ballerinax.kubernetes.handlers.HPAHandler) ConfigMapHandler(org.ballerinax.kubernetes.handlers.ConfigMapHandler) JobHandler(org.ballerinax.kubernetes.handlers.JobHandler) SecretHandler(org.ballerinax.kubernetes.handlers.SecretHandler) HelmChartHandler(org.ballerinax.kubernetes.handlers.HelmChartHandler) OpenShiftImageStreamHandler(org.ballerinax.kubernetes.handlers.openshift.OpenShiftImageStreamHandler) PersistentVolumeClaimHandler(org.ballerinax.kubernetes.handlers.PersistentVolumeClaimHandler)

Example 2 with IstioGatewayHandler

use of org.ballerinax.kubernetes.handlers.istio.IstioGatewayHandler 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

IstioGatewayHandler (org.ballerinax.kubernetes.handlers.istio.IstioGatewayHandler)2 File (java.io.File)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Gateway (me.snowdrop.istio.api.networking.v1alpha3.Gateway)1 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)1 ConfigMapHandler (org.ballerinax.kubernetes.handlers.ConfigMapHandler)1 DeploymentHandler (org.ballerinax.kubernetes.handlers.DeploymentHandler)1 DockerHandler (org.ballerinax.kubernetes.handlers.DockerHandler)1 HPAHandler (org.ballerinax.kubernetes.handlers.HPAHandler)1 HelmChartHandler (org.ballerinax.kubernetes.handlers.HelmChartHandler)1 IngressHandler (org.ballerinax.kubernetes.handlers.IngressHandler)1 JobHandler (org.ballerinax.kubernetes.handlers.JobHandler)1 PersistentVolumeClaimHandler (org.ballerinax.kubernetes.handlers.PersistentVolumeClaimHandler)1 ResourceQuotaHandler (org.ballerinax.kubernetes.handlers.ResourceQuotaHandler)1 SecretHandler (org.ballerinax.kubernetes.handlers.SecretHandler)1 ServiceHandler (org.ballerinax.kubernetes.handlers.ServiceHandler)1 IstioVirtualServiceHandler (org.ballerinax.kubernetes.handlers.istio.IstioVirtualServiceHandler)1 OpenShiftBuildConfigHandler (org.ballerinax.kubernetes.handlers.openshift.OpenShiftBuildConfigHandler)1