use of io.stackgres.common.crd.postgres.service.StackGresPostgresService in project stackgres by ongres.
the class DefaultPostgresServicesMutator method createNewPostgresService.
private StackGresPostgresService createNewPostgresService() {
StackGresPostgresService service = new StackGresPostgresService();
service.setEnabled(Boolean.TRUE);
service.setType(StackGresPostgresServiceType.CLUSTER_IP.toString());
return service;
}
use of io.stackgres.common.crd.postgres.service.StackGresPostgresService in project stackgres by ongres.
the class PatroniServices method generateResource.
/**
* Create the Services associated with the cluster.
*/
@Override
public Stream<HasMetadata> generateResource(StackGresDistributedLogsContext context) {
final StackGresDistributedLogs cluster = context.getSource();
final String namespace = cluster.getMetadata().getNamespace();
final Map<String, String> clusterLabels = labelFactory.clusterLabels(cluster);
Service config = createConfigService(namespace, configName(context), clusterLabels);
Service patroni = createPatroniService(context);
Service primary = createPrimaryService(context);
Seq<HasMetadata> services = Seq.of(config, patroni, primary);
boolean isReplicasServiceEnabled = Optional.of(cluster).map(StackGresDistributedLogs::getSpec).map(StackGresDistributedLogsSpec::getPostgresServices).map(StackGresPostgresServices::getReplicas).map(StackGresPostgresService::getEnabled).orElse(true);
if (isReplicasServiceEnabled) {
services = services.append(createReplicaService(context));
}
return services;
}
use of io.stackgres.common.crd.postgres.service.StackGresPostgresService in project stackgres by ongres.
the class PatroniServices method generateResource.
/**
* Create the Services associated with the cluster.
*/
@Override
public Stream<HasMetadata> generateResource(StackGresClusterContext context) {
final StackGresCluster cluster = context.getSource();
final String namespace = cluster.getMetadata().getNamespace();
final Map<String, String> clusterLabels = labelFactory.clusterLabels(cluster);
Service config = createConfigService(namespace, configName(context), clusterLabels);
Service rest = createPatroniRestService(context);
Seq<HasMetadata> services = Seq.of(config, rest);
boolean isPrimaryServiceEnabled = Optional.of(cluster).map(StackGresCluster::getSpec).map(StackGresClusterSpec::getPostgresServices).map(StackGresClusterPostgresServices::getPrimary).map(StackGresPostgresService::getEnabled).orElse(true);
if (isPrimaryServiceEnabled) {
Service patroni = createPatroniService(context);
services = services.append(patroni);
Service primary = createPrimaryService(context);
services = services.append(primary);
}
boolean isReplicaServiceEnabled = Optional.of(cluster).map(StackGresCluster::getSpec).map(StackGresClusterSpec::getPostgresServices).map(StackGresClusterPostgresServices::getReplicas).map(StackGresPostgresService::getEnabled).orElse(true);
if (isReplicaServiceEnabled) {
Service replicas = createReplicaService(context);
services = services.append(replicas);
}
return services;
}
use of io.stackgres.common.crd.postgres.service.StackGresPostgresService in project stackgres by ongres.
the class DefaultPostgresServicesMutatorTest method clusterWithPostgresServiceNoType_shouldSetClusterIP.
@Test
void clusterWithPostgresServiceNoType_shouldSetClusterIP() {
StackGresPostgresService primary = new StackGresPostgresService();
StackGresPostgresService replica = new StackGresPostgresService();
primary.setEnabled(Boolean.TRUE);
replica.setEnabled(Boolean.FALSE);
setPostgresServices(primary, 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("ClusterIP", pgServices.getReplicas().getType());
}
use of io.stackgres.common.crd.postgres.service.StackGresPostgresService in project stackgres by ongres.
the class DefaultPostgresServicesMutatorTest method clusterWithPostgresServiceNoReplicas_shouldSetValue.
@Test
void clusterWithPostgresServiceNoReplicas_shouldSetValue() {
StackGresPostgresService primary = new StackGresPostgresService();
primary.setEnabled(Boolean.FALSE);
primary.setType("LoadBalancing");
setPostgresServices(primary, null);
StackGresCluster actualCluster = mutate(review);
StackGresClusterPostgresServices pgServices = actualCluster.getSpec().getPostgresServices();
assertEquals(Boolean.FALSE, pgServices.getPrimary().getEnabled());
assertEquals("LoadBalancing", pgServices.getPrimary().getType());
assertEquals(Boolean.TRUE, pgServices.getReplicas().getEnabled());
assertEquals("ClusterIP", pgServices.getReplicas().getType());
}
Aggregations