Search in sources :

Example 1 with StackGresClusterPostgres

use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgres in project stackgres by ongres.

the class ExtensionsResourceTest method getIndexAnyVersion.

private StackGresExtensionIndexAnyVersion getIndexAnyVersion(String postgresVersion, StackGresClusterExtension clusterExtension) {
    StackGresCluster cluster = new StackGresCluster();
    cluster.setSpec(new StackGresClusterSpec());
    cluster.getSpec().setPostgres(new StackGresClusterPostgres());
    cluster.getSpec().getPostgres().setVersion(postgresVersion);
    return new StackGresExtensionIndexAnyVersion(cluster, clusterExtension);
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterPostgres(io.stackgres.common.crd.sgcluster.StackGresClusterPostgres) StackGresExtensionIndexAnyVersion(io.stackgres.common.extension.StackGresExtensionIndexAnyVersion)

Example 2 with StackGresClusterPostgres

use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgres in project stackgres by ongres.

the class SslValidatorTest method prepareForSsl.

private void prepareForSsl(StackGresClusterReview review) {
    review.getRequest().getObject().getSpec().setPostgres(new StackGresClusterPostgres());
    review.getRequest().getObject().getSpec().getPostgres().setSsl(new StackGresClusterSsl());
    review.getRequest().getObject().getSpec().getPostgres().getSsl().setEnabled(true);
    review.getRequest().getObject().getSpec().getPostgres().getSsl().setCertificateSecretKeySelector(new SecretKeySelector());
    review.getRequest().getObject().getSpec().getPostgres().getSsl().getCertificateSecretKeySelector().setName("secret1");
    review.getRequest().getObject().getSpec().getPostgres().getSsl().getCertificateSecretKeySelector().setKey("test");
    review.getRequest().getObject().getSpec().getPostgres().getSsl().setPrivateKeySecretKeySelector(new SecretKeySelector());
    review.getRequest().getObject().getSpec().getPostgres().getSsl().getPrivateKeySecretKeySelector().setName("secret2");
    review.getRequest().getObject().getSpec().getPostgres().getSsl().getPrivateKeySecretKeySelector().setKey("test");
}
Also used : StackGresClusterSsl(io.stackgres.common.crd.sgcluster.StackGresClusterSsl) StackGresClusterPostgres(io.stackgres.common.crd.sgcluster.StackGresClusterPostgres) SecretKeySelector(io.stackgres.common.crd.SecretKeySelector)

Example 3 with StackGresClusterPostgres

use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgres in project stackgres by ongres.

the class ExtensionUtilTest method testExtensionsMetadataMapSameMajorBuild.

@Test
public void testExtensionsMetadataMapSameMajorBuild() {
    StackGresCluster cluster = new StackGresCluster();
    cluster.setSpec(new StackGresClusterSpec());
    cluster.getSpec().setPostgres(new StackGresClusterPostgres());
    var extensionMetadataMap = ExtensionUtil.toExtensionsMetadataIndexSameMajorBuilds(repository, extensionsMetadata);
    cluster.getSpec().getPostgres().setVersion(firstPgMajorVersion);
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(0))));
    Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(0))).size());
    Assertions.assertNotEquals(repository, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(0))).get(0).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(1))));
    Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(1))).size());
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(1))).get(0).getExtension().getRepository());
    Assertions.assertNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(2))));
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(3))));
    Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(3))).size());
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(3))).get(0).getExtension().getRepository());
    cluster.getSpec().getPostgres().setVersion(secondPgMajorVersion);
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(0))));
    Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(0))).size());
    Assertions.assertNotEquals(repository, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(0))).get(0).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(1))));
    Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(1))).size());
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(1))).get(0).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(2))));
    Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(2))).size());
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(2))).get(0).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(3))));
    Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(3))).size());
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(3))).get(0).getExtension().getRepository());
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterPostgres(io.stackgres.common.crd.sgcluster.StackGresClusterPostgres) Test(org.junit.jupiter.api.Test)

Example 4 with StackGresClusterPostgres

use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgres in project stackgres by ongres.

the class ExtensionUtilTest method testExtensionsMetadataMapAnyVersion.

@Test
public void testExtensionsMetadataMapAnyVersion() {
    StackGresCluster cluster = new StackGresCluster();
    cluster.setSpec(new StackGresClusterSpec());
    cluster.getSpec().setPostgres(new StackGresClusterPostgres());
    cluster.getSpec().setPostgres(new StackGresClusterPostgres());
    Map<StackGresExtensionIndexAnyVersion, List<StackGresExtensionMetadata>> extensionMetadataMap = ExtensionUtil.toExtensionsMetadataIndexAnyVersions(repository, extensionsMetadata);
    cluster.getSpec().getPostgres().setVersion(firstPgMajorVersion);
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(0))));
    Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(0))).size());
    Assertions.assertNotEquals(repository, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(0))).get(0).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))));
    Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))).size());
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))).get(0).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))));
    Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))).size());
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))).get(0).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(3))));
    Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(3))).size());
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(3))).get(0).getExtension().getRepository());
    cluster.getSpec().getPostgres().setVersion(secondPgMajorVersion);
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(0))));
    Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(0))).size());
    Assertions.assertNotEquals(repository, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(0))).get(0).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))));
    Assertions.assertEquals(2, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))).size());
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))).get(0).getExtension().getRepository());
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))).get(1).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))));
    Assertions.assertEquals(2, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))).size());
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))).get(0).getExtension().getRepository());
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))).get(1).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(3))));
    Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(3))).size());
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(3))).get(0).getExtension().getRepository());
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterPostgres(io.stackgres.common.crd.sgcluster.StackGresClusterPostgres) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 5 with StackGresClusterPostgres

