Search in sources :

Example 1 with StackGresClusterSpec

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();
}
Also used : StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) JsonPointer(com.github.fge.jackson.jsonpointer.JsonPointer) AddOperation(com.github.fge.jsonpatch.AddOperation)

Example 2 with StackGresClusterSpec

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));
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 3 with StackGresClusterSpec

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));
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 4 with StackGresClusterSpec

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

Example 5 with StackGresClusterSpec

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());
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)46 Test (org.junit.jupiter.api.Test)26 StackGresClusterConfiguration (io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration)23 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)18 QuarkusTest (io.quarkus.test.junit.QuarkusTest)16 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)15 List (java.util.List)11 Optional (java.util.Optional)11 Inject (javax.inject.Inject)10 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 StackGresClusterPod (io.stackgres.common.crd.sgcluster.StackGresClusterPod)8 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)7 Collectors (java.util.stream.Collectors)7 StackGresClusterInitData (io.stackgres.common.crd.sgcluster.StackGresClusterInitData)6 StackGresClusterPostgres (io.stackgres.common.crd.sgcluster.StackGresClusterPostgres)6 StackGresComponent (io.stackgres.common.StackGresComponent)5 StackGresBackup (io.stackgres.common.crd.sgbackup.StackGresBackup)5 StackGresBackupConfig (io.stackgres.common.crd.sgbackupconfig.StackGresBackupConfig)5 ValidationFailed (io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed)5