Search in sources :

Example 1 with ServiceBackendPortBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder in project che-server by eclipse-che.

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();
}
Also used : IngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder) IngressBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder) HashMap(java.util.HashMap) IngressServiceBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackendBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) HTTPIngressRuleValueBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder) IngressSpecBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressSpecBuilder) HTTPIngressRuleValue(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue) ServiceBackendPortBuilder(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)

Example 2 with ServiceBackendPortBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder 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();
}
Also used : IngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder) IngressBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder) HashMap(java.util.HashMap) IngressServiceBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackendBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) HTTPIngressRuleValueBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder) IngressSpecBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressSpecBuilder) HTTPIngressRuleValue(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue) ServiceBackendPortBuilder(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)

Example 3 with ServiceBackendPortBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder in project ingress-access-operator by neo9.

the class ServiceExposerReconciler method reconcile.

public void reconcile(Service service) {
    String serviceNamespaceAndName = getResourceNamespaceAndName(service);
    log.trace("start working with service {}", serviceNamespaceAndName);
    Ingress oldIngress = ingressRepository.get(service.getMetadata().getNamespace(), service.getMetadata().getName());
    if (nonNull(oldIngress) && !isManagedByOperator(oldIngress)) {
        throw new ResourceNotManagedByOperatorException(getResourceNamespaceAndName(oldIngress));
    }
    String hostname = generateHostname(service);
    log.debug("generating ingress for hostname : {}", hostname);
    Map<String, String> ingressAnnotations = rawBlockToMap(getAnnotationValue(EXPOSE_INGRESS_ADDITIONAL_ANNOTATIONS, service, ""));
    Map<String, String> ingressLabels = rawBlockToMap(getAnnotationValue(EXPOSE_INGRESS_ADDITIONAL_LABELS, service, ""));
    SpecNested<IngressBuilder> ingressBuilderSpecNested = new IngressBuilder().withNewMetadata().withNamespace(service.getMetadata().getNamespace()).withName(service.getMetadata().getName()).addToAnnotations(ingressAnnotations).addToLabels(ingressLabels).addToLabels(MANAGED_BY_OPERATOR_KEY, MANAGED_BY_OPERATOR_VALUE).endMetadata().withNewSpec().withRules(new IngressRuleBuilder().withHost(hostname).withHttp(new HTTPIngressRuleValueBuilder().withPaths(new HTTPIngressPathBuilder().withPath("/").withPathType("Prefix").withBackend(new IngressBackendBuilder().withService(new IngressServiceBackendBuilder().withName(service.getMetadata().getName()).withPort(new ServiceBackendPortBuilder().withNumber(service.getSpec().getPorts().get(0).getPort()).build()).build()).build()).build()).build()).build());
    if (shouldEnableTls(ingressAnnotations)) {
        ingressBuilderSpecNested = ingressBuilderSpecNested.withTls(new IngressTLSBuilder().addToHosts(hostname).withSecretName(String.format("%s-tls", service.getMetadata().getName())).build());
    }
    Ingress ingress = ingressBuilderSpecNested.endSpec().build();
    ingressRepository.createOrReplace(ingress);
    log.trace("end of working with service {}", serviceNamespaceAndName);
}
Also used : IngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder) IngressBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder) ResourceNotManagedByOperatorException(io.neo9.ingress.access.exceptions.ResourceNotManagedByOperatorException) IngressServiceBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackendBuilder) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) HTTPIngressRuleValueBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder) ServiceBackendPortBuilder(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) IngressTLSBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)

Example 4 with ServiceBackendPortBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder 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;
}
Also used : IngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) IngressBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder) HTTPIngressRuleValueBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder) IngressSpecBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressSpecBuilder) IngressServiceBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackendBuilder) ServiceBackendPortBuilder(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder) BridgeIngress(com.redhat.service.smartevents.shard.operator.resources.BridgeIngress) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)

Example 5 with ServiceBackendPortBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder in project keycloak by keycloak.

the class KeycloakIngressE2EIT method testMainIngressDurability.

@Test
public void testMainIngressDurability() {
    var kc = K8sUtils.getDefaultKeycloakDeployment();
    K8sUtils.deployKeycloak(k8sclient, kc, true);
    var ingress = new KeycloakIngress(k8sclient, kc);
    var ingressSelector = k8sclient.network().v1().ingresses().inNamespace(namespace).withName(ingress.getName());
    Log.info("Trying to delete the ingress");
    assertThat(ingressSelector.delete()).isTrue();
    Awaitility.await().untilAsserted(() -> assertThat(ingressSelector.get()).isNotNull());
    // wait for reconciler to calm down to avoid race condititon
    K8sUtils.waitForKeycloakToBeReady(k8sclient, kc);
    Log.info("Trying to modify the ingress");
    var currentIngress = ingressSelector.get();
    var labels = Map.of("address", "EvergreenTerrace742");
    currentIngress.getSpec().getDefaultBackend().getService().setPort(new ServiceBackendPortBuilder().withName("foo").build());
    currentIngress.getMetadata().getAnnotations().clear();
    currentIngress.getMetadata().getLabels().putAll(labels);
    ingressSelector.createOrReplace(currentIngress);
    Awaitility.await().ignoreExceptions().untilAsserted(() -> {
        var i = ingressSelector.get();
        // additional labels should not be overwritten
        assertThat(i.getMetadata().getLabels().entrySet().containsAll(labels.entrySet())).isTrue();
        assertEquals("HTTPS", i.getMetadata().getAnnotations().get("nginx.ingress.kubernetes.io/backend-protocol"));
        assertEquals(Constants.KEYCLOAK_HTTPS_PORT, i.getSpec().getDefaultBackend().getService().getPort().getNumber());
    });
    // Delete the ingress
    kc.getSpec().setDisableDefaultIngress(true);
    K8sUtils.deployKeycloak(k8sclient, kc, true);
    Awaitility.await().untilAsserted(() -> {
        assertThat(k8sclient.network().v1().ingresses().inNamespace(namespace).list().getItems().size()).isEqualTo(0);
    });
}
Also used : KeycloakIngress(org.keycloak.operator.v2alpha1.KeycloakIngress) ServiceBackendPortBuilder(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Aggregations

ServiceBackendPortBuilder (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder)6 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder)5 HTTPIngressRuleValueBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder)5 IngressBackendBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder)5 IngressRuleBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder)5 IngressServiceBackendBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackendBuilder)5 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)4 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)4 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)4 IngressSpec (io.fabric8.kubernetes.api.model.networking.v1.IngressSpec)4 IngressSpecBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressSpecBuilder)4 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)3 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)3 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)2 HTTPIngressRuleValue (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue)2 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)2 HashMap (java.util.HashMap)2 BridgeIngress (com.redhat.service.bridge.shard.operator.resources.BridgeIngress)1 BridgeIngress (com.redhat.service.smartevents.shard.operator.resources.BridgeIngress)1 IngressTLSBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)1