use of io.stackgres.common.crd.sgcluster.StackGresClusterSpec in project stackgres by ongres.
the class ClusterConfigurationMutator method ensureConfigurationNode.
static List<JsonPatchOperation> ensureConfigurationNode(StackGresClusterReview review) {
final StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
StackGresClusterConfiguration configuration = spec.getConfiguration();
if (configuration == null) {
try {
configuration = new StackGresClusterConfiguration();
spec.setConfiguration(configuration);
final JsonPointer confPointer = getTargetPointer();
final AddOperation configurationAdd = new AddOperation(confPointer, JsonPatchMutator.FACTORY.objectNode());
return ImmutableList.of(configurationAdd);
} catch (NoSuchFieldException e) {
return ImmutableList.of();
}
}
return ImmutableList.of();
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterSpec in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenValidPostgresVersion_shouldNotFail.
@Test
void givenValidPostgresVersion_shouldNotFail() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
String postgresProfile = spec.getConfiguration().getPostgresConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(configFinder.findByNameAndNamespace(eq(postgresProfile), eq(namespace))).thenReturn(Optional.of(postgresConfig));
final String randomVersion = getRandomPostgresVersion();
spec.getPostgres().setVersion(randomVersion);
postgresConfig.getSpec().setPostgresVersion(getMajorPostgresVersion(randomVersion));
validator.validate(review);
verify(configFinder).findByNameAndNamespace(eq(postgresProfile), eq(namespace));
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterSpec in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenValidMajorPostgresVersion_shouldNotFail.
@Test
void givenValidMajorPostgresVersion_shouldNotFail() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
spec.getPostgres().setVersion(getMajorPostgresVersion(getRandomPostgresVersion()));
String postgresProfile = spec.getConfiguration().getPostgresConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(configFinder.findByNameAndNamespace(eq(postgresProfile), eq(namespace))).thenReturn(Optional.of(postgresConfig));
final String randomVersion = getRandomPostgresVersion();
spec.getPostgres().setVersion(randomVersion);
postgresConfig.getSpec().setPostgresVersion(getMajorPostgresVersion(randomVersion));
validator.validate(review);
verify(configFinder).findByNameAndNamespace(eq(postgresProfile), eq(namespace));
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterSpec in project stackgres by ongres.
the class ClusterValidationQuarkusTest method getConstraintClusterReview.
private StackGresClusterReview getConstraintClusterReview() {
var review = readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
review.getRequest().getObject().getMetadata().setNamespace("test");
StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
spec.setToInstallPostgresExtensions(getInstalledExtension("dblink", "pg_stat_statements", "plpgsql", "plpython3u"));
spec.setDistributedLogs(null);
spec.setInitData(null);
spec.getPostgres().setVersion("12.8");
return review;
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterSpec in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenEmptyPostgresConfigReference_shouldFail.
@Test
void givenEmptyPostgresConfigReference_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
spec.getConfiguration().setPostgresConfig("");
ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = exception.getResult().getMessage();
assertEquals("sgPostgresConfig must be provided", resultMessage);
verify(configFinder, never()).findByNameAndNamespace(anyString(), anyString());
}
Aggregations