Search in sources :

Example 1 with StackGresExtensionMetadata

use of io.stackgres.common.extension.StackGresExtensionMetadata in project stackgres by ongres.

the class AbstractExtensionsMutator method getExtension.

protected Optional<StackGresClusterInstalledExtension> getExtension(StackGresCluster cluster, String extensionName, String extensionVersion) {
    StackGresClusterExtension extension = new StackGresClusterExtension();
    extension.setName(extensionName);
    extension.setVersion(extensionVersion);
    try {
        StackGresExtensionMetadata extensionMetadata = getExtensionMetadataManager().getExtensionCandidateSameMajorBuild(cluster, extension);
        return Optional.of(ExtensionUtil.getInstalledExtension(extension, extensionMetadata));
    } catch (Exception ex) {
        LOGGER.warn("Unable to retrieve candidate with same major build for extension", ex);
        return Optional.empty();
    }
}
Also used : StackGresClusterExtension(io.stackgres.common.crd.sgcluster.StackGresClusterExtension) StackGresExtensionMetadata(io.stackgres.common.extension.StackGresExtensionMetadata)

Example 2 with StackGresExtensionMetadata

use of io.stackgres.common.extension.StackGresExtensionMetadata in project stackgres by ongres.

the class ExtensionsMutatorTest method clusterWithExtensionInstalledAddExtensionWithExtraMounts_shouldReplaceToInstallExtensions.

@Test
void clusterWithExtensionInstalledAddExtensionWithExtraMounts_shouldReplaceToInstallExtensions() throws Exception {
    final StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
    final StackGresClusterExtension extension = getExtension();
    extension.setVersion(installedExtension.getVersion());
    review.getRequest().getObject().getSpec().getPostgres().setExtensions(ImmutableList.of(extension));
    review.getRequest().getObject().getSpec().setToInstallPostgresExtensions(new ArrayList<>());
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().addAll(defaultExtensions);
    final StackGresClusterInstalledExtension installedTestExtension = getInstalledExtension();
    installedTestExtension.setName("test");
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().add(installedTestExtension);
    final StackGresExtensionMetadata extensionMetadata = getExtensionMetadata();
    extensionMetadata.getVersion().setExtraMounts(ImmutableList.of("test"));
    when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(extension))).thenReturn(extensionMetadata);
    final List<JsonPatchOperation> operations = mutator.mutate(review);
    assertEquals(1, operations.size());
    assertEquals(1, operations.stream().filter(o -> o instanceof ReplaceOperation).count());
}
Also used : ReplaceOperation(com.github.fge.jsonpatch.ReplaceOperation) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) StackGresClusterExtension(io.stackgres.common.crd.sgcluster.StackGresClusterExtension) StackGresExtensionMetadata(io.stackgres.common.extension.StackGresExtensionMetadata) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) Test(org.junit.jupiter.api.Test)

Example 3 with StackGresExtensionMetadata

use of io.stackgres.common.extension.StackGresExtensionMetadata in project stackgres by ongres.

the class ExtensionsMutatorTest method clusterWithMissingExtension_shouldNotDoAnything.

@Test
void clusterWithMissingExtension_shouldNotDoAnything() throws Exception {
    final StackGresClusterInstalledExtension installedTestExtension = getInstalledExtension();
    installedTestExtension.setName("test");
    final StackGresClusterExtension testExtension = getExtension();
    testExtension.setName("test");
    testExtension.setVersion(installedTestExtension.getVersion());
    review.getRequest().getObject().getSpec().getPostgres().setExtensions(ImmutableList.of(testExtension));
    review.getRequest().getObject().getSpec().setToInstallPostgresExtensions(new ArrayList<>());
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().addAll(defaultExtensions);
    final StackGresExtensionMetadata extensionTestMetadata = getExtensionMetadata();
    extensionTestMetadata.getExtension().setName("test");
    when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(testExtension))).thenThrow(IllegalArgumentException.class);
    final List<JsonPatchOperation> operations = mutator.mutate(review);
    assertEquals(0, operations.size());
}
Also used : StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) StackGresClusterExtension(io.stackgres.common.crd.sgcluster.StackGresClusterExtension) StackGresExtensionMetadata(io.stackgres.common.extension.StackGresExtensionMetadata) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) Test(org.junit.jupiter.api.Test)

Example 4 with StackGresExtensionMetadata

use of io.stackgres.common.extension.StackGresExtensionMetadata in project stackgres by ongres.

the class ExtensionsMutatorTest method clusterWithExtensionInstalledAddADifferntExtension_shouldAddToInstallPostgresExtensions.

