Search in sources :

Example 1 with Xp7DeploymentSpecNodesPreinstalledApps

use of com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentSpecNodesPreinstalledApps in project xp-operator by enonic.

the class MutationApi method xp7deployment.

private void xp7deployment(MutationRequest mt) {
    // Collect old and new object
    Xp7Deployment oldR = (Xp7Deployment) mt.getAdmissionReview().getRequest().getOldObject();
    Xp7Deployment newR = (Xp7Deployment) mt.getAdmissionReview().getRequest().getObject();
    // Create default status
    Xp7DeploymentStatus defStatus = new Xp7DeploymentStatus().withMessage("Waiting for pods").withState(Xp7DeploymentStatus.State.PENDING).withXp7DeploymentStatusFields(new Xp7DeploymentStatusFields().withXp7DeploymentStatusFieldsPods(new LinkedList<>()));
    if (newR.getSpec() != null && newR.getSpec().getEnabled() != null && !newR.getSpec().getEnabled()) {
        defStatus.setState(Xp7DeploymentStatus.State.STOPPED);
        defStatus.setMessage("XP deployment stopped");
    }
    // Get OP
    AdmissionOperation op = getOperation(mt.getAdmissionReview());
    // Ensure status
    switch(op) {
        case // Always set the default status on new objects
        CREATE:
            patch(mt, true, "/status", newR.getStatus(), defStatus);
            break;
        case UPDATE:
            if (newR.getSpec() != null && !newR.getSpec().equals(oldR.getSpec())) {
                // On any change change, set default status
                patch(mt, true, "/status", newR.getStatus(), defStatus);
            } else {
                // Else make sure the old status is not removed
                patch(mt, false, "/status", newR.getStatus(), oldR.getStatus());
            }
            break;
        case DELETE:
            // Do nothing
            break;
    }
    List<Xp7DeploymentSpecNodesPreinstalledApps> preInstall = newR.getSpec().getNodesPreinstalledApps();
    if (preInstall == null || preInstall.isEmpty()) {
        patch(mt, true, "/spec/nodesPreinstalledApps", newR.getSpec().getNodesPreinstalledApps(), preInstalledApps);
    } else {
        List<String> names = preInstall.stream().map(Xp7DeploymentSpecNodesPreinstalledApps::getName).collect(Collectors.toList());
        List<Xp7DeploymentSpecNodesPreinstalledApps> newList = new LinkedList<>(preInstall);
        preInstalledApps.stream().filter(a -> !names.contains(a.getName())).forEach(newList::add);
        patch(mt, true, "/spec/nodesPreinstalledApps", newR.getSpec().getNodesPreinstalledApps(), newList);
    }
}
Also used : AdmissionOperation(com.enonic.kubernetes.operator.api.AdmissionOperation) LbServiceIpProducer(com.enonic.kubernetes.operator.domain.LbServiceIpProducer) java.util(java.util) Xp7App(com.enonic.kubernetes.client.v1.xp7app.Xp7App) Produces(javax.ws.rs.Produces) Xp7Config(com.enonic.kubernetes.client.v1.xp7config.Xp7Config) Path(javax.ws.rs.Path) DomainStatus(com.enonic.kubernetes.client.v1.domain.DomainStatus) BaseAdmissionApi(com.enonic.kubernetes.operator.api.BaseAdmissionApi) Inject(javax.inject.Inject) DomainStatusFields(com.enonic.kubernetes.client.v1.domain.DomainStatusFields) Xp7Deployment(com.enonic.kubernetes.client.v1.xp7deployment.Xp7Deployment) Consumes(javax.ws.rs.Consumes) Xp7ConfigStatus(com.enonic.kubernetes.client.v1.xp7config.Xp7ConfigStatus) Xp7DeploymentStatusFields(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFields) Utils.createOwnerReference(com.enonic.kubernetes.common.Utils.createOwnerReference) Configuration.cfgStr(com.enonic.kubernetes.common.Configuration.cfgStr) Domain(com.enonic.kubernetes.client.v1.domain.Domain) Predicates.matchAnnotationPrefix(com.enonic.kubernetes.kubernetes.Predicates.matchAnnotationPrefix) Xp7AppStatus(com.enonic.kubernetes.client.v1.xp7app.Xp7AppStatus) POST(javax.ws.rs.POST) BaseEncoding(com.google.common.io.BaseEncoding) Xp7AppStatusFields(com.enonic.kubernetes.client.v1.xp7app.Xp7AppStatusFields) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AdmissionResponseBuilder(io.fabric8.kubernetes.api.model.admission.v1.AdmissionResponseBuilder) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) Xp7DeploymentSpecNodesPreinstalledApps(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentSpecNodesPreinstalledApps) AdmissionReview(io.fabric8.kubernetes.api.model.admission.v1.AdmissionReview) Configuration.cfgBool(com.enonic.kubernetes.common.Configuration.cfgBool) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Configuration.cfgStrChild(com.enonic.kubernetes.common.Configuration.cfgStrChild) Xp7DeploymentStatus(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatus) ApplicationScoped(javax.enterprise.context.ApplicationScoped) AdmissionOperation(com.enonic.kubernetes.operator.api.AdmissionOperation) Xp7Deployment(com.enonic.kubernetes.client.v1.xp7deployment.Xp7Deployment) Xp7DeploymentSpecNodesPreinstalledApps(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentSpecNodesPreinstalledApps) Xp7DeploymentStatus(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatus) Xp7DeploymentStatusFields(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFields)

Aggregations

Domain (com.enonic.kubernetes.client.v1.domain.Domain)1 DomainStatus (com.enonic.kubernetes.client.v1.domain.DomainStatus)1 DomainStatusFields (com.enonic.kubernetes.client.v1.domain.DomainStatusFields)1 Xp7App (com.enonic.kubernetes.client.v1.xp7app.Xp7App)1 Xp7AppStatus (com.enonic.kubernetes.client.v1.xp7app.Xp7AppStatus)1 Xp7AppStatusFields (com.enonic.kubernetes.client.v1.xp7app.Xp7AppStatusFields)1 Xp7Config (com.enonic.kubernetes.client.v1.xp7config.Xp7Config)1 Xp7ConfigStatus (com.enonic.kubernetes.client.v1.xp7config.Xp7ConfigStatus)1 Xp7Deployment (com.enonic.kubernetes.client.v1.xp7deployment.Xp7Deployment)1 Xp7DeploymentSpecNodesPreinstalledApps (com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentSpecNodesPreinstalledApps)1 Xp7DeploymentStatus (com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatus)1 Xp7DeploymentStatusFields (com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFields)1 Configuration.cfgBool (com.enonic.kubernetes.common.Configuration.cfgBool)1 Configuration.cfgStr (com.enonic.kubernetes.common.Configuration.cfgStr)1 Configuration.cfgStrChild (com.enonic.kubernetes.common.Configuration.cfgStrChild)1 Utils.createOwnerReference (com.enonic.kubernetes.common.Utils.createOwnerReference)1 Predicates.matchAnnotationPrefix (com.enonic.kubernetes.kubernetes.Predicates.matchAnnotationPrefix)1 AdmissionOperation (com.enonic.kubernetes.operator.api.AdmissionOperation)1 BaseAdmissionApi (com.enonic.kubernetes.operator.api.BaseAdmissionApi)1 LbServiceIpProducer (com.enonic.kubernetes.operator.domain.LbServiceIpProducer)1