use of io.fabric8.kubernetes.api.model.networking.v1.IngressSpec in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class KubernetesNetworkingService method buildIngress.
private Ingress buildIngress(BridgeIngress bridgeIngress, Service service) {
Ingress ingress = templateProvider.loadBridgeIngressKubernetesIngressTemplate(bridgeIngress);
IngressBackend ingressBackend = new IngressBackendBuilder().withService(new IngressServiceBackendBuilder().withName(service.getMetadata().getName()).withPort(new ServiceBackendPortBuilder().withNumber(service.getSpec().getPorts().get(0).getPort()).build()).build()).build();
HTTPIngressPath httpIngressPath = new HTTPIngressPathBuilder().withBackend(ingressBackend).withPath("/" + service.getMetadata().getName() + PATH_REGEX).withPathType("Prefix").build();
IngressRule ingressRule = new IngressRuleBuilder().withHttp(new HTTPIngressRuleValueBuilder().withPaths(httpIngressPath).build()).build();
IngressSpec ingressSpec = new IngressSpecBuilder().withRules(ingressRule).build();
ingress.setSpec(ingressSpec);
return ingress;
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressSpec 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.IngressSpec 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.IngressSpec in project devspaces-images by redhat-developer.
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.IngressSpec in project devspaces-images by redhat-developer.
the class KubernetesPreviewUrlCommandProvisionerTest method shouldUpdateCommandWhenServiceAndIngressFound.
@Test
public void shouldUpdateCommandWhenServiceAndIngressFound() throws InfrastructureException {
final int PORT = 8080;
final String SERVICE_PORT_NAME = "service-" + PORT;
List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap()));
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockNamespace.services()).thenReturn(mockServices);
Service service = new Service();
ObjectMeta metadata = new ObjectMeta();
metadata.setName("servicename");
service.setMetadata(metadata);
ServiceSpec spec = new ServiceSpec();
spec.setPorts(Collections.singletonList(new ServicePort(null, SERVICE_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(spec);
Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));
Ingress ingress = new Ingress();
IngressSpec ingressSpec = new IngressSpec();
IngressRule rule = new IngressRule("testhost", new HTTPIngressRuleValue(Collections.singletonList(new HTTPIngressPath(new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVICE_PORT_NAME, PORT))), null, null))));
ingressSpec.setRules(Collections.singletonList(rule));
ingress.setSpec(ingressSpec);
Mockito.when(mockNamespace.ingresses()).thenReturn(mockIngresses);
Mockito.when(mockIngresses.get()).thenReturn(Collections.singletonList(ingress));
previewUrlCommandProvisioner.provision(env, mockNamespace);
assertTrue(env.getCommands().get(0).getAttributes().containsKey("previewUrl"));
assertEquals(env.getCommands().get(0).getAttributes().get("previewUrl"), "testhost");
assertTrue(env.getWarnings().isEmpty());
}
Aggregations