Search in sources :

Example 1 with Mapping

use of com.enonic.kubernetes.operator.ingress.Mapping in project xp-operator by enonic.

the class AdmissionApi method ingress.

private void ingress(AdmissionReview admissionReview) {
    AdmissionOperation op = getOperation(admissionReview);
    if (op == AdmissionOperation.DELETE) {
        return;
    }
    Ingress newIngress = (Ingress) admissionReview.getRequest().getObject();
    if (matchAnnotationPrefix(cfgStr("operator.charts.values.annotationKeys.vhostMapping")).negate().test(newIngress)) {
        return;
    }
    Set<Mapping> mappings = getAnnotationMappings(newIngress);
    Preconditions.checkArgument(!mappings.isEmpty(), "malformed 'enonic.cloud/xp7.vhost.mapping' annotations");
    for (Mapping m : mappings) {
        List<String> paths = newIngress.getSpec().getRules().stream().map(r -> r.getHttp().getPaths().stream().filter(p -> p.getBackend().getService().getPort().getNumber() == 8080).map(HTTPIngressPath::getPath).collect(Collectors.toList())).flatMap(Collection::stream).collect(Collectors.toList());
        Preconditions.checkArgument(paths.contains(m.source()), String.format("source '%s' in 'enonic.cloud/xp7.vhost.mapping' annotation not defined in ingress rules on host %s, port 8080", m.source(), m.host()));
    }
}
Also used : AdmissionOperation(com.enonic.kubernetes.operator.api.AdmissionOperation) Mapping(com.enonic.kubernetes.operator.ingress.Mapping) Xp7App(com.enonic.kubernetes.client.v1.xp7app.Xp7App) Produces(javax.ws.rs.Produces) Predicates.inNodeGroupAllOr(com.enonic.kubernetes.kubernetes.Predicates.inNodeGroupAllOr) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) Xp7Config(com.enonic.kubernetes.client.v1.xp7config.Xp7Config) Path(javax.ws.rs.Path) Xp7DeploymentSpecNodeGroup(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentSpecNodeGroup) BaseAdmissionApi(com.enonic.kubernetes.operator.api.BaseAdmissionApi) HashSet(java.util.HashSet) Matcher(java.util.regex.Matcher) Xp7Deployment(com.enonic.kubernetes.client.v1.xp7deployment.Xp7Deployment) Consumes(javax.ws.rs.Consumes) Configuration.cfgStr(com.enonic.kubernetes.common.Configuration.cfgStr) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) Configuration.cfgIfBool(com.enonic.kubernetes.common.Configuration.cfgIfBool) Domain(com.enonic.kubernetes.client.v1.domain.Domain) Predicates.matchAnnotationPrefix(com.enonic.kubernetes.kubernetes.Predicates.matchAnnotationPrefix) POST(javax.ws.rs.POST) Predicates.inSameNamespaceAs(com.enonic.kubernetes.kubernetes.Predicates.inSameNamespaceAs) Predicates.fieldEquals(com.enonic.kubernetes.kubernetes.Predicates.fieldEquals) OperatorXp7ConfigSync.getAnnotationMappings(com.enonic.kubernetes.operator.ingress.OperatorXp7ConfigSync.getAnnotationMappings) Collection(java.util.Collection) Predicates.withName(com.enonic.kubernetes.kubernetes.Predicates.withName) Set(java.util.Set) Validator.dns1123(com.enonic.kubernetes.common.Validator.dns1123) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Predicates.isBeingBackupRestored(com.enonic.kubernetes.kubernetes.Predicates.isBeingBackupRestored) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) Validator(com.enonic.kubernetes.common.Validator) List(java.util.List) AdmissionReview(io.fabric8.kubernetes.api.model.admission.v1.AdmissionReview) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Pattern(java.util.regex.Pattern) AdmissionOperation(com.enonic.kubernetes.operator.api.AdmissionOperation) Collections(java.util.Collections) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Mapping(com.enonic.kubernetes.operator.ingress.Mapping) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)

Aggregations

Domain (com.enonic.kubernetes.client.v1.domain.Domain)1 Xp7App (com.enonic.kubernetes.client.v1.xp7app.Xp7App)1 Xp7Config (com.enonic.kubernetes.client.v1.xp7config.Xp7Config)1 Xp7Deployment (com.enonic.kubernetes.client.v1.xp7deployment.Xp7Deployment)1 Xp7DeploymentSpecNodeGroup (com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentSpecNodeGroup)1 Configuration.cfgIfBool (com.enonic.kubernetes.common.Configuration.cfgIfBool)1 Configuration.cfgStr (com.enonic.kubernetes.common.Configuration.cfgStr)1 Validator (com.enonic.kubernetes.common.Validator)1 Validator.dns1123 (com.enonic.kubernetes.common.Validator.dns1123)1 Predicates.fieldEquals (com.enonic.kubernetes.kubernetes.Predicates.fieldEquals)1 Predicates.inNodeGroupAllOr (com.enonic.kubernetes.kubernetes.Predicates.inNodeGroupAllOr)1 Predicates.inSameNamespaceAs (com.enonic.kubernetes.kubernetes.Predicates.inSameNamespaceAs)1 Predicates.isBeingBackupRestored (com.enonic.kubernetes.kubernetes.Predicates.isBeingBackupRestored)1 Predicates.matchAnnotationPrefix (com.enonic.kubernetes.kubernetes.Predicates.matchAnnotationPrefix)1 Predicates.withName (com.enonic.kubernetes.kubernetes.Predicates.withName)1 AdmissionOperation (com.enonic.kubernetes.operator.api.AdmissionOperation)1 BaseAdmissionApi (com.enonic.kubernetes.operator.api.BaseAdmissionApi)1 Mapping (com.enonic.kubernetes.operator.ingress.Mapping)1 OperatorXp7ConfigSync.getAnnotationMappings (com.enonic.kubernetes.operator.ingress.OperatorXp7ConfigSync.getAnnotationMappings)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1