Search in sources :

Example 1 with StackGresPostgresConfig

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);
    }
}
Also used : StackGresPostgresConfig(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig)

Example 2 with StackGresPostgresConfig

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());
}
Also used : PostgresConfigDto(io.stackgres.apiweb.dto.pgconfig.PostgresConfigDto) StackGresPostgresConfig(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig) Test(org.junit.jupiter.api.Test)

Example 3 with StackGresPostgresConfig

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;
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) StackGresPostgresConfigSpec(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfigSpec) StackGresPostgresConfig(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig) StackGresPostgresConfigStatus(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfigStatus)

Example 4 with StackGresPostgresConfig

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;
}
Also used : StackGresPostgresConfig(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig)

Example 5 with StackGresPostgresConfig

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());
}
Also used : PostgresConfigDto(io.stackgres.apiweb.dto.pgconfig.PostgresConfigDto) StackGresPostgresConfig(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig) Test(org.junit.jupiter.api.Test)

Aggregations

StackGresPostgresConfig (io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig)20 Test (org.junit.jupiter.api.Test)11 PostgresConfigDto (io.stackgres.apiweb.dto.pgconfig.PostgresConfigDto)8 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)3 StackGresPostgresConfigSpec (io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfigSpec)3 ValidationFailed (io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed)3 JsonPatchOperation (com.github.fge.jsonpatch.JsonPatchOperation)2 StackGresPostgresConfigStatus (io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfigStatus)2 PgConfigReview (io.stackgres.operator.common.PgConfigReview)2 AddOperation (com.github.fge.jsonpatch.AddOperation)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 Resources (com.google.common.io.Resources)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)1 Secret (io.fabric8.kubernetes.api.model.Secret)1 OperatorProperty (io.stackgres.common.OperatorProperty)1 BackupPhase (io.stackgres.common.crd.sgbackup.BackupPhase)1 StackGresBackup (io.stackgres.common.crd.sgbackup.StackGresBackup)1 StackGresBackupConfig (io.stackgres.common.crd.sgbackupconfig.StackGresBackupConfig)1