Search in sources :

Example 16 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project che-server by eclipse-che.

the class PreviewUrlExposerTest method shouldProvisionIngressWhenNotFound.

@Test
public void shouldProvisionIngressWhenNotFound() 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;
    final String SERVICE_NAME = "servicename";
    CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
    Service service = new Service();
    ObjectMeta serviceMeta = new ObjectMeta();
    serviceMeta.setName(SERVICE_NAME);
    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);
    Map<String, Service> services = new HashMap<>();
    services.put(SERVICE_NAME, service);
    KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setIngresses(new HashMap<>()).build();
    previewUrlExposer.expose(env);
    assertEquals(env.getIngresses().size(), 1);
    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(), SERVICE_NAME);
}
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) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend) Test(org.testng.annotations.Test)

Example 17 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress 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 18 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project che-server by eclipse-che.

the class KubernetesInternalRuntime method createAndWaitReady.

private List<Ingress> createAndWaitReady(Collection<Ingress> ingresses) throws InfrastructureException {
    List<Ingress> createdIngresses = new ArrayList<>();
    for (Ingress ingress : ingresses) {
        createdIngresses.add(namespace.ingresses().create(ingress));
    }
    LOG.debug("Ingresses created for workspace '{}'. Wait them to be ready.", getContext().getIdentity().getWorkspaceId());
    // wait for LB ip
    List<Ingress> readyIngresses = new ArrayList<>();
    for (Ingress ingress : createdIngresses) {
        Ingress actualIngress = namespace.ingresses().wait(ingress.getMetadata().getName(), // Smaller value of ingress and start timeout should be used
        Math.min(ingressStartTimeoutMillis, startSynchronizer.getStartTimeoutMillis()), TimeUnit.MILLISECONDS, p -> (!p.getStatus().getLoadBalancer().getIngress().isEmpty()));
        readyIngresses.add(actualIngress);
    }
    LOG.debug("Ingresses creation for workspace '{}' done.", getContext().getIdentity().getWorkspaceId());
    return readyIngresses;
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress)

Example 19 with Ingress

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

the class IngressTlsProvisioner method provision.

@Override
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws KubernetesInfrastructureException {
    if (!isTlsEnabled) {
        return;
    }
    String wsTlsSecretName = tlsSecretName;
    if (!isNullOrEmpty(tlsCert) && !isNullOrEmpty(tlsKey)) {
        wsTlsSecretName = identity.getWorkspaceId() + '-' + tlsSecretName;
        provisionTlsSecret(k8sEnv, wsTlsSecretName);
    }
    for (Ingress ingress : k8sEnv.getIngresses().values()) {
        useSecureProtocolForIngressServers(ingress);
        enableTLS(ingress, wsTlsSecretName);
    }
}
Also used : Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress)

Example 20 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress 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)

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