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