use of io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend in project devspaces-images by redhat-developer.
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();
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend 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());
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend in project devspaces-images by redhat-developer.
the class IngressesTest method findHostWhenPortDefinedByString.
@Test
public void findHostWhenPortDefinedByString() {
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");
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend in project quick by bakdata.
the class GatewayResourceLoaderTest method shouldCreateGatewayIngress.
@Test
void shouldCreateGatewayIngress() {
final GatewayCreationData gatewayCreationData = new GatewayCreationData(GATEWAY_NAME, REPLICAS, TAG, null);
final GatewayResources gatewayResources = this.loader.forCreation(gatewayCreationData, ResourcePrefix.GATEWAY);
final Optional<HasMetadata> hasMetadata = findResource(gatewayResources, ResourceKind.INGRESS);
final String expected = ResourcePrefix.GATEWAY.getPrefix() + GATEWAY_NAME;
assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(Ingress.class)).satisfies(gatewayIngress -> {
assertThat(gatewayIngress.getMetadata()).hasFieldOrPropertyWithValue("name", expected).extracting(ObjectMeta::getAnnotations, MAP).containsExactlyInAnyOrderEntriesOf(Map.of("kubernetes.io/ingress.class", "traefik", "traefik.ingress.kubernetes.io/router.middlewares", String.format("%s-%s@kubernetescrd", "test", expected), "traefik.ingress.kubernetes.io/router.entrypoints", "websecure", "traefik.ingress.kubernetes.io/router.tls", "true"));
final IngressSpec ingressSpec = gatewayIngress.getSpec();
assertThat(ingressSpec).isNotNull();
assertThat(ingressSpec.getRules()).isNotNull().hasSize(1).first().satisfies(rule -> assertThat(rule.getHost()).isEqualTo("quick.host.io")).extracting(IngressRule::getHttp).isNotNull().extracting(HTTPIngressRuleValue::getPaths, InstanceOfAssertFactories.list(HTTPIngressPath.class)).isNotNull().hasSize(1).first().hasFieldOrPropertyWithValue("path", "/gateway/" + GATEWAY_NAME).hasFieldOrPropertyWithValue("pathType", "Prefix").extracting(path -> path.getBackend().getService()).isNotNull().hasFieldOrPropertyWithValue("name", expected).extracting(IngressServiceBackend::getPort).hasFieldOrPropertyWithValue("number", KubernetesResources.SERVICE_PORT);
});
}
Aggregations