Search in sources :

Example 1 with Xp7DeploymentStatusFields

use of com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFields 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)

Example 2 with Xp7DeploymentStatusFields

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

the class OperatorXp7DeploymentStatus method buildFields.

private Xp7DeploymentStatusFields buildFields(final List<Pod> pods) {
    List<Xp7DeploymentStatusFieldsPod> fieldPods = new LinkedList<>();
    for (Pod pod : pods) {
        Optional<ContainerStatus> cs = pod.getStatus().getContainerStatuses().stream().filter(s -> s.getName().equals("exp")).findFirst();
        fieldPods.add(new Xp7DeploymentStatusFieldsPod().withName(pod.getMetadata().getName()).withReady(cs.isPresent() && cs.get().getReady()).withPhase(pod.getStatus().getPhase()));
    }
    return new Xp7DeploymentStatusFields().withXp7DeploymentStatusFieldsPods(fieldPods);
}
Also used : Xp7DeploymentStatusFieldsPod(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFieldsPod) Clients(com.enonic.kubernetes.kubernetes.Clients) Predicates.inSameNamespaceAs(com.enonic.kubernetes.kubernetes.Predicates.inSameNamespaceAs) Xp7DeploymentSpecNodeGroup(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentSpecNodeGroup) Searchers(com.enonic.kubernetes.kubernetes.Searchers) Pod(io.fabric8.kubernetes.api.model.Pod) Xp7DeploymentStatusFieldsPod(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFieldsPod) Predicates.isEnonicManaged(com.enonic.kubernetes.kubernetes.Predicates.isEnonicManaged) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) List(java.util.List) Predicates.onCondition(com.enonic.kubernetes.kubernetes.Predicates.onCondition) Xp7Deployment(com.enonic.kubernetes.client.v1.xp7deployment.Xp7Deployment) Informers(com.enonic.kubernetes.kubernetes.Informers) K8sLogHelper(com.enonic.kubernetes.kubernetes.commands.K8sLogHelper) Xp7DeploymentStatusFields(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFields) Observes(javax.enterprise.event.Observes) InformerEventHandler(com.enonic.kubernetes.operator.helpers.InformerEventHandler) Optional(java.util.Optional) Xp7DeploymentStatus(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatus) ContainerStatus(io.fabric8.kubernetes.api.model.ContainerStatus) ApplicationScoped(javax.enterprise.context.ApplicationScoped) StartupEvent(io.quarkus.runtime.StartupEvent) LinkedList(java.util.LinkedList) Predicates.isPartOfDeployment(com.enonic.kubernetes.kubernetes.Predicates.isPartOfDeployment) ContainerStatus(io.fabric8.kubernetes.api.model.ContainerStatus) Pod(io.fabric8.kubernetes.api.model.Pod) Xp7DeploymentStatusFieldsPod(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFieldsPod) LinkedList(java.util.LinkedList) Xp7DeploymentStatusFields(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFields)

Aggregations

Xp7Deployment (com.enonic.kubernetes.client.v1.xp7deployment.Xp7Deployment)2 Xp7DeploymentStatus (com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatus)2 Xp7DeploymentStatusFields (com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFields)2 Collectors (java.util.stream.Collectors)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Inject (javax.inject.Inject)2 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 Xp7DeploymentSpecNodeGroup (com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentSpecNodeGroup)1 Xp7DeploymentSpecNodesPreinstalledApps (com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentSpecNodesPreinstalledApps)1 Xp7DeploymentStatusFieldsPod (com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFieldsPod)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