use of io.stackgres.operatorframework.admissionwebhook.AdmissionRequest in project stackgres by ongres.
the class ExtensionsChannelMutator method mutate.
@Override
public List<JsonPatchOperation> mutate(StackGresClusterReview review) {
if (review.getRequest().getOperation() == Operation.CREATE || review.getRequest().getOperation() == Operation.UPDATE) {
ImmutableList.Builder<JsonPatchOperation> operations = ImmutableList.builder();
Optional.of(review).map(StackGresClusterReview::getRequest).map(AdmissionRequest<StackGresCluster>::getObject).ifPresent(cluster -> {
Optional.of(cluster).map(StackGresCluster::getSpec).map(StackGresClusterSpec::getPostgres).map(StackGresClusterPostgres::getExtensions).stream().flatMap(extensions -> Seq.seq(extensions).zipWithIndex()).forEach(Unchecked.consumer(extension -> {
final JsonPointer extensionVersionPointer = CLUSTER_CONFIG_POINTER.append("postgres").append("extensions").append(extension.v2.intValue()).append("version");
final StackGresExtensionMetadata extensionMetadata;
try {
extensionMetadata = extensionMetadataManager.getExtensionCandidateSameMajorBuild(cluster, extension.v1);
} catch (Exception ex) {
LOGGER.warn("Unable to retrieve candidate with same major build for extension", ex);
return;
}
final StackGresClusterInstalledExtension installedExtension = ExtensionUtil.getInstalledExtension(extension.v1, extensionMetadata);
final TextNode extensionVersion = new TextNode(installedExtension.getVersion());
if (extension.v1.getVersion() == null) {
operations.add(new AddOperation(extensionVersionPointer, extensionVersion));
} else if (!installedExtension.getVersion().equals(extension.v1.getVersion())) {
operations.add(new ReplaceOperation(extensionVersionPointer, extensionVersion));
}
}));
});
return operations.build();
}
return ImmutableList.of();
}
Aggregations