use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices in project stackgres by ongres.
the class StackGresDistributedLogsUtilTest method shouldBuildSgDistributedLogsPostgresServices_withOnlyPrimary.
@Test
void shouldBuildSgDistributedLogsPostgresServices_withOnlyPrimary() {
StackGresDistributedLogsSpec spec = new StackGresDistributedLogsSpecFixture().withPrimaryPostgresServices(primary).build();
StackGresClusterPostgresServices postgresServices = StackGresDistributedLogsUtil.buildPostgresServices(spec);
assertNotNull(postgresServices.getPrimary());
assertNull(postgresServices.getReplicas());
assertTrue(primary.equals(postgresServices.getPrimary()));
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices 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.StackGresClusterPostgresServices in project stackgres by ongres.
the class StackGresDistributedLogsUtil method buildPostgresServices.
static StackGresClusterPostgresServices buildPostgresServices(StackGresDistributedLogsSpec stackGresDistributedLogsSpec) {
StackGresClusterPostgresServices postgresServices = new StackGresClusterPostgresServices();
Optional.ofNullable(stackGresDistributedLogsSpec).map(StackGresDistributedLogsSpec::getPostgresServices).ifPresent(pgServices -> {
postgresServices.setPrimary(pgServices.getPrimary());
postgresServices.setReplicas(pgServices.getReplicas());
});
return postgresServices;
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices in project stackgres by ongres.
the class PatroniServicesTest method enableReplicaService.
private void enableReplicaService(boolean enabled) {
StackGresClusterPostgresServices postgresServices = new StackGresClusterPostgresServices();
StackGresPostgresService replicaService = new StackGresPostgresService();
replicaService.setEnabled(enabled);
postgresServices.setReplicas(replicaService);
defaultCluster.getSpec().setPostgresServices(postgresServices);
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices in project stackgres by ongres.
the class DefaultPostgresServicesMutatorTest method clusterWithPostgresServiceNoPrimary_shouldSetValue.
@Test
void clusterWithPostgresServiceNoPrimary_shouldSetValue() {
StackGresPostgresService replica = new StackGresPostgresService();
replica.setEnabled(Boolean.FALSE);
replica.setType("LoadBalancing");
setPostgresServices(null, replica);
StackGresCluster actualCluster = mutate(review);
StackGresClusterPostgresServices pgServices = actualCluster.getSpec().getPostgresServices();
assertEquals(Boolean.TRUE, pgServices.getPrimary().getEnabled());
assertEquals("ClusterIP", pgServices.getPrimary().getType());
assertEquals(Boolean.FALSE, pgServices.getReplicas().getEnabled());
assertEquals("LoadBalancing", pgServices.getReplicas().getType());
}
Aggregations