Search in sources :

Example 11 with StackGresPostgresConfig

use of io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig in project stackgres by ongres.

the class PgConfigDefaultStateMutator method mutate.

@Override
public List<JsonPatchOperation> mutate(PgConfigReview review) {
    List<JsonPatchOperation> operations = new ArrayList<>();
    StackGresPostgresConfig pgConfig = review.getRequest().getObject();
    if (pgConfig.getStatus() == null) {
        pgConfig.setStatus(new StackGresPostgresConfigStatus());
        operations.add(buildAddOperation(PG_CONFIG_DEFAULT_PARAMETERS_POINTER.parent(), MAPPER.createObjectNode()));
    }
    operations.addAll(mutate(PG_CONFIG_DEFAULT_PARAMETERS_POINTER, pgConfig));
    return operations;
}
Also used : ArrayList(java.util.ArrayList) StackGresPostgresConfig(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig) StackGresPostgresConfigStatus(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfigStatus) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation)

Example 12 with StackGresPostgresConfig

use of io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig in project stackgres by ongres.

the class PgConfigDefaultValuesMutator method mutate.

@Override
public List<JsonPatchOperation> mutate(PgConfigReview review) {
    ImmutableList.Builder<JsonPatchOperation> operations = ImmutableList.builder();
    StackGresPostgresConfig pgConfig = review.getRequest().getObject();
    StackGresPostgresConfigSpec spec = pgConfig.getSpec();
    if (spec == null) {
        spec = new StackGresPostgresConfigSpec();
        pgConfig.setSpec(spec);
        operations.add(new AddOperation(PG_CONFIG_POINTER.parent(), FACTORY.objectNode()));
    }
    if (spec.getPostgresqlConf() == null) {
        pgConfig.getSpec().setPostgresqlConf(ImmutableMap.of());
        operations.add(new AddOperation(PG_CONFIG_POINTER, FACTORY.objectNode()));
    }
    operations.addAll(mutate(PG_CONFIG_POINTER, pgConfig));
    return operations.build();
}
Also used : StackGresPostgresConfigSpec(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfigSpec) ImmutableList(com.google.common.collect.ImmutableList) AddOperation(com.github.fge.jsonpatch.AddOperation) StackGresPostgresConfig(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation)

Example 13 with StackGresPostgresConfig

use of io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig in project stackgres by ongres.

the class DefaultPostgresFactory method buildResource.

@Override
StackGresPostgresConfig buildResource(String namespace) {
    StackGresPostgresConfigSpec spec = new StackGresPostgresConfigSpec();
    spec.setPostgresVersion(postgresVersion);
    spec.setPostgresqlConf(getDefaultValues());
    StackGresPostgresConfig profile = new StackGresPostgresConfig();
    profile.getMetadata().setName(generateDefaultName());
    profile.getMetadata().setNamespace(namespace);
    profile.setSpec(spec);
    return profile;
}
Also used : StackGresPostgresConfigSpec(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfigSpec) StackGresPostgresConfig(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig)

Example 14 with StackGresPostgresConfig

use of io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig in project stackgres by ongres.

the class PostgresConfigTransformerTest method emptyConfig_shouldBeTransformerd.

@Test
void emptyConfig_shouldBeTransformerd() {
    List<String> clusters = ImmutableList.of("test");
    StackGresPostgresConfig source = createEmptyConfig();
    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("", 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(0, transformed.getStatus().getPostgresqlConf().size());
    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 15 with StackGresPostgresConfig

use of io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig in project stackgres by ongres.

the class PostgresConfigTransformerTest method simpleConfigDto_shouldBeTransformerd.

@Test
void simpleConfigDto_shouldBeTransformerd() {
    StackGresPostgresConfig original = createOriginal();
    PostgresConfigDto source = createEmptyConfigDto();
    source.getSpec().setPostgresqlConf("test=1");
    StackGresPostgresConfig transformed = transformer.toCustomResource(source, original);
    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.assertEquals(ImmutableMap.of("test", "1"), transformed.getSpec().getPostgresqlConf());
}
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