use of com.enonic.kubernetes.client.v1.xp7app.Xp7AppStatusFields in project xp-operator by enonic.
the class MutationApi method xp7app.
private void xp7app(MutationRequest mt) {
// Collect old and new object
Xp7App oldR = (Xp7App) mt.getAdmissionReview().getRequest().getOldObject();
Xp7App newR = (Xp7App) mt.getAdmissionReview().getRequest().getObject();
// Create default status
Xp7AppStatus defStatus = new Xp7AppStatus().withMessage("Created").withState(Xp7AppStatus.State.PENDING).withXp7AppStatusFields(new Xp7AppStatusFields());
// 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().getUrl().equals(oldR.getSpec().getUrl())) {
// On url 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:
// Set pending deletion status
oldR.getStatus().setState(Xp7AppStatus.State.PENDING);
oldR.getStatus().setMessage("Pending deletion");
patch(mt, true, "/status", newR.getStatus(), oldR.getStatus());
break;
}
// Ensure enabled
patch(mt, false, "/spec/enabled", newR.getSpec().getEnabled(), true);
if (op == AdmissionOperation.CREATE) {
// Ensure finalizers
List<String> oldFinalizers = ((HasMetadata) mt.getAdmissionReview().getRequest().getObject()).getMetadata().getFinalizers();
Set<String> newFinalizers = oldFinalizers != null ? new HashSet<>(oldFinalizers) : new HashSet<>();
String uninstallFinalizer = cfgStr("operator.charts.values.finalizers.app.uninstall");
if (!newFinalizers.contains(uninstallFinalizer)) {
newFinalizers.add(uninstallFinalizer);
patch(mt, true, "/metadata/finalizers", null, newFinalizers);
}
// Ensure owner reference
ensureOwnerReference(mt);
}
}
Aggregations