Search in sources :

Example 1 with StackGresPostgresServices

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();
}
Also used : StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) StackGresPostgresServices(io.stackgres.common.crd.postgres.service.StackGresPostgresServices) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder)

Example 2 with StackGresPostgresServices

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;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) StackGresPostgresServices(io.stackgres.common.crd.postgres.service.StackGresPostgresServices) StackGresPostgresService(io.stackgres.common.crd.postgres.service.StackGresPostgresService) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Example 3 with StackGresPostgresServices

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();
}
Also used : StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) StackGresPostgresServices(io.stackgres.common.crd.postgres.service.StackGresPostgresServices) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder)

Aggregations

IntOrString (io.fabric8.kubernetes.api.model.IntOrString)3 StackGresPostgresServices (io.stackgres.common.crd.postgres.service.StackGresPostgresServices)3 StackGresDistributedLogs (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs)3 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)2 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 Service (io.fabric8.kubernetes.api.model.Service)1 StackGresPostgresService (io.stackgres.common.crd.postgres.service.StackGresPostgresService)1