Search in sources :

Example 41 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project kubernetes-client by fabric8io.

the class NetworkingV1beta1IngressTest method testCreateOrReplaceWhenAnnotationUpdated.

@Test
void testCreateOrReplaceWhenAnnotationUpdated() {
    // Given
    Ingress ingressFromServer = new IngressBuilder().withNewMetadata().withName("ing1").endMetadata().build();
    Ingress ingressUpdated = new IngressBuilder(ingressFromServer).editOrNewMetadata().addToAnnotations("nginx.ingress.kubernetes.io/rewrite-target", "/").endMetadata().build();
    server.expect().post().withPath("/apis/networking.k8s.io/v1beta1/namespaces/ns1/ingresses").andReturn(HttpURLConnection.HTTP_CONFLICT, ingressFromServer).once();
    server.expect().get().withPath("/apis/networking.k8s.io/v1beta1/namespaces/ns1/ingresses/ing1").andReturn(HttpURLConnection.HTTP_OK, ingressFromServer).times(2);
    server.expect().put().withPath("/apis/networking.k8s.io/v1beta1/namespaces/ns1/ingresses/ing1").andReturn(HttpURLConnection.HTTP_OK, ingressUpdated).once();
    // When
    ingressUpdated = client.network().ingresses().inNamespace("ns1").createOrReplace(ingressUpdated);
    // Then
    assertNotNull(ingressUpdated);
    assertNotNull(ingressUpdated.getMetadata());
    assertTrue(ingressUpdated.getMetadata().getAnnotations().containsKey("nginx.ingress.kubernetes.io/rewrite-target"));
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder) Ingress(io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress) Test(org.junit.jupiter.api.Test)

Example 42 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project kubernetes-client by fabric8io.

the class NetworkingV1beta1IngressTest method testGet.

@Test
void testGet() {
    server.expect().withPath("/apis/networking.k8s.io/v1beta1/namespaces/test/ingresses/ingress1").andReturn(200, new IngressBuilder().build()).once();
    server.expect().withPath("/apis/networking.k8s.io/v1beta1/namespaces/ns1/ingresses/ingress2").andReturn(200, new IngressBuilder().build()).once();
    Ingress ingress = client.network().ingress().withName("ingress1").get();
    assertNotNull(ingress);
    ingress = client.network().ingress().withName("ingress2").get();
    assertNull(ingress);
    ingress = client.network().ingress().inNamespace("ns1").withName("ingress2").get();
    assertNotNull(ingress);
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder) Ingress(io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress) Test(org.junit.jupiter.api.Test)

Example 43 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project ingress-access-operator by neo9.

the class ServiceExposerReconciler method reconcileOnDelete.

public void reconcileOnDelete(Service service) {
    String serviceNamespaceAndName = getResourceNamespaceAndName(service);
    log.trace("start working with deleted service {}", serviceNamespaceAndName);
    Ingress oldIngress = ingressRepository.get(service.getMetadata().getNamespace(), service.getMetadata().getName());
    if (nonNull(oldIngress) && !isManagedByOperator(oldIngress)) {
        throw new ResourceNotManagedByOperatorException(getResourceNamespaceAndName(oldIngress));
    }
    if (nonNull(oldIngress)) {
        log.info("deleting ingress {} due to service deletion {}", getResourceNamespaceAndName(oldIngress), serviceNamespaceAndName);
        ingressRepository.delete(oldIngress.getMetadata().getNamespace(), oldIngress.getMetadata().getName());
    }
    log.trace("end of working with deleted service {}", serviceNamespaceAndName);
}
Also used : ResourceNotManagedByOperatorException(io.neo9.ingress.access.exceptions.ResourceNotManagedByOperatorException) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress)

Example 44 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress 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 45 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress 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

Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)158 Service (io.fabric8.kubernetes.api.model.Service)47 Test (org.junit.jupiter.api.Test)42 Test (org.testng.annotations.Test)36 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)31 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)28 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)25 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)24 ArrayList (java.util.ArrayList)22 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)21 HashMap (java.util.HashMap)21 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)16 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)16 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)14 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)14 ServiceBackendPort (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort)14 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)14 KafkaCluster (io.strimzi.operator.cluster.model.KafkaCluster)14 Reconciliation (io.strimzi.operator.common.Reconciliation)14 IngressOperator (io.strimzi.operator.common.operator.resource.IngressOperator)14