use of io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig in project stackgres by ongres.
the class PostgresConfigValidator method validateAgainstConfiguration.
private void validateAgainstConfiguration(String givenMajorVersion, String pgConfig, String namespace) throws ValidationFailed {
Optional<StackGresPostgresConfig> postgresConfigOpt = configFinder.findByNameAndNamespace(pgConfig, namespace);
if (postgresConfigOpt.isPresent()) {
StackGresPostgresConfig postgresConfig = postgresConfigOpt.get();
String pgVersion = postgresConfig.getSpec().getPostgresVersion();
if (!pgVersion.equals(givenMajorVersion)) {
final String message = "Invalid postgres version, must be " + pgVersion + " to use sgPostgresConfig " + pgConfig;
fail(errorPostgresMismatchUri, message);
}
} else {
final String message = "Invalid sgPostgresConfig value " + pgConfig;
fail(errorCrReferencerUri, message);
}
}
use of io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig in project stackgres by ongres.
the class PostgresConfigTransformerTest method simpleConfig_shouldBeTransformerd.
@Test
void simpleConfig_shouldBeTransformerd() {
List<String> clusters = ImmutableList.of("test");
StackGresPostgresConfig source = createEmptyConfig();
source.getSpec().setPostgresqlConf(ImmutableMap.of("test", "1"));
PostgresConfigDto transformed = transformer.toResource(source, clusters);
Assertions.assertNotNull(transformed.getMetadata());
Assertions.assertEquals("default", transformed.getMetadata().getNamespace());
Assertions.assertEquals("test", transformed.getMetadata().getName());
Assertions.assertEquals("test", transformed.getMetadata().getUid());
Assertions.assertNotNull(transformed.getSpec());
Assertions.assertEquals("11", transformed.getSpec().getPostgresVersion());
Assertions.assertNotNull(transformed.getSpec().getPostgresqlConf());
Assertions.assertEquals("test='1'", transformed.getSpec().getPostgresqlConf());
Assertions.assertNotNull(transformed.getStatus());
Assertions.assertNotNull(transformed.getStatus().getDefaultParameters());
Assertions.assertEquals(0, transformed.getStatus().getDefaultParameters().size());
Assertions.assertNotNull(transformed.getStatus().getPostgresqlConf());
Assertions.assertEquals(1, transformed.getStatus().getPostgresqlConf().size());
Assertions.assertEquals("test", transformed.getStatus().getPostgresqlConf().get(0).getParameter());
Assertions.assertEquals("1", transformed.getStatus().getPostgresqlConf().get(0).getValue());
Assertions.assertEquals("https://postgresqlco.nf/en/doc/param/test/11/", transformed.getStatus().getPostgresqlConf().get(0).getDocumentationLink());
Assertions.assertNotNull(transformed.getStatus().getClusters());
Assertions.assertEquals(clusters, transformed.getStatus().getClusters());
}
use of io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig in project stackgres by ongres.
the class PostgresConfigTransformerTest method createEmptyConfig.
StackGresPostgresConfig createEmptyConfig() {
StackGresPostgresConfig source = new StackGresPostgresConfig();
source.setMetadata(new ObjectMeta());
source.getMetadata().setNamespace("default");
source.getMetadata().setName("test");
source.getMetadata().setUid("test");
source.setSpec(new StackGresPostgresConfigSpec());
source.getSpec().setPostgresVersion("11");
source.getSpec().setPostgresqlConf(ImmutableMap.of());
source.setStatus(new StackGresPostgresConfigStatus());
source.getStatus().setDefaultParameters(ImmutableMap.of());
return source;
}
use of io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig in project stackgres by ongres.
the class PostgresConfigTransformer method toCustomResource.
@Override
public StackGresPostgresConfig toCustomResource(PostgresConfigDto source, StackGresPostgresConfig original) {
StackGresPostgresConfig transformation = Optional.ofNullable(original).orElseGet(StackGresPostgresConfig::new);
transformation.setMetadata(getCustomResourceMetadata(source, original));
transformation.setSpec(getCustomResourceSpec(source.getSpec()));
return transformation;
}
use of io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig in project stackgres by ongres.
the class PostgresConfigTransformerTest method advancedConfig_shouldBeTransformerd.
@Test
void advancedConfig_shouldBeTransformerd() {
List<String> clusters = ImmutableList.of("test");
StackGresPostgresConfig source = createEmptyConfig();
source.getSpec().setPostgresqlConf(ImmutableMap.<String, String>builder().put("test4", "").put("test5", "1").put("test7", "1'").build());
PostgresConfigDto transformed = transformer.toResource(source, clusters);
Assertions.assertNotNull(transformed.getMetadata());
Assertions.assertEquals("default", transformed.getMetadata().getNamespace());
Assertions.assertEquals("test", transformed.getMetadata().getName());
Assertions.assertEquals("test", transformed.getMetadata().getUid());
Assertions.assertNotNull(transformed.getSpec());
Assertions.assertEquals("11", transformed.getSpec().getPostgresVersion());
Assertions.assertNotNull(transformed.getSpec().getPostgresqlConf());
Assertions.assertEquals("test4=''\ntest5='1'\ntest7='1'''", transformed.getSpec().getPostgresqlConf());
Assertions.assertNotNull(transformed.getStatus());
Assertions.assertNotNull(transformed.getStatus().getDefaultParameters());
Assertions.assertEquals(0, transformed.getStatus().getDefaultParameters().size());
Assertions.assertNotNull(transformed.getStatus().getPostgresqlConf());
Assertions.assertEquals(3, transformed.getStatus().getPostgresqlConf().size());
Assertions.assertEquals("test4", transformed.getStatus().getPostgresqlConf().get(0).getParameter());
Assertions.assertEquals("", transformed.getStatus().getPostgresqlConf().get(0).getValue());
Assertions.assertEquals("https://postgresqlco.nf/en/doc/param/test4/11/", transformed.getStatus().getPostgresqlConf().get(0).getDocumentationLink());
Assertions.assertEquals("test5", transformed.getStatus().getPostgresqlConf().get(1).getParameter());
Assertions.assertEquals("1", transformed.getStatus().getPostgresqlConf().get(1).getValue());
Assertions.assertEquals("https://postgresqlco.nf/en/doc/param/test5/11/", transformed.getStatus().getPostgresqlConf().get(1).getDocumentationLink());
Assertions.assertEquals("test7", transformed.getStatus().getPostgresqlConf().get(2).getParameter());
Assertions.assertEquals("1'", transformed.getStatus().getPostgresqlConf().get(2).getValue());
Assertions.assertEquals("https://postgresqlco.nf/en/doc/param/test7/11/", transformed.getStatus().getPostgresqlConf().get(2).getDocumentationLink());
Assertions.assertNotNull(transformed.getStatus().getClusters());
Assertions.assertEquals(clusters, transformed.getStatus().getClusters());
}
Aggregations