Search in sources :

Example 1 with StackGresPostgresService

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

Example 2 with StackGresPostgresService

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;
}
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 StackGresPostgresService

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

Example 4 with StackGresPostgresService

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());
}
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)

Example 5 with StackGresPostgresService

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());
}
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

StackGresPostgresService (io.stackgres.common.crd.postgres.service.StackGresPostgresService)19 StackGresClusterPostgresServices (io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices)10 Test (org.junit.jupiter.api.Test)7 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)6 PostgresService (io.stackgres.apiweb.app.postgres.service.PostgresService)4 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 Service (io.fabric8.kubernetes.api.model.Service)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 DistributedLogsPostgresServices (io.stackgres.apiweb.dto.distributedlogs.DistributedLogsPostgresServices)2 ClusterPodSchedulingConverter (io.stackgres.apiweb.transformer.converter.cluster.ClusterPodSchedulingConverter)2 StackGresDistributedLogsPostgresServicesFixture (io.stackgres.apiweb.transformer.distributedlogs.converter.fixture.StackGresDistributedLogsPostgresServicesFixture)2 StackGresClusterConfiguration (io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration)2 StackGresClusterInitData (io.stackgres.common.crd.sgcluster.StackGresClusterInitData)2