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());
}
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");
}
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());
}
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();
}
}
}
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;
}
Aggregations