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