Search in sources :

Example 1 with ResourceNotManagedByOperatorException

use of io.neo9.ingress.access.exceptions.ResourceNotManagedByOperatorException 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 2 with ResourceNotManagedByOperatorException

use of io.neo9.ingress.access.exceptions.ResourceNotManagedByOperatorException 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 3 with ResourceNotManagedByOperatorException

use of io.neo9.ingress.access.exceptions.ResourceNotManagedByOperatorException in project ingress-access-operator by neo9.

the class IstioSidecarReconciler method reconcile.

public void reconcile() {
    Sidecar oldSidecar = sidecarRepository.getSidecar(additionalWatchersConfig.updateIstioIngressSidecar().getIngressNamespace(), SIDECAR_NAME);
    if (nonNull(oldSidecar) && !isManagedByOperator(oldSidecar)) {
        throw new ResourceNotManagedByOperatorException(getResourceNamespaceAndName(oldSidecar));
    }
    List<Namespace> namespacesWatchedByIstio = namespaceRepository.listNamespacesWithLabel(ISTIO_WATCH_NAMESPACE_LABEL_KEY, ISTIO_WATCH_NAMESPACE_LABEL_VALUE);
    List<String> namespaceForSidecar = Stream.concat(additionalWatchersConfig.updateIstioIngressSidecar().getAdditionalEgressRulesEntries().stream(), namespacesWatchedByIstio.stream().map(namespace -> namespace.getMetadata().getName())).map(s -> String.format("%s/*", s)).distinct().collect(Collectors.toList());
    log.trace("computed namespace list : {}", namespaceForSidecar);
    Sidecar sidecar = new Sidecar();
    sidecar.getMetadata().setNamespace(additionalWatchersConfig.updateIstioIngressSidecar().getIngressNamespace());
    sidecar.getMetadata().setName(SIDECAR_NAME);
    sidecar.getMetadata().setLabels(Map.of(MANAGED_BY_OPERATOR_KEY, MANAGED_BY_OPERATOR_VALUE));
    EgressSpec egressSpec = new EgressSpec(namespaceForSidecar);
    SidecarSpec sidecarSpec = new SidecarSpec();
    sidecarSpec.setEgress(List.of(egressSpec));
    sidecar.setSpec(sidecarSpec);
    sidecarRepository.createOrReplace(sidecar);
}
Also used : ResourceNotManagedByOperatorException(io.neo9.ingress.access.exceptions.ResourceNotManagedByOperatorException) EgressSpec(io.neo9.ingress.access.customresources.external.istio.spec.EgressSpec) SidecarSpec(io.neo9.ingress.access.customresources.external.istio.spec.SidecarSpec) Namespace(io.fabric8.kubernetes.api.model.Namespace) Sidecar(io.neo9.ingress.access.customresources.external.istio.Sidecar)

Aggregations

ResourceNotManagedByOperatorException (io.neo9.ingress.access.exceptions.ResourceNotManagedByOperatorException)3 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)2 Namespace (io.fabric8.kubernetes.api.model.Namespace)1 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder)1 HTTPIngressRuleValueBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder)1 IngressBackendBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder)1 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)1 IngressRuleBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder)1 IngressServiceBackendBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackendBuilder)1 IngressTLSBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)1 ServiceBackendPortBuilder (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder)1 Sidecar (io.neo9.ingress.access.customresources.external.istio.Sidecar)1 EgressSpec (io.neo9.ingress.access.customresources.external.istio.spec.EgressSpec)1 SidecarSpec (io.neo9.ingress.access.customresources.external.istio.spec.SidecarSpec)1