Search in sources :

Example 31 with Ingress

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

the class IngressesTest method emptyWhenPortByIntAndNotFound.

@Test
public void emptyWhenPortByIntAndNotFound() {
    final String SERVER_PORT_NAME = "server-8080";
    final int PORT = 8080;
    Service service = createService(SERVER_PORT_NAME, PORT);
    Ingress ingress = createIngress(new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(null, 666))));
    Optional<IngressRule> foundRule = Ingresses.findIngressRuleForServicePort(singletonList(ingress), service, PORT);
    assertFalse(foundRule.isPresent());
}
Also used : ServiceBackendPort(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) 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) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) Test(org.testng.annotations.Test)

Example 32 with Ingress

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

the class IngressesTest method findHostWhenPortDefinedByInt.

@Test
public void findHostWhenPortDefinedByInt() {
    final String SERVER_PORT_NAME = "server-8080";
    final int PORT = 8080;
    Service service = createService(SERVER_PORT_NAME, PORT);
    Ingress ingress = createIngress(new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVER_PORT_NAME, PORT))));
    Optional<IngressRule> foundRule = Ingresses.findIngressRuleForServicePort(singletonList(ingress), service, PORT);
    assertTrue(foundRule.isPresent());
    assertEquals(foundRule.get().getHost(), "ingresshost");
}
Also used : ServiceBackendPort(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) 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) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) Test(org.testng.annotations.Test)

Example 33 with Ingress

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

the class IngressesTest method emptyWhenPortByStringAndNotFound.

@Test
public void emptyWhenPortByStringAndNotFound() {
    final String SERVER_PORT_NAME = "server-8080";
    final int PORT = 8080;
    Service service = createService(SERVER_PORT_NAME, PORT);
    Ingress ingress = createIngress(new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort("does not exist", null))));
    Optional<IngressRule> foundRule = Ingresses.findIngressRuleForServicePort(singletonList(ingress), service, PORT);
    assertFalse(foundRule.isPresent());
}
Also used : ServiceBackendPort(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) 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) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) Test(org.testng.annotations.Test)

Example 34 with Ingress

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

the class KubernetesIngresses method wait.

public Ingress wait(String name, long timeout, TimeUnit timeoutUnit, Predicate<Ingress> predicate) throws InfrastructureException {
    CompletableFuture<Ingress> future = new CompletableFuture<>();
    Watch watch = null;
    try {
        Resource<Ingress> ingressResource = clientFactory.create(workspaceId).network().v1().ingresses().inNamespace(namespace).withName(name);
        watch = ingressResource.watch(new Watcher<>() {

            @Override
            public void eventReceived(Action action, Ingress ingress) {
                if (predicate.test(ingress)) {
                    future.complete(ingress);
                }
            }

            @Override
            public void onClose(WatcherException cause) {
                future.completeExceptionally(new InfrastructureException("Waiting for ingress '" + name + "' was interrupted"));
            }
        });
        Ingress actualIngress = ingressResource.get();
        if (actualIngress == null) {
            throw new InfrastructureException("Specified ingress " + name + " doesn't exist");
        }
        if (predicate.test(actualIngress)) {
            return actualIngress;
        }
        try {
            return future.get(timeout, timeoutUnit);
        } catch (ExecutionException e) {
            throw new InfrastructureException(e.getCause().getMessage(), e);
        } catch (TimeoutException e) {
            throw new InfrastructureException("Waiting for ingress '" + name + "' reached timeout");
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new InfrastructureException("Waiting for ingress '" + name + "' was interrupted");
        }
    } catch (KubernetesClientException e) {
        throw new KubernetesInfrastructureException(e);
    } finally {
        if (watch != null) {
            watch.close();
        }
    }
}
Also used : Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Watcher(io.fabric8.kubernetes.client.Watcher) KubernetesInfrastructureException(org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException) WatcherException(io.fabric8.kubernetes.client.WatcherException) CompletableFuture(java.util.concurrent.CompletableFuture) Watch(io.fabric8.kubernetes.client.Watch) ExecutionException(java.util.concurrent.ExecutionException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) KubernetesInfrastructureException(org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException) TimeoutException(java.util.concurrent.TimeoutException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 35 with Ingress

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

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)

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