use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project che-server by eclipse-che.
the class PreviewUrlExposerTest method shouldNotProvisionWhenServiceAndIngressFound.
@Test
public void shouldNotProvisionWhenServiceAndIngressFound() throws InternalInfrastructureException {
final int PORT = 8080;
final String SERVER_PORT_NAME = "server-" + PORT;
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
Service service = new Service();
ObjectMeta serviceMeta = new ObjectMeta();
serviceMeta.setName("servicename");
service.setMetadata(serviceMeta);
ServiceSpec serviceSpec = new ServiceSpec();
serviceSpec.setPorts(singletonList(new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(serviceSpec);
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");
IngressBackend ingressBackend = new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVER_PORT_NAME, PORT)));
ingressRule.setHttp(new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(ingressBackend, null, null))));
ingressSpec.setRules(singletonList(ingressRule));
ingress.setSpec(ingressSpec);
Map<String, Service> services = new HashMap<>();
services.put("servicename", service);
Map<String, Ingress> ingresses = new HashMap<>();
ingresses.put("ingressname", ingress);
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setIngresses(ingresses).build();
assertEquals(env.getIngresses().size(), 1);
previewUrlExposer.expose(env);
assertEquals(env.getIngresses().size(), 1);
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project che-server by eclipse-che.
the class PreviewUrlExposerTest method shouldProvisionIngressWhenNotFound.
@Test
public void shouldProvisionIngressWhenNotFound() 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;
final String SERVICE_NAME = "servicename";
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
Service service = new Service();
ObjectMeta serviceMeta = new ObjectMeta();
serviceMeta.setName(SERVICE_NAME);
service.setMetadata(serviceMeta);
ServiceSpec serviceSpec = new ServiceSpec();
serviceSpec.setPorts(singletonList(new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(serviceSpec);
Map<String, Service> services = new HashMap<>();
services.put(SERVICE_NAME, service);
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setIngresses(new HashMap<>()).build();
previewUrlExposer.expose(env);
assertEquals(env.getIngresses().size(), 1);
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(), SERVICE_NAME);
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project che-server by eclipse-che.
the class DefaultHostExternalServiceExposureStrategyTest method assertThatExternalServerIsExposed.
@SuppressWarnings("SameParameterValue")
private void assertThatExternalServerIsExposed(String machineName, String serviceName, String serverNameRegex, ServicePort servicePort, ServerConfigImpl expected) {
// ensure that required ingress is created
for (Ingress ingress : kubernetesEnvironment.getIngresses().values()) {
IngressRule ingressRule = ingress.getSpec().getRules().get(0);
IngressBackend backend = ingressRule.getHttp().getPaths().get(0).getBackend();
if (serviceName.equals(backend.getService().getName())) {
assertEquals(backend.getService().getPort().getName(), servicePort.getName());
Annotations.Deserializer ingressAnnotations = Annotations.newDeserializer(ingress.getMetadata().getAnnotations());
Map<String, ServerConfigImpl> servers = ingressAnnotations.servers();
ServerConfig serverConfig = servers.get(serverNameRegex);
if (serverConfig == null) {
// ok, this ingress is not for this particular server
continue;
}
assertEquals(serverConfig, expected);
assertEquals(ingressAnnotations.machineName(), machineName);
return;
}
}
Assert.fail(format("Could not find an ingress for machine '%s' and service '%s'", machineName, serviceName));
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project devspaces-images by redhat-developer.
the class ExternalServerIngressBuilder method build.
public Ingress build() {
ServiceBackendPortBuilder serviceBackendPortBuilder = new ServiceBackendPortBuilder();
// cannot set both port and name
if (!isNullOrEmpty(servicePortName)) {
serviceBackendPortBuilder.withName(servicePortName);
} else if (servicePort != null) {
serviceBackendPortBuilder.withNumber(servicePort);
}
IngressServiceBackend ingressServiceBackend = new IngressServiceBackendBuilder().withPort(serviceBackendPortBuilder.build()).withName(serviceName).build();
IngressBackend ingressBackend = new IngressBackendBuilder().withService(ingressServiceBackend).build();
HTTPIngressPathBuilder httpIngressPathBuilder = new HTTPIngressPathBuilder().withBackend(ingressBackend).withPathType(INGRESS_PATH_TYPE);
if (!isNullOrEmpty(path)) {
httpIngressPathBuilder.withPath(path);
}
HTTPIngressPath httpIngressPath = httpIngressPathBuilder.build();
HTTPIngressRuleValue httpIngressRuleValue = new HTTPIngressRuleValueBuilder().withPaths(httpIngressPath).build();
IngressRuleBuilder ingressRuleBuilder = new IngressRuleBuilder().withHttp(httpIngressRuleValue);
if (!isNullOrEmpty(host)) {
ingressRuleBuilder.withHost(host);
}
IngressRule ingressRule = ingressRuleBuilder.build();
IngressSpec ingressSpec = new IngressSpecBuilder().withRules(ingressRule).build();
Map<String, String> ingressAnnotations = new HashMap<>(annotations);
ingressAnnotations.putAll(Annotations.newSerializer().servers(serversConfigs).machineName(machineName).annotations());
return new IngressBuilder().withSpec(ingressSpec).withMetadata(new ObjectMetaBuilder().withName(name).withAnnotations(ingressAnnotations).withLabels(labels).build()).build();
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project devspaces-images by redhat-developer.
the class PreviewUrlExposerTest method shouldNotProvisionWhenServiceAndIngressFound.
@Test
public void shouldNotProvisionWhenServiceAndIngressFound() throws InternalInfrastructureException {
final int PORT = 8080;
final String SERVER_PORT_NAME = "server-" + PORT;
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
Service service = new Service();
ObjectMeta serviceMeta = new ObjectMeta();
serviceMeta.setName("servicename");
service.setMetadata(serviceMeta);
ServiceSpec serviceSpec = new ServiceSpec();
serviceSpec.setPorts(singletonList(new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(serviceSpec);
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");
IngressBackend ingressBackend = new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVER_PORT_NAME, PORT)));
ingressRule.setHttp(new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(ingressBackend, null, null))));
ingressSpec.setRules(singletonList(ingressRule));
ingress.setSpec(ingressSpec);
Map<String, Service> services = new HashMap<>();
services.put("servicename", service);
Map<String, Ingress> ingresses = new HashMap<>();
ingresses.put("ingressname", ingress);
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setIngresses(ingresses).build();
assertEquals(env.getIngresses().size(), 1);
previewUrlExposer.expose(env);
assertEquals(env.getIngresses().size(), 1);
}
Aggregations