Search in sources :

Example 26 with IngressBackend

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());
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) HashMap(java.util.HashMap) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) 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) Test(org.testng.annotations.Test)

Example 27 with IngressBackend

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;
}
Also used : IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) ServiceBackendPort(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)

Example 28 with IngressBackend

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;
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) HTTPIngressRuleValue(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)

Example 29 with IngressBackend

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());
}
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 30 with IngressBackend

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

Aggregations

IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)28 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)26 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)26 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)21 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)18 Service (io.fabric8.kubernetes.api.model.Service)17 ServiceBackendPort (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort)16 Test (org.testng.annotations.Test)16 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)12 IngressSpec (io.fabric8.kubernetes.api.model.networking.v1.IngressSpec)12 HTTPIngressRuleValue (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue)10 HashMap (java.util.HashMap)10 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)9 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)8 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)8 PreviewUrlImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl)8 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)8 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)6 HTTPIngressPath (io.fabric8.kubernetes.api.model.extensions.HTTPIngressPath)6 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)6