Search in sources :

Example 11 with IngressBuilder

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

the class IngressTest method testDeleteWithNamespaceMismatch.

@Test
public void testDeleteWithNamespaceMismatch() {
    Ingress ingress1 = new IngressBuilder().withNewMetadata().withName("ingress1").withNamespace("test").and().build();
    Boolean deleted = client.extensions().ingress().inNamespace("test1").delete(ingress1);
    assertFalse(deleted);
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.extensions.IngressBuilder) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) Test(org.junit.jupiter.api.Test)

Example 12 with IngressBuilder

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

the class IngressTest method testCreateWithNameMismatch.

@Test
public void testCreateWithNameMismatch() {
    Assertions.assertThrows(KubernetesClientException.class, () -> {
        Ingress ingress1 = new IngressBuilder().withNewMetadata().withName("ingress1").withNamespace("test").and().build();
        Ingress ingress2 = new IngressBuilder().withNewMetadata().withName("ingress2").withNamespace("ns1").and().build();
        client.extensions().ingress().inNamespace("test1").withName("myingress1").create(ingress1);
    });
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.extensions.IngressBuilder) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) Test(org.junit.jupiter.api.Test)

Example 13 with IngressBuilder

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

the class IngressTest method testDeleteMulti.

@Test
public void testDeleteMulti() {
    Ingress ingress1 = new IngressBuilder().withNewMetadata().withName("ingress1").withNamespace("test").and().build();
    Ingress ingress2 = new IngressBuilder().withNewMetadata().withName("ingress2").withNamespace("ns1").and().build();
    Ingress ingress3 = new IngressBuilder().withNewMetadata().withName("ingress3").withNamespace("any").and().build();
    server.expect().withPath("/apis/extensions/v1beta1/namespaces/test/ingresses/ingress1").andReturn(200, ingress1).once();
    server.expect().withPath("/apis/extensions/v1beta1/namespaces/ns1/ingresses/ingress2").andReturn(200, ingress2).once();
    Boolean deleted = client.extensions().ingress().inAnyNamespace().delete(ingress1, ingress2);
    assertTrue(deleted);
    deleted = client.extensions().ingress().inAnyNamespace().delete(ingress3);
    assertFalse(deleted);
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.extensions.IngressBuilder) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) Test(org.junit.jupiter.api.Test)

Example 14 with IngressBuilder

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

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

the class ServiceExposerReconcilerTest method shouldNotEnableTlsIfAnnotationIsDetected.

@Test
public void shouldNotEnableTlsIfAnnotationIsDetected() {
    // given
    Ingress ingress = new IngressBuilder().withNewMetadata().withNamespace("mynamespace").withName("myname").addToAnnotations(EXPOSE_INGRESS_HOSTNAME, "hello.{{domain}}").addToAnnotations("cert-manager.io/cluster-issuer", "my-issuer").endMetadata().build();
    // when
    boolean shouldEnableTls = serviceExposerReconciler.shouldEnableTls(ingress.getMetadata().getAnnotations());
    // then
    assertThat(shouldEnableTls).isTrue();
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) 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