@Test
void clusterWithExtensionInstalledAddADifferntExtension_shouldAddToInstallPostgresExtensions() throws Exception {
    final StackGresClusterInstalledExtension installedTestExtension = getInstalledExtension();
    installedTestExtension.setName("test");
    final StackGresClusterExtension testExtension = getExtension();
    testExtension.setName("test");
    testExtension.setVersion(installedTestExtension.getVersion());
    final StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
    final StackGresClusterExtension extension = getExtension();
    extension.setVersion(installedExtension.getVersion());
    review.getRequest().getObject().getSpec().getPostgres().setExtensions(ImmutableList.of(extension, testExtension));
    review.getRequest().getObject().getSpec().setToInstallPostgresExtensions(new ArrayList<>());
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().addAll(defaultExtensions);
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().add(installedTestExtension);
    final StackGresExtensionMetadata extensionTestMetadata = getExtensionMetadata();
    extensionTestMetadata.getExtension().setName("test");
    when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(testExtension))).thenReturn(extensionTestMetadata);
    final StackGresExtensionMetadata extensionMetadata = getExtensionMetadata();
    when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(extension))).thenReturn(extensionMetadata);
    final List<JsonPatchOperation> operations = mutator.mutate(review);
    assertEquals(1, operations.size());
}
Also used : StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) StackGresClusterExtension(io.stackgres.common.crd.sgcluster.StackGresClusterExtension) StackGresExtensionMetadata(io.stackgres.common.extension.StackGresExtensionMetadata) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) Test(org.junit.jupiter.api.Test)

Example 5 with StackGresExtensionMetadata

use of io.stackgres.common.extension.StackGresExtensionMetadata in project stackgres by ongres.

the class ExtensionsMutatorTest method clusterWithAnAlreadyInstalledMissingExtension_shouldReplaceToInstall.

@Test
void clusterWithAnAlreadyInstalledMissingExtension_shouldReplaceToInstall() throws Exception {
    final StackGresClusterInstalledExtension installedTestExtension = getInstalledExtension();
    installedTestExtension.setName("test");
    final StackGresClusterExtension testExtension = getExtension();
    testExtension.setName("test");
    testExtension.setVersion(installedTestExtension.getVersion());
    review.getRequest().getObject().getSpec().getPostgres().setExtensions(ImmutableList.of(testExtension));
    review.getRequest().getObject().getSpec().setToInstallPostgresExtensions(new ArrayList<>());
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().addAll(defaultExtensions);
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().add(installedTestExtension);
    final StackGresExtensionMetadata extensionTestMetadata = getExtensionMetadata();
    extensionTestMetadata.getExtension().setName("test");
    when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(testExtension))).thenThrow(IllegalArgumentException.class);
    final List<JsonPatchOperation> operations = mutator.mutate(review);
    assertEquals(1, operations.size());
    assertEquals(1, operations.stream().filter(o -> o instanceof ReplaceOperation).count());
}
Also used : ReplaceOperation(com.github.fge.jsonpatch.ReplaceOperation) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) StackGresClusterExtension(io.stackgres.common.crd.sgcluster.StackGresClusterExtension) StackGresExtensionMetadata(io.stackgres.common.extension.StackGresExtensionMetadata) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) Test(org.junit.jupiter.api.Test)

Aggregations

StackGresExtensionMetadata (io.stackgres.common.extension.StackGresExtensionMetadata)10 JsonPatchOperation (com.github.fge.jsonpatch.JsonPatchOperation)9 StackGresClusterExtension (io.stackgres.common.crd.sgcluster.StackGresClusterExtension)9 StackGresClusterInstalledExtension (io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension)9 Test (org.junit.jupiter.api.Test)8 ReplaceOperation (com.github.fge.jsonpatch.ReplaceOperation)7 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 JsonPointer (com.github.fge.jackson.jsonpointer.JsonPointer)1 AddOperation (com.github.fge.jsonpatch.AddOperation)1 ImmutableList (com.google.common.collect.ImmutableList)1 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)1 StackGresClusterPostgres (io.stackgres.common.crd.sgcluster.StackGresClusterPostgres)1 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)1 ExtensionUtil (io.stackgres.common.extension.ExtensionUtil)1 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)1 ClusterExtensionMetadataManager (io.stackgres.operator.mutation.ClusterExtensionMetadataManager)1 AdmissionRequest (io.stackgres.operatorframework.admissionwebhook.AdmissionRequest)1 Operation (io.stackgres.operatorframework.admissionwebhook.Operation)1 List (java.util.List)1 Optional (java.util.Optional)1