Search in sources :

Example 11 with StackGresClusterInstalledExtension

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

the class ExtensionManagerTest method getInstalledExtension.

private StackGresClusterInstalledExtension getInstalledExtension() {
    StackGresClusterInstalledExtension installedExtension = new StackGresClusterInstalledExtension();
    installedExtension.setName("timescaledb");
    installedExtension.setPublisher("com.ongres");
    installedExtension.setRepository(REPOSITORY.toASCIIString());
    installedExtension.setVersion("1.7.1");
    installedExtension.setPostgresVersion(POSTGRES_MAJOR_VERSION);
    installedExtension.setBuild(BUILD_MAJOR_VERSION);
    return installedExtension;
}
Also used : StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension)

Example 12 with StackGresClusterInstalledExtension

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

the class ExtensionManagerTest method testCheckExtensionWillOverwrite.

@Test
void testCheckExtensionWillOverwrite() throws Exception {
    StackGresCluster cluster = getCluster();
    when(webClientFactory.create(anyBoolean())).thenReturn(webClient);
    when(webClient.getJson(any(), any())).thenReturn(getExtensions());
    final String extensionPackageName = ExtensionUtil.getExtensionPackageName(getInstalledExtension());
    when(fileSystemHandler.newInputStream(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.TGZ_SUFFIX)))).then(invocation -> getClass().getResourceAsStream("/test.tgz"));
    when(fileSystemHandler.exists(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib/postgresql/12/lib").resolve("test.so")))).thenReturn(true);
    StackGresClusterInstalledExtension extension = getInstalledExtension();
    Assertions.assertTrue(extensionManager.getExtensionInstaller(context(cluster), extension).doesInstallOverwriteAnySharedLibrary());
    verify(webClientFactory, times(1)).create(anyBoolean());
    verify(webClient, times(1)).getJson(any(), any());
    verify(webClient, times(1)).getJson(eq(ExtensionUtil.getIndexUri(REPOSITORY)), eq(StackGresExtensions.class));
    verify(webClient, times(0)).getInputStream(eq(ExtensionUtil.getExtensionPackageUri(REPOSITORY, extension, getExtensionMetadata())));
    verify(fileSystemHandler, times(0)).newInputStream(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.SHA256_SUFFIX)));
    verify(fileSystemHandler, times(1)).newInputStream(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.TGZ_SUFFIX)));
    verify(fileSystemHandler, times(0)).createOrReplaceFile(any());
    verify(fileSystemHandler, times(0)).createDirectories(any());
    verify(fileSystemHandler, times(0)).createOrReplaceSymbolicLink(any(), any());
    verify(fileSystemHandler, times(0)).copyOrReplace(any(), any());
    verify(fileSystemHandler, times(0)).setPosixFilePermissions(any(), any());
    verify(fileSystemHandler, times(0)).deleteIfExists(any());
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) Test(org.junit.jupiter.api.Test)

Example 13 with StackGresClusterInstalledExtension

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

the class ExtensionEventEmitterImplTest method setUp.

@BeforeEach
void setUp() {
    extension = new StackGresClusterInstalledExtension();
    extension.setBuild(StringUtils.getRandomString());
    extension.setName(StringUtils.getRandomString());
    extension.setVersion(StringUtils.getRandomString());
}
Also used : StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with StackGresClusterInstalledExtension

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

the class ExtensionUtilTest method testExtensionsMetadataMap.

@Test
public void testExtensionsMetadataMap() {
    StackGresClusterInstalledExtension installedExtension0 = new StackGresClusterInstalledExtension();
    installedExtension0.setName(extensions.get(0).getName());
    installedExtension0.setPublisher(extensionsMetadata.getPublishers().get(0).getId());
    installedExtension0.setRepository(repository.toASCIIString());
    installedExtension0.setVersion(extensions.get(0).getVersion());
    installedExtension0.setPostgresVersion(firstPgMajorVersion);
    installedExtension0.setBuild(build);
    StackGresClusterInstalledExtension installedExtension1 = new StackGresClusterInstalledExtension();
    installedExtension1.setName(extensions.get(1).getName());
    installedExtension1.setPublisher(extensionsMetadata.getPublishers().get(0).getId());
    installedExtension1.setRepository(repository.toASCIIString());
    installedExtension1.setVersion(extensionsMetadata.getExtensions().stream().filter(e -> e.getName().equals(extensions.get(1).getName())).findAny().get().getVersions().get(0).getVersion());
    installedExtension1.setPostgresVersion(firstPgMajorVersion);
    installedExtension1.setBuild(build);
    StackGresClusterInstalledExtension installedExtension2 = new StackGresClusterInstalledExtension();
    installedExtension2.setName(extensions.get(2).getName());
    installedExtension2.setPublisher(extensionsMetadata.getPublishers().get(0).getId());
    installedExtension2.setRepository(repository.toASCIIString());
    installedExtension2.setVersion(extensions.get(2).getVersion());
    installedExtension2.setPostgresVersion(firstPgMajorVersion);
    installedExtension2.setBuild(build);
    StackGresClusterInstalledExtension installedExtension3 = new StackGresClusterInstalledExtension();
    installedExtension3.setName(extensions.get(3).getName());
    installedExtension3.setPublisher(extensionsMetadata.getPublishers().get(0).getId());
    installedExtension3.setRepository(repository.toASCIIString());
    installedExtension3.setVersion(extensionsMetadata.getExtensions().stream().filter(e -> e.getName().equals(extensions.get(3).getName())).findAny().get().getVersions().get(0).getVersion());
    installedExtension3.setPostgresVersion(pgVersion);
    installedExtension3.setBuild(build);
    Map<StackGresExtensionIndex, StackGresExtensionMetadata> extensionMetadataMap = ExtensionUtil.toExtensionsMetadataIndex(repository, extensionsMetadata);
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension0)));
    Assertions.assertNotEquals(repository, extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension0)).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension1)));
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension1)).getExtension().getRepository());
    Assertions.assertNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension2)));
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension3)));
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension3)).getExtension().getRepository());
    installedExtension0.setPostgresVersion(secondPgMajorVersion);
    installedExtension1.setPostgresVersion(secondPgMajorVersion);
    installedExtension2.setPostgresVersion(secondPgMajorVersion);
    installedExtension3.setPostgresVersion(secondPgVersion);
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension0)));
    Assertions.assertNotEquals(repository, extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension0)).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension1)));
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension1)).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension2)));
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension2)).getExtension().getRepository());
    Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension3)));
    Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension3)).getExtension().getRepository());
}
Also used : StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) Test(org.junit.jupiter.api.Test)

