Search in sources :

Example 81 with StackGresCluster

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

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

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

the class PatroniServices method createReplicaService.

private Service createReplicaService(StackGresClusterContext context) {
    StackGresCluster cluster = context.getSource();
    final Map<String, String> replicaLabels = labelFactory.patroniReplicaLabels(cluster);
    Map<String, String> annotations = Optional.ofNullable(cluster.getSpec()).map(StackGresClusterSpec::getMetadata).map(StackGresClusterSpecMetadata::getAnnotations).map(StackGresClusterSpecAnnotations::getReplicasService).orElse(Map.of());
    String serviceType = Optional.ofNullable(cluster.getSpec()).map(StackGresClusterSpec::getPostgresServices).map(StackGresClusterPostgresServices::getReplicas).map(StackGresPostgresService::getType).orElse(StackGresPostgresServiceType.CLUSTER_IP.toString());
    return new ServiceBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(readOnlyName(context)).withLabels(replicaLabels).withAnnotations(annotations).endMetadata().withNewSpec().withSelector(replicaLabels).withPorts(new ServicePortBuilder().withProtocol("TCP").withName(PatroniConfigMap.POSTGRES_PORT_NAME).withPort(PatroniUtil.POSTGRES_SERVICE_PORT).withTargetPort(new IntOrString(PatroniConfigMap.POSTGRES_PORT_NAME)).build(), new ServicePortBuilder().withProtocol("TCP").withName(PatroniConfigMap.POSTGRES_REPLICATION_PORT_NAME).withPort(PatroniUtil.REPLICATION_SERVICE_PORT).withTargetPort(new IntOrString(PatroniConfigMap.POSTGRES_REPLICATION_PORT_NAME)).build()).withType(serviceType).endSpec().build();
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) StackGresClusterSpecMetadata(io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder)

Example 84 with StackGresCluster

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

the class TemplatesConfigMap method buildSource.

@NotNull
public HasMetadata buildSource(StackGresClusterContext context) {
    Map<String, String> data = getPatroniTemplates();
    final StackGresCluster cluster = context.getSource();
    return new ConfigMapBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(context)).withLabels(labelFactory.clusterLabels(cluster)).endMetadata().withData(data).build();
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 85 with StackGresCluster

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

the class TemplatesConfigMap method generateResource.

public Stream<HasMetadata> generateResource(StackGresClusterContext context) {
    Map<String, String> data = getPatroniTemplates();
    final StackGresCluster cluster = context.getSource();
    ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(context)).withLabels(labelFactory.clusterLabels(cluster)).endMetadata().withData(data).build();
    return Stream.of(configMap);
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) AbstractPatroniTemplatesConfigMap(io.stackgres.operator.conciliation.factory.AbstractPatroniTemplatesConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder)

Aggregations

StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)127 Test (org.junit.jupiter.api.Test)48 Optional (java.util.Optional)32 List (java.util.List)31 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)27 StackGresClusterInstalledExtension (io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension)25 ImmutableList (com.google.common.collect.ImmutableList)24 Inject (javax.inject.Inject)22 ArrayList (java.util.ArrayList)19 StackGresClusterStatus (io.stackgres.common.crd.sgcluster.StackGresClusterStatus)18 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)15 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)15 StackGresComponent (io.stackgres.common.StackGresComponent)15 StackGresClusterPodStatus (io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus)14 ExtensionInstaller (io.stackgres.common.extension.ExtensionManager.ExtensionInstaller)14 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)13 Collectors (java.util.stream.Collectors)13 BeforeEach (org.junit.jupiter.api.BeforeEach)13 ExtensionUninstaller (io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller)12 JsonUtil (io.stackgres.testutil.JsonUtil)12