Search in sources :

Example 6 with IngressRule

use of io.fabric8.kubernetes.api.model.networking.v1.IngressRule in project che-server by eclipse-che.

the class PreviewUrlExposerTest method shouldNotProvisionWhenServiceAndIngressFound.

@Test
public void shouldNotProvisionWhenServiceAndIngressFound() throws InternalInfrastructureException {
    final int PORT = 8080;
    final String SERVER_PORT_NAME = "server-" + PORT;
    CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
    Service service = new Service();
    ObjectMeta serviceMeta = new ObjectMeta();
    serviceMeta.setName("servicename");
    service.setMetadata(serviceMeta);
    ServiceSpec serviceSpec = new ServiceSpec();
    serviceSpec.setPorts(singletonList(new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
    service.setSpec(serviceSpec);
    Ingress ingress = new Ingress();
    ObjectMeta ingressMeta = new ObjectMeta();
    ingressMeta.setName("ingressname");
    ingress.setMetadata(ingressMeta);
    IngressSpec ingressSpec = new IngressSpec();
    IngressRule ingressRule = new IngressRule();
    ingressRule.setHost("ingresshost");
    IngressBackend ingressBackend = new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVER_PORT_NAME, PORT)));
    ingressRule.setHttp(new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(ingressBackend, null, null))));
    ingressSpec.setRules(singletonList(ingressRule));
    ingress.setSpec(ingressSpec);
    Map<String, Service> services = new HashMap<>();
    services.put("servicename", service);
    Map<String, Ingress> ingresses = new HashMap<>();
    ingresses.put("ingressname", ingress);
    KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setIngresses(ingresses).build();
    assertEquals(env.getIngresses().size(), 1);
    previewUrlExposer.expose(env);
    assertEquals(env.getIngresses().size(), 1);
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) HashMap(java.util.HashMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) ServiceBackendPort(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) HTTPIngressRuleValue(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend) Test(org.testng.annotations.Test)

Example 7 with IngressRule

use of io.fabric8.kubernetes.api.model.networking.v1.IngressRule in project che-server by eclipse-che.

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 8 with IngressRule

use of io.fabric8.kubernetes.api.model.networking.v1.IngressRule in project devspaces-images by redhat-developer.

the class ExternalServerIngressBuilder method build.

public Ingress build() {
    ServiceBackendPortBuilder serviceBackendPortBuilder = new ServiceBackendPortBuilder();
    // cannot set both port and name
    if (!isNullOrEmpty(servicePortName)) {
        serviceBackendPortBuilder.withName(servicePortName);
    } else if (servicePort != null) {
        serviceBackendPortBuilder.withNumber(servicePort);
    }
    IngressServiceBackend ingressServiceBackend = new IngressServiceBackendBuilder().withPort(serviceBackendPortBuilder.build()).withName(serviceName).build();
    IngressBackend ingressBackend = new IngressBackendBuilder().withService(ingressServiceBackend).build();
    HTTPIngressPathBuilder httpIngressPathBuilder = new HTTPIngressPathBuilder().withBackend(ingressBackend).withPathType(INGRESS_PATH_TYPE);
    if (!isNullOrEmpty(path)) {
        httpIngressPathBuilder.withPath(path);
    }
    HTTPIngressPath httpIngressPath = httpIngressPathBuilder.build();
    HTTPIngressRuleValue httpIngressRuleValue = new HTTPIngressRuleValueBuilder().withPaths(httpIngressPath).build();
    IngressRuleBuilder ingressRuleBuilder = new IngressRuleBuilder().withHttp(httpIngressRuleValue);
    if (!isNullOrEmpty(host)) {
        ingressRuleBuilder.withHost(host);
    }
    IngressRule ingressRule = ingressRuleBuilder.build();
    IngressSpec ingressSpec = new IngressSpecBuilder().withRules(ingressRule).build();
    Map<String, String> ingressAnnotations = new HashMap<>(annotations);
    ingressAnnotations.putAll(Annotations.newSerializer().servers(serversConfigs).machineName(machineName).annotations());
    return new IngressBuilder().withSpec(ingressSpec).withMetadata(new ObjectMetaBuilder().withName(name).withAnnotations(ingressAnnotations).withLabels(labels).build()).build();
}
Also used : IngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder) IngressBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder) HashMap(java.util.HashMap) IngressServiceBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackendBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) HTTPIngressRuleValueBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder) IngressSpecBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressSpecBuilder) HTTPIngressRuleValue(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue) ServiceBackendPortBuilder(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)

