use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project che-server by eclipse-che.
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 che-server by eclipse-che.
the class KubernetesInternalRuntimeTest method mockIngress.
private static Ingress mockIngress() {
final Ingress ingress = mock(Ingress.class);
mockName(INGRESS_NAME, ingress);
final IngressSpec spec = mock(IngressSpec.class);
final IngressBackend backend = mock(IngressBackend.class);
final IngressServiceBackend ingressServiceBackend = mock(IngressServiceBackend.class);
final ServiceBackendPort serviceBackendPort = mock(ServiceBackendPort.class);
when(spec.getDefaultBackend()).thenReturn(backend);
when(backend.getService()).thenReturn(ingressServiceBackend);
when(ingressServiceBackend.getPort()).thenReturn(serviceBackendPort);
when(ingressServiceBackend.getName()).thenReturn(SERVICE_NAME);
when(serviceBackendPort.getNumber()).thenReturn(EXPOSED_PORT_1);
final IngressRule rule = mock(IngressRule.class);
when(rule.getHost()).thenReturn(INGRESS_HOST);
when(spec.getRules()).thenReturn(singletonList(rule));
when(ingress.getSpec()).thenReturn(spec);
when(ingress.getMetadata().getLabels()).thenReturn(ImmutableMap.of(CHE_ORIGINAL_NAME_LABEL, INGRESS_NAME));
return ingress;
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project che-server by eclipse-che.
the class IngressesTest method createIngress.
private Ingress createIngress(IngressBackend backend) {
Ingress ingress = new Ingress();
ObjectMeta ingressMeta = new ObjectMeta();
ingressMeta.setName("ingressname");
ingress.setMetadata(ingressMeta);
IngressSpec ingressSpec = new IngressSpec();
IngressRule ingressRule = new IngressRule();
ingressRule.setHost("ingresshost");
ingressRule.setHttp(new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(backend, null, null))));
ingressSpec.setRules(singletonList(ingressRule));
ingress.setSpec(ingressSpec);
return ingress;
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project che-server by eclipse-che.
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 io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project che-server by eclipse-che.
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