Search in sources :

Example 11 with StackGresClusterPostgresServices

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()));
}
Also used : StackGresDistributedLogsSpec(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsSpec) StackGresDistributedLogsSpecFixture(io.stackgres.common.fixture.StackGresDistributedLogsSpecFixture) StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices) Test(org.junit.jupiter.api.Test)

Example 12 with StackGresClusterPostgresServices

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();
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) StackGresClusterSpecMetadata(io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder)

Example 13 with StackGresClusterPostgresServices

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;
}
Also used : StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices)

Example 14 with StackGresClusterPostgresServices

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);
}
Also used : StackGresPostgresService(io.stackgres.common.crd.postgres.service.StackGresPostgresService) StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices)

Example 15 with StackGresClusterPostgresServices

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());
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresPostgresService(io.stackgres.common.crd.postgres.service.StackGresPostgresService) StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices) Test(org.junit.jupiter.api.Test)

Aggregations

StackGresClusterPostgresServices (io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices)18 StackGresPostgresService (io.stackgres.common.crd.postgres.service.StackGresPostgresService)10 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)9 Test (org.junit.jupiter.api.Test)8 StackGresClusterSpecMetadata (io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata)4 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)3 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)2 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)2 PostgresService (io.stackgres.apiweb.app.postgres.service.PostgresService)2 ClusterConfiguration (io.stackgres.apiweb.dto.cluster.ClusterConfiguration)2 ClusterInitData (io.stackgres.apiweb.dto.cluster.ClusterInitData)2 ClusterPostgresServices (io.stackgres.apiweb.dto.cluster.ClusterPostgresServices)2 ClusterSpecAnnotations (io.stackgres.apiweb.dto.cluster.ClusterSpecAnnotations)2 ClusterSpecLabels (io.stackgres.apiweb.dto.cluster.ClusterSpecLabels)2 ClusterSpecMetadata (io.stackgres.apiweb.dto.cluster.ClusterSpecMetadata)2 ClusterSsl (io.stackgres.apiweb.dto.cluster.ClusterSsl)2 ClusterPodSchedulingConverter (io.stackgres.apiweb.transformer.converter.cluster.ClusterPodSchedulingConverter)2 StackGresClusterConfiguration (io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration)2 StackGresClusterInitData (io.stackgres.common.crd.sgcluster.StackGresClusterInitData)2 StackGresClusterPod (io.stackgres.common.crd.sgcluster.StackGresClusterPod)2