Example 9 with IngressRule

use of io.fabric8.kubernetes.api.model.networking.v1.IngressRule in project devspaces-images by redhat-developer.

the class IngressServerResolver method fillIngressServers.

private Map<String, ServerImpl> fillIngressServers(Ingress ingress) {
    IngressRule ingressRule = ingress.getSpec().getRules().get(0);
    // host either set by rule, or determined by LB ip
    final String host = ingressRule.getHost() != null ? ingressRule.getHost() : ingress.getStatus().getLoadBalancer().getIngress().get(0).getIp();
    return Annotations.newDeserializer(ingress.getMetadata().getAnnotations()).servers().entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> {
        String root = pathTransformInverter.undoPathTransformation(ingressRule.getHttp().getPaths().get(0).getPath());
        String path = buildPath(root, e.getValue().getPath());
        // the /jwt/auth needs to be based on the webroot of the server, not the path of
        // the endpoint.
        String endpointOrigin = buildPath(root, "/");
        return new RuntimeServerBuilder().protocol(e.getValue().getProtocol()).host(host).path(path).endpointOrigin(endpointOrigin).attributes(e.getValue().getAttributes()).targetPort(e.getValue().getPort()).build();
    }));
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) IngressPathTransformInverter(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.IngressPathTransformInverter) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) KubernetesServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) List(java.util.List) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Map(java.util.Map) Entry(java.util.Map.Entry) Service(io.fabric8.kubernetes.api.model.Service) RuntimeServerBuilder(org.eclipse.che.workspace.infrastructure.kubernetes.server.RuntimeServerBuilder) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) RuntimeServerBuilder(org.eclipse.che.workspace.infrastructure.kubernetes.server.RuntimeServerBuilder)

Example 10 with IngressRule

use of io.fabric8.kubernetes.api.model.networking.v1.IngressRule in project devspaces-images by redhat-developer.

the class PreviewUrlExposerTest method shouldNotProvisionWhenServiceAndIngressFound.

@Test
public void shouldNotProvisionWhenServiceAndIngressFound() throws InternalInfrastructureException {
    final int PORT = 8080;
    final String SERVER_PORT_NAME = "server-" + PORT;
    CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
    Service service = new Service();
    ObjectMeta serviceMeta = new ObjectMeta();
    serviceMeta.setName("servicename");
    service.setMetadata(serviceMeta);
    ServiceSpec serviceSpec = new ServiceSpec();
    serviceSpec.setPorts(singletonList(new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
    service.setSpec(serviceSpec);
    Ingress ingress = new Ingress();
    ObjectMeta ingressMeta = new ObjectMeta();
    ingressMeta.setName("ingressname");
    ingress.setMetadata(ingressMeta);
    IngressSpec ingressSpec = new IngressSpec();
    IngressRule ingressRule = new IngressRule();
    ingressRule.setHost("ingresshost");
    IngressBackend ingressBackend = new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVER_PORT_NAME, PORT)));
    ingressRule.setHttp(new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(ingressBackend, null, null))));
    ingressSpec.setRules(singletonList(ingressRule));
    ingress.setSpec(ingressSpec);
    Map<String, Service> services = new HashMap<>();
    services.put("servicename", service);
    Map<String, Ingress> ingresses = new HashMap<>();
    ingresses.put("ingressname", ingress);
    KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setIngresses(ingresses).build();
    assertEquals(env.getIngresses().size(), 1);
    previewUrlExposer.expose(env);
    assertEquals(env.getIngresses().size(), 1);
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) HashMap(java.util.HashMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) ServiceBackendPort(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) HTTPIngressRuleValue(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend) Test(org.testng.annotations.Test)

Aggregations

IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)39 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)37 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)24 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)19 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)19 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)19 Service (io.fabric8.kubernetes.api.model.Service)17 ServiceBackendPort (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort)16 IngressSpec (io.fabric8.kubernetes.api.model.networking.v1.IngressSpec)14 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder)12 Test (org.testng.annotations.Test)12 HTTPIngressRuleValue (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue)11 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)10 IngressRuleBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder)10 ArrayList (java.util.ArrayList)10 IngressTLSBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)9 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)8 GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)8 HTTPIngressRuleValueBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder)7 Annotations (org.eclipse.che.workspace.infrastructure.kubernetes.Annotations)6