Search in sources :

Example 26 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project devspaces-images by redhat-developer.

the class PreviewUrlExposerTest method shouldProvisionServiceAndIngressWhenNotFound.

@Test
public void shouldProvisionServiceAndIngressWhenNotFound() throws InternalInfrastructureException {
    Mockito.when(externalServiceExposureStrategy.getExternalPath(Mockito.anyString(), Mockito.any())).thenReturn("some-server-path");
    final int PORT = 8080;
    final String SERVER_PORT_NAME = "server-" + PORT;
    CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
    KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setIngresses(new HashMap<>()).setServices(new HashMap<>()).build();
    previewUrlExposer.expose(env);
    assertEquals(env.getIngresses().size(), 1);
    assertEquals(env.getServices().size(), 1);
    Service provisionedService = env.getServices().values().iterator().next();
    ServicePort provisionedServicePort = provisionedService.getSpec().getPorts().get(0);
    assertEquals(provisionedServicePort.getName(), SERVER_PORT_NAME);
    assertEquals(provisionedServicePort.getPort().intValue(), PORT);
    Ingress provisionedIngress = env.getIngresses().values().iterator().next();
    IngressBackend provisionedIngressBackend = provisionedIngress.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend();
    assertEquals(provisionedIngressBackend.getService().getPort().getName(), SERVER_PORT_NAME);
    assertEquals(provisionedIngressBackend.getService().getName(), provisionedService.getMetadata().getName());
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) HashMap(java.util.HashMap) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend) Test(org.testng.annotations.Test)

Example 27 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project devspaces-images by redhat-developer.

the class DefaultHostExternalServiceExposureStrategyTest method assertThatExternalServerIsExposed.

@SuppressWarnings("SameParameterValue")
private void assertThatExternalServerIsExposed(String machineName, String serviceName, String serverNameRegex, ServicePort servicePort, ServerConfigImpl expected) {
    // ensure that required ingress is created
    for (Ingress ingress : kubernetesEnvironment.getIngresses().values()) {
        IngressRule ingressRule = ingress.getSpec().getRules().get(0);
        IngressBackend backend = ingressRule.getHttp().getPaths().get(0).getBackend();
        if (serviceName.equals(backend.getService().getName())) {
            assertEquals(backend.getService().getPort().getName(), servicePort.getName());
            Annotations.Deserializer ingressAnnotations = Annotations.newDeserializer(ingress.getMetadata().getAnnotations());
            Map<String, ServerConfigImpl> servers = ingressAnnotations.servers();
            ServerConfig serverConfig = servers.get(serverNameRegex);
            if (serverConfig == null) {
                // ok, this ingress is not for this particular server
                continue;
            }
            assertEquals(serverConfig, expected);
            assertEquals(ingressAnnotations.machineName(), machineName);
            return;
        }
    }
    Assert.fail(format("Could not find an ingress for machine '%s' and service '%s'", machineName, serviceName));
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)

Example 28 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project devspaces-images by redhat-developer.

the class ExternalServerIngressBuilderTest method shouldCreateIngress.

@Test
public void shouldCreateIngress() {
    // given
    final String path = "/path/to/server";
    final String host = "host-to-server";
    // when
    Ingress ingress = externalServerIngressBuilder.withPath(path).withHost(host).withAnnotations(ANNOTATIONS).withMachineName(MACHINE_NAME).withName(NAME).withServers(SERVERS).withServiceName(SERVICE_NAME).withServicePortName(SERVICE_PORT_NAME).withServicePort(SERVICE_PORT).build();
    // then
    assertIngressSpec(path, host, ingress);
}
Also used : Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Test(org.testng.annotations.Test)

Example 29 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project devspaces-images by redhat-developer.

the class IngressServerExposerTest method shouldReplaceServerNamePlaceholders.

@Test
public void shouldReplaceServerNamePlaceholders() {
    // given
    Map<String, String> annotations = new HashMap<>();
    annotations.put("ssl", "true");
    annotations.put("websocket-service", SERVICE_NAME_PLACEHOLDER);
    IngressServerExposer<KubernetesEnvironment> exposer = new IngressServerExposer<>(serviceExposureStrategy, annotations, null, "");
    KubernetesEnvironment env = KubernetesEnvironment.builder().build();
    Map<String, ServerConfig> externalServers = new HashMap<>();
    externalServers.put("ide", new ServerConfigImpl("6543", "http", "/", emptyMap()));
    // when
    exposer.expose(env, "editor", "ide", "server123", new ServicePort(), externalServers);
    // then
    Collection<Ingress> ingresses = env.getIngresses().values();
    assertEquals(ingresses.size(), 1);
    Ingress ingress = ingresses.iterator().next();
    assertEquals(ingress.getMetadata().getAnnotations().get("ssl"), "true");
    assertEquals(ingress.getMetadata().getAnnotations().get("websocket-service"), "ide");
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) HashMap(java.util.HashMap) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Test(org.testng.annotations.Test)

Example 30 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project devspaces-images by redhat-developer.

the class MultiHostExternalServiceExposureStrategyTest method assertThatExternalServerIsExposed.

private void assertThatExternalServerIsExposed(String machineName, String serviceName, String serverNameRegex, String portProtocol, Integer port, ServicePort servicePort, ServerConfigImpl expected) {
    // ensure that required ingress is created
    String ingressName = serviceName + "-" + (expected.isUnique() ? serverNameRegex : servicePort.getName());
    Ingress ingress = kubernetesEnvironment.getIngresses().get(ingressName);
    IngressRule ingressRule = ingress.getSpec().getRules().get(0);
    assertEquals(ingressRule.getHost(), ingressName + "." + DOMAIN);
    assertEquals(ingressRule.getHttp().getPaths().get(0).getPath(), "/");
    IngressBackend backend = ingressRule.getHttp().getPaths().get(0).getBackend();
    assertEquals(backend.getService().getName(), serviceName);
    assertEquals(backend.getService().getPort().getName(), servicePort.getName());
    Annotations.Deserializer ingressAnnotations = Annotations.newDeserializer(ingress.getMetadata().getAnnotations());
    Map<String, ServerConfigImpl> servers = ingressAnnotations.servers();
    ServerConfig serverConfig = servers.get(serverNameRegex);
    assertEquals(serverConfig, expected);
    assertEquals(ingressAnnotations.machineName(), machineName);
    assertEquals(ingress.getMetadata().getLabels().get("foo"), "bar");
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)

Aggregations

Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)158 Service (io.fabric8.kubernetes.api.model.Service)47 Test (org.junit.jupiter.api.Test)42 Test (org.testng.annotations.Test)36 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)31 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)28 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)25 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)24 ArrayList (java.util.ArrayList)22 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)21 HashMap (java.util.HashMap)21 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)16 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)16 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)14 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)14 ServiceBackendPort (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort)14 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)14 KafkaCluster (io.strimzi.operator.cluster.model.KafkaCluster)14 Reconciliation (io.strimzi.operator.common.Reconciliation)14 IngressOperator (io.strimzi.operator.common.operator.resource.IngressOperator)14