Search in sources :

Example 41 with IngressRule

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

use of io.fabric8.kubernetes.api.model.networking.v1.IngressRule 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());
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArrayList(java.util.ArrayList) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) 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) HTTPIngressRuleValue(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend) Test(org.testng.annotations.Test)

Example 43 with IngressRule

use of io.fabric8.kubernetes.api.model.networking.v1.IngressRule in project devspaces-images by redhat-developer.

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;
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) HTTPIngressRuleValue(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)

Example 44 with IngressRule

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

use of io.fabric8.kubernetes.api.model.networking.v1.IngressRule in project flink-kubernetes-operator by apache.

the class IngressUtils method updateIngressRules.

public static void updateIngressRules(FlinkDeployment flinkDeployment, Configuration effectiveConfig, String operatorNamespace, KubernetesClient client, boolean remove) {
    if (flinkDeployment.getSpec().getIngressDomain() != null) {
        final IngressRule ingressRule = fromDeployment(flinkDeployment, effectiveConfig);
        getIngress(operatorNamespace, client).ifPresent(ingress -> {
            Ingress updated;
            if (remove) {
                updated = new IngressBuilder(ingress).editSpec().removeFromRules(ingressRule).endSpec().build();
            } else {
                updated = new IngressBuilder(ingress).editSpec().addToRules(ingressRule).endSpec().build();
            }
            LOG.info("Updating ingress rules {}", ingress);
            client.resourceList(updated).inNamespace(operatorNamespace).createOrReplace();
        });
    }
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress)

Aggregations

IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)39 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)37 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)24 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)19 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)19 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)19 Service (io.fabric8.kubernetes.api.model.Service)17 ServiceBackendPort (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort)16 IngressSpec (io.fabric8.kubernetes.api.model.networking.v1.IngressSpec)14 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder)12 Test (org.testng.annotations.Test)12 HTTPIngressRuleValue (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue)11 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)10 IngressRuleBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder)10 ArrayList (java.util.ArrayList)10 IngressTLSBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)9 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)8 GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)8 HTTPIngressRuleValueBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder)7 Annotations (org.eclipse.che.workspace.infrastructure.kubernetes.Annotations)6