Search in sources :

Example 1 with IngressBuilder

use of io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder in project fabric8-maven-plugin by fabric8io.

the class IngressEnricher method addIngress.

private void addIngress(KubernetesListBuilder listBuilder, ServiceBuilder serviceBuilder) {
    ObjectMeta serviceMetadata = serviceBuilder.getMetadata();
    if (serviceMetadata != null && isExposedService(serviceMetadata) && shouldCreateExternalURLForService(serviceBuilder)) {
        String serviceName = serviceMetadata.getName();
        if (!hasIngress(listBuilder, serviceName)) {
            Integer servicePort = getServicePort(serviceBuilder);
            if (servicePort != null) {
                IngressBuilder ingressBuilder = new IngressBuilder().withMetadata(serviceMetadata).withNewSpec().endSpec();
                // removing `expose : true` label from metadata.
                ingressBuilder.withNewMetadataLike(removeExposeLabel(ingressBuilder.getMetadata()));
                if (StringUtils.isNotBlank(routeDomainPostfix)) {
                    routeDomainPostfix = serviceName + "." + FileUtil.stripPrefix(routeDomainPostfix, ".");
                    ingressBuilder = ingressBuilder.withSpec(new IngressSpecBuilder().addNewRule().withHost(routeDomainPostfix).withNewHttp().withPaths(new HTTPIngressPathBuilder().withNewBackend().withServiceName(serviceName).withServicePort(KubernetesHelper.createIntOrString(getServicePort(serviceBuilder))).endBackend().build()).endHttp().endRule().build());
                } else {
                    ingressBuilder.withSpec(new IngressSpecBuilder().withBackend(new IngressBackendBuilder().withNewServiceName(serviceName).withNewServicePort(getServicePort(serviceBuilder)).build()).build());
                }
                listBuilder.addToItems(ingressBuilder.build());
            }
        }
    }
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) IngressBuilder(io.fabric8.kubernetes.api.model.extensions.IngressBuilder) IngressBackendBuilder(io.fabric8.kubernetes.api.model.extensions.IngressBackendBuilder) IngressSpecBuilder(io.fabric8.kubernetes.api.model.extensions.IngressSpecBuilder) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.extensions.HTTPIngressPathBuilder)

Example 2 with IngressBuilder

use of io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder 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 3 with IngressBuilder

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

the class KubernetesEnvironmentFactoryTest method ignoreIgressesWhenRecipeContainsThem.

@Test
public void ignoreIgressesWhenRecipeContainsThem() throws Exception {
    when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(new IngressBuilder().withNewMetadata().withName("ingress1").endMetadata().build(), new IngressBuilder().withNewMetadata().withName("ingress2").endMetadata().build()));
    final KubernetesEnvironment parsed = k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
    assertTrue(parsed.getIngresses().isEmpty());
    assertEquals(parsed.getWarnings().size(), 1);
    assertEquals(parsed.getWarnings().get(0), new WarningImpl(INGRESSES_IGNORED_WARNING_CODE, INGRESSES_IGNORED_WARNING_MESSAGE));
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) InternalRecipe(org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) Test(org.testng.annotations.Test)

Example 4 with IngressBuilder

use of io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder 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 5 with IngressBuilder

use of io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder in project kubernetes-client by fabric8io.

the class KubernetesAttributesExtractorTest method shouldHandleIngress.

@Test
void shouldHandleIngress() {
    KubernetesAttributesExtractor extractor = new KubernetesAttributesExtractor();
    extractor.extract(new IngressBuilder().withNewMetadata().endMetadata().build());
    AttributeSet attributes = extractor.fromPath("/apis/extensions/v1beta1/namespaces/myns/ingresses/myingress");
    AttributeSet expected = new AttributeSet();
    expected = expected.add(new Attribute("plural", "ingresses"));
    expected = expected.add(new Attribute("namespace", "myns"));
    expected = expected.add(new Attribute("name", "myingress"));
    assertTrue(attributes.matches(expected));
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.extensions.IngressBuilder) AttributeSet(io.fabric8.mockwebserver.crud.AttributeSet) Attribute(io.fabric8.mockwebserver.crud.Attribute) Test(org.junit.jupiter.api.Test)

Aggregations

IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)39 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)31 Test (org.junit.jupiter.api.Test)28 IngressBuilder (io.fabric8.kubernetes.api.model.extensions.IngressBuilder)13 ArrayList (java.util.ArrayList)13 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)11 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder)11 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)9 IngressTLSBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)9 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)8 GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)8 Test (org.junit.Test)8 IngressRuleBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder)7 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder)6 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)5 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)5 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.extensions.HTTPIngressPathBuilder)5 Ingress (io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress)5 HashMap (java.util.HashMap)5 HTTPIngressPath (io.fabric8.kubernetes.api.model.extensions.HTTPIngressPath)4