use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project devspaces-images by redhat-developer.
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 io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project devspaces-images by redhat-developer.
the class PreviewUrlExposerTest method shouldProvisionServiceAndIngressWhenNotFound.
@Test
public void shouldProvisionServiceAndIngressWhenNotFound() 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;
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setIngresses(new HashMap<>()).setServices(new HashMap<>()).build();
previewUrlExposer.expose(env);
assertEquals(env.getIngresses().size(), 1);
assertEquals(env.getServices().size(), 1);
Service provisionedService = env.getServices().values().iterator().next();
ServicePort provisionedServicePort = provisionedService.getSpec().getPorts().get(0);
assertEquals(provisionedServicePort.getName(), SERVER_PORT_NAME);
assertEquals(provisionedServicePort.getPort().intValue(), PORT);
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(), provisionedService.getMetadata().getName());
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project devspaces-images by redhat-developer.
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 io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project devspaces-images by redhat-developer.
the class MultiHostExternalServiceExposureStrategyTest method assertThatExternalServerIsExposed.
private void assertThatExternalServerIsExposed(String machineName, String serviceName, String serverNameRegex, String portProtocol, Integer port, ServicePort servicePort, ServerConfigImpl expected) {
// ensure that required ingress is created
String ingressName = serviceName + "-" + (expected.isUnique() ? serverNameRegex : servicePort.getName());
Ingress ingress = kubernetesEnvironment.getIngresses().get(ingressName);
IngressRule ingressRule = ingress.getSpec().getRules().get(0);
assertEquals(ingressRule.getHost(), ingressName + "." + DOMAIN);
assertEquals(ingressRule.getHttp().getPaths().get(0).getPath(), "/");
IngressBackend backend = ingressRule.getHttp().getPaths().get(0).getBackend();
assertEquals(backend.getService().getName(), serviceName);
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);
assertEquals(serverConfig, expected);
assertEquals(ingressAnnotations.machineName(), machineName);
assertEquals(ingress.getMetadata().getLabels().get("foo"), "bar");
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend 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());
}
Aggregations