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