Search in sources :

Example 1 with StackGresClusterExtension

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

the class ExtensionManagerTest method getClusterExtension.

private StackGresClusterExtension getClusterExtension() {
    StackGresClusterExtension extension = new StackGresClusterExtension();
    extension.setName("timescaledb");
    return extension;
}
Also used : StackGresClusterExtension(io.stackgres.common.crd.sgcluster.StackGresClusterExtension)

Example 2 with StackGresClusterExtension

use of io.stackgres.common.crd.sgcluster.StackGresClusterExtension 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 3 with StackGresClusterExtension

use of io.stackgres.common.crd.sgcluster.StackGresClusterExtension 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)

Example 4 with StackGresClusterExtension

use of io.stackgres.common.crd.sgcluster.StackGresClusterExtension 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 5 with StackGresClusterExtension

use of io.stackgres.common.crd.sgcluster.StackGresClusterExtension 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)

Aggregations

StackGresClusterExtension (io.stackgres.common.crd.sgcluster.StackGresClusterExtension)22 Test (org.junit.jupiter.api.Test)15 JsonPatchOperation (com.github.fge.jsonpatch.JsonPatchOperation)14 StackGresClusterInstalledExtension (io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension)14 ReplaceOperation (com.github.fge.jsonpatch.ReplaceOperation)10 StackGresExtensionMetadata (io.stackgres.common.extension.StackGresExtensionMetadata)10 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)3 AddOperation (com.github.fge.jsonpatch.AddOperation)2 Extension (io.stackgres.apiweb.dto.extension.Extension)2 ExtensionUtil (io.stackgres.common.extension.ExtensionUtil)2 StackGresExtension (io.stackgres.common.extension.StackGresExtension)2 List (java.util.List)2 Seq (org.jooq.lambda.Seq)2 Tuple2 (org.jooq.lambda.tuple.Tuple2)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 JsonPointer (com.github.fge.jackson.jsonpointer.JsonPointer)1 ImmutableList (com.google.common.collect.ImmutableList)1