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