Example 15 with StackGresClusterInstalledExtension

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

the class AbstractExtensionsMutator method mutateExtensions.

private ImmutableList<JsonPatchOperation> mutateExtensions(T customResource) {
    final ImmutableList.Builder<JsonPatchOperation> operations = ImmutableList.builder();
    final StackGresCluster cluster = getCluster(customResource);
    List<StackGresClusterExtension> extensions = getExtensions(customResource);
    List<StackGresClusterInstalledExtension> missingDefaultExtensions = Seq.seq(getDefaultExtensions(getCluster(customResource))).filter(defaultExtension -> extensions.stream().noneMatch(extension -> extension.getName().equals(defaultExtension.getName()))).collect(ImmutableList.toImmutableList());
    final List<StackGresClusterInstalledExtension> toInstallExtensions = Seq.seq(extensions).map(extension -> getToInstallExtension(cluster, extension)).filter(Optional::isPresent).map(Optional::get).append(missingDefaultExtensions).collect(ImmutableList.toImmutableList());
    final ArrayNode toInstallExtensionsNode = getObjectMapper().valueToTree(toInstallExtensions);
    if (getToInstallExtensions(customResource).orElse(null) == null) {
        operations.add(new AddOperation(TO_INSTALL_EXTENSIONS_POINTER, toInstallExtensionsNode));
    } else if (getToInstallExtensions(customResource).map(previousToInstallExtensions -> toInstallExtensionsHasChanged(toInstallExtensions, previousToInstallExtensions)).orElse(true)) {
        operations.add(new ReplaceOperation(TO_INSTALL_EXTENSIONS_POINTER, toInstallExtensionsNode));
    }
    Seq.seq(extensions).zipWithIndex().forEach(extension -> toInstallExtensions.stream().filter(toInstallExtension -> toInstallExtension.getName().equals(extension.v1.getName())).findFirst().ifPresent(installedExtension -> onExtensionToInstall(operations, extension.v1, extension.v2.intValue(), installedExtension)));
    return operations.build();
}
Also used : Logger(org.slf4j.Logger) AddOperation(com.github.fge.jsonpatch.AddOperation) Operation(io.stackgres.operatorframework.admissionwebhook.Operation) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) JsonPointer(com.github.fge.jackson.jsonpointer.JsonPointer) ReplaceOperation(com.github.fge.jsonpatch.ReplaceOperation) Seq(org.jooq.lambda.Seq) AdmissionReview(io.stackgres.operatorframework.admissionwebhook.AdmissionReview) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) StackGresClusterExtension(io.stackgres.common.crd.sgcluster.StackGresClusterExtension) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) StackGresExtensionMetadata(io.stackgres.common.extension.StackGresExtensionMetadata) ImmutableList(com.google.common.collect.ImmutableList) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) ExtensionUtil(io.stackgres.common.extension.ExtensionUtil) JsonPatchMutator(io.stackgres.operatorframework.admissionwebhook.mutating.JsonPatchMutator) Optional(java.util.Optional) AdmissionRequest(io.stackgres.operatorframework.admissionwebhook.AdmissionRequest) CustomResource(io.fabric8.kubernetes.client.CustomResource) Optional(java.util.Optional) ImmutableList(com.google.common.collect.ImmutableList) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) StackGresClusterExtension(io.stackgres.common.crd.sgcluster.StackGresClusterExtension) 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) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

StackGresClusterInstalledExtension (io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension)52 Test (org.junit.jupiter.api.Test)35 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)24 List (java.util.List)15 Optional (java.util.Optional)15 JsonPatchOperation (com.github.fge.jsonpatch.JsonPatchOperation)14 ImmutableList (com.google.common.collect.ImmutableList)14 StackGresClusterExtension (io.stackgres.common.crd.sgcluster.StackGresClusterExtension)14 ExtensionInstaller (io.stackgres.common.extension.ExtensionManager.ExtensionInstaller)14 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)13 StackGresClusterStatus (io.stackgres.common.crd.sgcluster.StackGresClusterStatus)13 BeforeEach (org.junit.jupiter.api.BeforeEach)13 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)12 StackGresComponent (io.stackgres.common.StackGresComponent)12 StackGresClusterPodStatus (io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus)12 ExtensionUninstaller (io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller)12 ArrayList (java.util.ArrayList)12 ReplaceOperation (com.github.fge.jsonpatch.ReplaceOperation)11 StackGresClusterList (io.stackgres.common.crd.sgcluster.StackGresClusterList)11 JsonUtil (io.stackgres.testutil.JsonUtil)11