Search in sources :

Example 6 with ServiceBackendPort

use of io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort 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());
}
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 7 with ServiceBackendPort

use of io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort 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");
}
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 8 with ServiceBackendPort

use of io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort 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());
}
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 9 with ServiceBackendPort

use of io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort in project che-server by eclipse-che.

the class IngressServerResolverTest method createIngress.

private Ingress createIngress(String name, String machineName, Pair<String, ServerConfig> server) {
    Serializer serializer = Annotations.newSerializer();
    serializer.machineName(machineName);
    serializer.server(server.first, server.second);
    return new IngressBuilder().withNewMetadata().withName(name).withAnnotations(serializer.annotations()).endMetadata().withNewSpec().withRules(new IngressRule(null, new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(new IngressBackend(null, new IngressServiceBackend(name, new ServiceBackendPort("8080", 8080))), INGRESS_PATH_PREFIX, null))))).endSpec().withNewStatus().withLoadBalancer(new LoadBalancerStatusBuilder().addNewIngress().withIp("127.0.0.1").endIngress().build()).endStatus().build();
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) ServiceBackendPort(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) HTTPIngressRuleValue(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend) LoadBalancerStatusBuilder(io.fabric8.kubernetes.api.model.LoadBalancerStatusBuilder) Serializer(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations.Serializer) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)

Example 10 with ServiceBackendPort

use of io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort 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)

Aggregations

IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)16 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)16 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)16 ServiceBackendPort (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort)16 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)14 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)12 Service (io.fabric8.kubernetes.api.model.Service)12 Test (org.testng.annotations.Test)12 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)6 HTTPIngressRuleValue (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue)6 IngressSpec (io.fabric8.kubernetes.api.model.networking.v1.IngressSpec)6 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)5 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)4 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)4 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)4 PreviewUrlImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl)4 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)4 LoadBalancerStatusBuilder (io.fabric8.kubernetes.api.model.LoadBalancerStatusBuilder)2 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)2 ArrayList (java.util.ArrayList)2