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());
}
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());
}
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();
}
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();
}
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);
}
Aggregations