use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgres in project stackgres by ongres.

the class ExtensionsChannelMutator method mutate.

@Override
public List<JsonPatchOperation> mutate(StackGresClusterReview review) {
    if (review.getRequest().getOperation() == Operation.CREATE || review.getRequest().getOperation() == Operation.UPDATE) {
        ImmutableList.Builder<JsonPatchOperation> operations = ImmutableList.builder();
        Optional.of(review).map(StackGresClusterReview::getRequest).map(AdmissionRequest<StackGresCluster>::getObject).ifPresent(cluster -> {
            Optional.of(cluster).map(StackGresCluster::getSpec).map(StackGresClusterSpec::getPostgres).map(StackGresClusterPostgres::getExtensions).stream().flatMap(extensions -> Seq.seq(extensions).zipWithIndex()).forEach(Unchecked.consumer(extension -> {
                final JsonPointer extensionVersionPointer = CLUSTER_CONFIG_POINTER.append("postgres").append("extensions").append(extension.v2.intValue()).append("version");
                final StackGresExtensionMetadata extensionMetadata;
                try {
                    extensionMetadata = extensionMetadataManager.getExtensionCandidateSameMajorBuild(cluster, extension.v1);
                } catch (Exception ex) {
                    LOGGER.warn("Unable to retrieve candidate with same major build for extension", ex);
                    return;
                }
                final StackGresClusterInstalledExtension installedExtension = ExtensionUtil.getInstalledExtension(extension.v1, extensionMetadata);
                final TextNode extensionVersion = new TextNode(installedExtension.getVersion());
                if (extension.v1.getVersion() == null) {
                    operations.add(new AddOperation(extensionVersionPointer, extensionVersion));
                } else if (!installedExtension.getVersion().equals(extension.v1.getVersion())) {
                    operations.add(new ReplaceOperation(extensionVersionPointer, extensionVersion));
                }
            }));
        });
        return operations.build();
    }
    return ImmutableList.of();
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) Unchecked(org.jooq.lambda.Unchecked) Logger(org.slf4j.Logger) AddOperation(com.github.fge.jsonpatch.AddOperation) Operation(io.stackgres.operatorframework.admissionwebhook.Operation) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) LoggerFactory(org.slf4j.LoggerFactory) JsonPointer(com.github.fge.jackson.jsonpointer.JsonPointer) ReplaceOperation(com.github.fge.jsonpatch.ReplaceOperation) Seq(org.jooq.lambda.Seq) TextNode(com.fasterxml.jackson.databind.node.TextNode) Inject(javax.inject.Inject) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) List(java.util.List) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) StackGresClusterPostgres(io.stackgres.common.crd.sgcluster.StackGresClusterPostgres) StackGresExtensionMetadata(io.stackgres.common.extension.StackGresExtensionMetadata) ClusterExtensionMetadataManager(io.stackgres.operator.mutation.ClusterExtensionMetadataManager) ImmutableList(com.google.common.collect.ImmutableList) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) ExtensionUtil(io.stackgres.common.extension.ExtensionUtil) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) AdmissionRequest(io.stackgres.operatorframework.admissionwebhook.AdmissionRequest) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ImmutableList(com.google.common.collect.ImmutableList) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) TextNode(com.fasterxml.jackson.databind.node.TextNode) JsonPointer(com.github.fge.jackson.jsonpointer.JsonPointer) StackGresExtensionMetadata(io.stackgres.common.extension.StackGresExtensionMetadata) AddOperation(com.github.fge.jsonpatch.AddOperation) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ReplaceOperation(com.github.fge.jsonpatch.ReplaceOperation)

Aggregations

StackGresClusterPostgres (io.stackgres.common.crd.sgcluster.StackGresClusterPostgres)8 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)7 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)6 StackGresClusterInitData (io.stackgres.common.crd.sgcluster.StackGresClusterInitData)2 StackGresClusterPod (io.stackgres.common.crd.sgcluster.StackGresClusterPod)2 StackGresClusterSpecAnnotations (io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations)2 StackGresClusterSpecMetadata (io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata)2 StackGresPodPersistentVolume (io.stackgres.common.crd.sgcluster.StackGresPodPersistentVolume)2 List (java.util.List)2 Optional (java.util.Optional)2 Inject (javax.inject.Inject)2 Unchecked (org.jooq.lambda.Unchecked)2 Test (org.junit.jupiter.api.Test)2 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 JsonPointer (com.github.fge.jackson.jsonpointer.JsonPointer)1 AddOperation (com.github.fge.jsonpatch.AddOperation)1 JsonPatchOperation (com.github.fge.jsonpatch.JsonPatchOperation)1 ReplaceOperation (com.github.fge.jsonpatch.ReplaceOperation)1 ImmutableList (com.google.common.collect.ImmutableList)1 Authenticated (io.quarkus.security.Authenticated)1