use of io.stackgres.common.crd.postgres.service.StackGresPostgresService 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);
}
use of io.stackgres.common.crd.postgres.service.StackGresPostgresService 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());
}
use of io.stackgres.common.crd.postgres.service.StackGresPostgresService in project stackgres by ongres.
the class DefaultPostgresServicesMutatorTest method clusterWithPostgresServiceNoEnabled_shouldSetValue.
@Test
void clusterWithPostgresServiceNoEnabled_shouldSetValue() {
StackGresPostgresService primary = new StackGresPostgresService();
primary.setType("LoadBalancing");
setPostgresServices(primary, null);
StackGresCluster actualCluster = mutate(review);
StackGresClusterPostgresServices pgServices = actualCluster.getSpec().getPostgresServices();
assertEquals(Boolean.TRUE, pgServices.getPrimary().getEnabled());
assertEquals("LoadBalancing", pgServices.getPrimary().getType());
assertEquals(Boolean.TRUE, pgServices.getReplicas().getEnabled());
assertEquals("ClusterIP", pgServices.getReplicas().getType());
}
use of io.stackgres.common.crd.postgres.service.StackGresPostgresService in project stackgres by ongres.
the class ClusterTransformer method getCustomResourceSpec.
private StackGresClusterSpec getCustomResourceSpec(ClusterSpec source) {
if (source == null) {
return null;
}
StackGresClusterSpec transformation = new StackGresClusterSpec();
transformation.setPostgres(new StackGresClusterPostgres());
transformation.getPostgres().setVersion(source.getPostgres().getVersion());
transformation.getPostgres().setExtensions(Optional.ofNullable(source.getPostgres().getExtensions()).stream().flatMap(List::stream).map(this::getCustomResourceExtension).collect(ImmutableList.toImmutableList()));
final ClusterSsl sourceClusterSsl = source.getPostgres().getSsl();
if (sourceClusterSsl != null) {
transformation.getPostgres().setSsl(new StackGresClusterSsl());
transformation.getPostgres().getSsl().setEnabled(sourceClusterSsl.getEnabled());
transformation.getPostgres().getSsl().setCertificateSecretKeySelector(sourceClusterSsl.getCertificateSecretKeySelector());
transformation.getPostgres().getSsl().setPrivateKeySecretKeySelector(sourceClusterSsl.getPrivateKeySecretKeySelector());
}
final ClusterConfiguration sourceClusterConfiguration = source.getConfigurations();
if (sourceClusterConfiguration != null) {
transformation.setConfiguration(new StackGresClusterConfiguration());
transformation.getConfiguration().setBackupConfig(source.getConfigurations().getSgBackupConfig());
transformation.getConfiguration().setConnectionPoolingConfig(source.getConfigurations().getSgPoolingConfig());
transformation.getConfiguration().setPostgresConfig(source.getConfigurations().getSgPostgresConfig());
}
transformation.setInstances(source.getInstances());
transformation.setNonProduction(getCustomResourceNonProduction(source.getNonProduction()));
transformation.setPrometheusAutobind(source.getPrometheusAutobind());
transformation.setResourceProfile(source.getSgInstanceProfile());
final ClusterSpecMetadata specMetadata = source.getMetadata();
if (specMetadata != null) {
transformation.setMetadata(new StackGresClusterSpecMetadata());
final ClusterSpecAnnotations sourceAnnotations = specMetadata.getAnnotations();
if (sourceAnnotations != null) {
StackGresClusterSpecAnnotations targetAnnotations = new StackGresClusterSpecAnnotations();
targetAnnotations.setAllResources(sourceAnnotations.getAllResources());
targetAnnotations.setClusterPods(sourceAnnotations.getClusterPods());
targetAnnotations.setServices(sourceAnnotations.getServices());
targetAnnotations.setPrimaryService(sourceAnnotations.getPrimaryService());
targetAnnotations.setReplicasService(sourceAnnotations.getReplicasService());
transformation.getMetadata().setAnnotations(targetAnnotations);
}
final ClusterSpecLabels sourceLabels = specMetadata.getLabels();
if (sourceLabels != null) {
StackGresClusterSpecLabels targetLabels = new StackGresClusterSpecLabels();
targetLabels.setClusterPods(sourceLabels.getClusterPods());
transformation.getMetadata().setLabels(targetLabels);
}
}
final ClusterPostgresServices sourcePostgresServices = source.getPostgresServices();
if (sourcePostgresServices != null) {
transformation.setPostgresServices(new StackGresClusterPostgresServices());
final StackGresClusterPostgresServices targetPostgresService = transformation.getPostgresServices();
final PostgresService sourcePrimaryService = sourcePostgresServices.getPrimary();
if (sourcePrimaryService != null) {
targetPostgresService.setPrimary(new StackGresPostgresService());
final StackGresPostgresService targetPrimaryService = targetPostgresService.getPrimary();
targetPrimaryService.setType(sourcePrimaryService.getType());
targetPrimaryService.setEnabled(sourcePrimaryService.getEnabled());
}
final PostgresService sourceReplicaService = sourcePostgresServices.getReplicas();
if (sourceReplicaService != null) {
targetPostgresService.setReplicas(new StackGresPostgresService());
final StackGresPostgresService targetReplicaService = targetPostgresService.getReplicas();
targetReplicaService.setEnabled(sourceReplicaService.getEnabled());
targetReplicaService.setType(sourceReplicaService.getType());
}
}
final ClusterInitData sourceInitData = source.getInitData();
if (sourceInitData != null) {
final StackGresClusterInitData targetInitData = new StackGresClusterInitData();
transformation.setInitData(targetInitData);
if (sourceInitData.getRestore() != null) {
targetInitData.setRestore(getCustomResourceRestore(sourceInitData.getRestore()));
}
if (sourceInitData.getScripts() != null) {
targetInitData.setScripts(getCustomResourceScripts(sourceInitData.getScripts()));
}
}
final StackGresClusterPod targetPod = new StackGresClusterPod();
transformation.setPod(targetPod);
targetPod.setPersistentVolume(new StackGresPodPersistentVolume());
targetPod.getPersistentVolume().setStorageClass(source.getPods().getPersistentVolume().getStorageClass());
targetPod.getPersistentVolume().setSize(source.getPods().getPersistentVolume().getSize());
targetPod.setDisableConnectionPooling(source.getPods().getDisableConnectionPooling());
targetPod.setDisableMetricsExporter(source.getPods().getDisableMetricsExporter());
targetPod.setDisablePostgresUtil(source.getPods().getDisablePostgresUtil());
targetPod.setScheduling(Optional.ofNullable(source.getPods().getScheduling()).map(sourceScheduling -> {
return new ClusterPodSchedulingConverter().to(sourceScheduling);
}).orElse(null));
transformation.setDistributedLogs(getCustomResourceDistributedLogs(source.getDistributedLogs()));
return transformation;
}
Aggregations