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);
}
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);
}
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);
}
Aggregations