use of io.stackgres.common.crd.sgcluster.StackGresCluster 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();
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class PoolingConfigValidator method checkIfPoolingConfigExists.
private void checkIfPoolingConfigExists(StackGresClusterReview review, String onError) throws ValidationFailed {
StackGresCluster cluster = review.getRequest().getObject();
String poolingConfig = cluster.getSpec().getConfiguration().getConnectionPoolingConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
if (Boolean.FALSE.equals(cluster.getSpec().getPod().getDisableConnectionPooling())) {
checkIfProvided(poolingConfig, "sgPoolingConfig");
Optional<StackGresPoolingConfig> poolingConfigOpt = configFinder.findByNameAndNamespace(poolingConfig, namespace);
if (poolingConfigOpt.isEmpty()) {
fail(onError);
}
}
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class PostgresConfigValidator method validate.
@Override
public void validate(StackGresClusterReview review) throws ValidationFailed {
StackGresCluster cluster = review.getRequest().getObject();
if (cluster == null) {
return;
}
String givenPgVersion = cluster.getSpec().getPostgres().getVersion();
String pgConfig = cluster.getSpec().getConfiguration().getPostgresConfig();
checkIfProvided(givenPgVersion, "postgres version");
checkIfProvided(pgConfig, "sgPostgresConfig");
if (givenPgVersion != null && !isPostgresVersionSupported(givenPgVersion)) {
final String message = "Unsupported postgres version " + givenPgVersion + ". Supported postgres versions are: " + StackGresComponent.POSTGRESQL.getOrderedVersions().toString(", ");
fail(errorPostgresMismatchUri, message);
}
String givenMajorVersion = StackGresComponent.POSTGRESQL.findMajorVersion(givenPgVersion);
String namespace = cluster.getMetadata().getNamespace();
switch(review.getRequest().getOperation()) {
case CREATE:
validateAgainstConfiguration(givenMajorVersion, pgConfig, namespace);
break;
case UPDATE:
StackGresCluster oldCluster = review.getRequest().getOldObject();
String oldPgConfig = oldCluster.getSpec().getConfiguration().getPostgresConfig();
if (!oldPgConfig.equals(pgConfig)) {
validateAgainstConfiguration(givenMajorVersion, pgConfig, namespace);
}
long givenMajorVersionIndex = StackGresComponent.POSTGRESQL.getOrderedMajorVersions().zipWithIndex().filter(t -> t.v1.equals(givenMajorVersion)).map(Tuple2::v2).findAny().get();
String oldPgVersion = oldCluster.getSpec().getPostgres().getVersion();
String oldMajorVersion = StackGresComponent.POSTGRESQL.findMajorVersion(oldPgVersion);
long oldMajorVersionIndex = StackGresComponent.POSTGRESQL.getOrderedMajorVersions().zipWithIndex().filter(t -> t.v1.equals(oldMajorVersion)).map(Tuple2::v2).findAny().get();
if (givenMajorVersionIndex > oldMajorVersionIndex) {
fail(errorForbiddenUpdateUri, "postgres version can not be changed to a previous major version");
}
break;
default:
}
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class RestoreConfigValidator method validate.
@Override
public void validate(StackGresClusterReview review) throws ValidationFailed {
StackGresCluster cluster = review.getRequest().getObject();
Optional<StackGresClusterRestore> restoreOpt = Optional.of(cluster.getSpec()).map(StackGresClusterSpec::getInitData).map(StackGresClusterInitData::getRestore);
checkRestoreConfig(review, restoreOpt);
if (restoreOpt.isPresent()) {
StackGresClusterRestore restoreConfig = restoreOpt.get();
checkBackup(review, restoreConfig);
}
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ScriptsConfigValidator method validate.
@Override
public void validate(StackGresClusterReview review) throws ValidationFailed {
StackGresCluster cluster = review.getRequest().getObject();
List<StackGresClusterScriptEntry> scripts = Optional.of(cluster.getSpec()).map(StackGresClusterSpec::getInitData).map(StackGresClusterInitData::getScripts).orElse(ImmutableList.of());
checkScriptsConfig(review, scripts);
}
Aggregations