use of io.fabric8.zjsonpatch.JsonPatch in project stackgres by ongres.
the class MutationResource method mutate.
default AdmissionReviewResponse mutate(T admissionReview, JsonPatchMutationPipeline<T> pipeline) {
AdmissionRequest<?> request = admissionReview.getRequest();
UUID requestUid = request.getUid();
logger.info("Mutating admission review " + requestUid.toString() + " of kind " + request.getKind().toString());
AdmissionResponse response = new AdmissionResponse();
response.setUid(requestUid);
AdmissionReviewResponse reviewResponse = new AdmissionReviewResponse();
reviewResponse.setResponse(response);
reviewResponse.setGroup(admissionReview.getGroup());
reviewResponse.setKind(admissionReview.getKind());
reviewResponse.setVersion(admissionReview.getVersion());
try {
pipeline.mutate(admissionReview).ifPresent(path -> {
response.setPatchType("JSONPatch");
String base64Path = Base64.getEncoder().encodeToString(path.getBytes(StandardCharsets.UTF_8));
response.setPatch(base64Path);
});
response.setAllowed(true);
} catch (Exception ex) {
Status status = new StatusBuilder().withMessage(Optional.ofNullable(ex.getMessage()).orElse("null")).withCode(500).build();
logger.error("cannot proceed with request " + requestUid.toString() + " cause: " + status.getMessage(), ex);
response.setAllowed(false);
response.setStatus(status);
}
return reviewResponse;
}
Aggregations