use of io.stackgres.common.crd.postgres.service.StackGresPostgresServices in project stackgres by ongres.
the class PatroniServices method createReplicaService.
private Service createReplicaService(StackGresDistributedLogsContext context) {
StackGresDistributedLogs cluster = context.getSource();
final Map<String, String> replicaLabels = labelFactory.patroniReplicaLabels(cluster);
final String namespace = cluster.getMetadata().getNamespace();
final String serviceName = readOnlyName(context);
String serviceType = Optional.ofNullable(cluster.getSpec()).map(StackGresDistributedLogsSpec::getPostgresServices).map(StackGresPostgresServices::getReplicas).map(StackGresPostgresService::getType).orElse(CLUSTER_IP.toString());
return new ServiceBuilder().withNewMetadata().withNamespace(namespace).withName(serviceName).withLabels(replicaLabels).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.postgres.service.StackGresPostgresServices 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.StackGresPostgresServices in project stackgres by ongres.
the class PatroniServices method createPatroniService.
private Service createPatroniService(StackGresDistributedLogsContext context) {
StackGresDistributedLogs cluster = context.getSource();
final Map<String, String> primaryLabels = labelFactory.patroniPrimaryLabels(cluster);
String serviceType = Optional.ofNullable(cluster.getSpec()).map(StackGresDistributedLogsSpec::getPostgresServices).map(StackGresPostgresServices::getPrimary).map(StackGresPostgresService::getType).orElse(CLUSTER_IP.toString());
return new ServiceBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(context)).withLabels(primaryLabels).endMetadata().withNewSpec().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();
}
Aggregations