Search in sources :

Example 1 with Xp7DeploymentStatusFieldsPod

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

the class OperatorXp7DeploymentStatus method handle.

private void handle(final Pod pod) {
    Optional<Xp7Deployment> xp7Deployment = searchers.xp7Deployment().find(inSameNamespaceAs(pod));
    if (xp7Deployment.isEmpty()) {
        return;
    }
    // Get current status
    Xp7DeploymentStatus currentStatus = xp7Deployment.get().getStatus();
    int oldStatusHash = currentStatus.hashCode();
    // Get all pods in deployment
    List<Pod> pods = searchers.pod().stream().filter(isEnonicManaged()).filter(isPartOfDeployment(xp7Deployment.get())).collect(Collectors.toList());
    // Set pod fields
    currentStatus.setXp7DeploymentStatusFields(buildFields(pods));
    // Get expected number of pods
    int expectedNumberOfPods = expectedNumberOfPods(xp7Deployment.get());
    // If pod count does not match
    if (pods.size() != expectedNumberOfPods) {
        updateOnChange(xp7Deployment.get(), oldStatusHash, currentStatus.withState(Xp7DeploymentStatus.State.PENDING).withMessage("Pod count mismatch"));
        return;
    }
    // If deployment is disabled
    if (!xp7Deployment.get().getSpec().getEnabled()) {
        updateOnChange(xp7Deployment.get(), oldStatusHash, currentStatus.withState(Xp7DeploymentStatus.State.STOPPED).withMessage("OK"));
        return;
    }
    // Iterate over pods and check status
    List<String> waitingForPods = new LinkedList<>();
    for (Xp7DeploymentStatusFieldsPod p : currentStatus.getXp7DeploymentStatusFields().getXp7DeploymentStatusFieldsPods()) {
        if (!p.getPhase().equals("Running") || !p.getReady()) {
            waitingForPods.add(p.getName());
        }
    }
    // If we are still waiting
    if (!waitingForPods.isEmpty()) {
        waitingForPods.sort(String::compareTo);
        updateOnChange(xp7Deployment.get(), oldStatusHash, currentStatus.withState(Xp7DeploymentStatus.State.PENDING).withMessage(String.format("Waiting for pods: %s", waitingForPods.stream().collect(Collectors.joining(", ")))));
        return;
    }
    // Return OK
    updateOnChange(xp7Deployment.get(), oldStatusHash, currentStatus.withState(Xp7DeploymentStatus.State.RUNNING).withMessage("OK"));
}
Also used : Xp7DeploymentStatusFieldsPod(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFieldsPod) Pod(io.fabric8.kubernetes.api.model.Pod) Xp7DeploymentStatusFieldsPod(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFieldsPod) Xp7Deployment(com.enonic.kubernetes.client.v1.xp7deployment.Xp7Deployment) Xp7DeploymentStatus(com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatus) LinkedList(java.util.LinkedList)

Example 2 with Xp7DeploymentStatusFieldsPod

use of com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFieldsPod 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 Xp7DeploymentStatusFieldsPod (com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFieldsPod)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 LinkedList (java.util.LinkedList)2 Xp7DeploymentSpecNodeGroup (com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentSpecNodeGroup)1 Xp7DeploymentStatusFields (com.enonic.kubernetes.client.v1.xp7deployment.Xp7DeploymentStatusFields)1 Clients (com.enonic.kubernetes.kubernetes.Clients)1 Informers (com.enonic.kubernetes.kubernetes.Informers)1 Predicates.inSameNamespaceAs (com.enonic.kubernetes.kubernetes.Predicates.inSameNamespaceAs)1 Predicates.isEnonicManaged (com.enonic.kubernetes.kubernetes.Predicates.isEnonicManaged)1 Predicates.isPartOfDeployment (com.enonic.kubernetes.kubernetes.Predicates.isPartOfDeployment)1 Predicates.onCondition (com.enonic.kubernetes.kubernetes.Predicates.onCondition)1 Searchers (com.enonic.kubernetes.kubernetes.Searchers)1 K8sLogHelper (com.enonic.kubernetes.kubernetes.commands.K8sLogHelper)1 InformerEventHandler (com.enonic.kubernetes.operator.helpers.InformerEventHandler)1 ContainerStatus (io.fabric8.kubernetes.api.model.ContainerStatus)1 StartupEvent (io.quarkus.runtime.StartupEvent)1 List (java.util.List)1 Optional (java.util.Optional)1