Search in sources :

Example 1 with StackGresClusterSpecLabels

use of io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels in project stackgres by ongres.

the class ClusterTransformer method getResourceSpec.

private ClusterSpec getResourceSpec(StackGresClusterSpec source) {
    if (source == null) {
        return null;
    }
    ClusterSpec transformation = new ClusterSpec();
    transformation.setPostgres(new ClusterPostgres());
    transformation.getPostgres().setVersion(source.getPostgres().getVersion());
    transformation.getPostgres().setExtensions(Optional.ofNullable(source.getPostgres().getExtensions()).stream().flatMap(List::stream).map(this::getResourceExtension).collect(ImmutableList.toImmutableList()));
    final StackGresClusterSsl sourceClusterSsl = source.getPostgres().getSsl();
    if (sourceClusterSsl != null) {
        transformation.getPostgres().setSsl(new ClusterSsl());
        transformation.getPostgres().getSsl().setEnabled(sourceClusterSsl.getEnabled());
        transformation.getPostgres().getSsl().setCertificateSecretKeySelector(sourceClusterSsl.getCertificateSecretKeySelector());
        transformation.getPostgres().getSsl().setPrivateKeySecretKeySelector(sourceClusterSsl.getPrivateKeySecretKeySelector());
    }
    transformation.setConfigurations(new ClusterConfiguration());
    transformation.getConfigurations().setSgBackupConfig(source.getConfiguration().getBackupConfig());
    transformation.getConfigurations().setSgPoolingConfig(source.getConfiguration().getConnectionPoolingConfig());
    transformation.setInstances(source.getInstances());
    transformation.setNonProduction(getResourceNonProduction(source.getNonProduction()));
    transformation.getConfigurations().setSgPostgresConfig(source.getConfiguration().getPostgresConfig());
    transformation.setPrometheusAutobind(source.getPrometheusAutobind());
    transformation.setSgInstanceProfile(source.getResourceProfile());
    final StackGresClusterInitData sourceInitData = source.getInitData();
    if (sourceInitData != null) {
        ClusterInitData targetInitData = new ClusterInitData();
        transformation.setInitData(targetInitData);
        final StackGresClusterRestore sourceRestore = sourceInitData.getRestore();
        if (sourceRestore != null) {
            targetInitData.setRestore(getResourceRestore(sourceRestore));
        }
        if (sourceInitData.getScripts() != null) {
            targetInitData.setScripts(sourceInitData.getScripts().stream().map(sourceEntry -> {
                ClusterScriptEntry targetEntry = new ClusterScriptEntry();
                targetEntry.setScript(sourceEntry.getScript());
                targetEntry.setDatabase(sourceEntry.getDatabase());
                targetEntry.setName(sourceEntry.getName());
                if (sourceEntry.getScriptFrom() != null) {
                    targetEntry.setScriptFrom(new ClusterScriptFrom());
                    targetEntry.getScriptFrom().setSecretKeyRef(sourceEntry.getScriptFrom().getSecretKeyRef());
                    targetEntry.getScriptFrom().setConfigMapKeyRef(sourceEntry.getScriptFrom().getConfigMapKeyRef());
                }
                return targetEntry;
            }).collect(ImmutableList.toImmutableList()));
        }
    }
    final ClusterPod targetPod = new ClusterPod();
    final StackGresClusterPod sourcePod = source.getPod();
    transformation.setPods(targetPod);
    targetPod.setPersistentVolume(new ClusterPodPersistentVolume());
    targetPod.getPersistentVolume().setStorageClass(sourcePod.getPersistentVolume().getStorageClass());
    targetPod.getPersistentVolume().setSize(sourcePod.getPersistentVolume().getSize());
    targetPod.setDisableConnectionPooling(sourcePod.getDisableConnectionPooling());
    targetPod.setDisableMetricsExporter(sourcePod.getDisableMetricsExporter());
    targetPod.setDisablePostgresUtil(sourcePod.getDisablePostgresUtil());
    final StackGresClusterSpecMetadata specMetadata = source.getMetadata();
    if (specMetadata != null) {
        transformation.setMetadata(new ClusterSpecMetadata());
        final StackGresClusterSpecAnnotations sourceAnnotations = specMetadata.getAnnotations();
        if (specMetadata.getAnnotations() != null) {
            ClusterSpecAnnotations targetAnnotations = new ClusterSpecAnnotations();
            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 StackGresClusterSpecLabels sourceLabels = specMetadata.getLabels();
        if (sourceLabels != null) {
            ClusterSpecLabels targetLabels = new ClusterSpecLabels();
            targetLabels.setClusterPods(sourceLabels.getClusterPods());
            transformation.getMetadata().setLabels(targetLabels);
        }
    }
    final StackGresClusterPostgresServices sourcePostgresServices = source.getPostgresServices();
    if (sourcePostgresServices != null) {
        transformation.setPostgresServices(new ClusterPostgresServices());
        final ClusterPostgresServices targetPostgresService = transformation.getPostgresServices();
        final StackGresPostgresService sourcePrimaryService = sourcePostgresServices.getPrimary();
        if (sourcePrimaryService != null) {
            targetPostgresService.setPrimary(new PostgresService());
            targetPostgresService.getPrimary().setType(sourcePrimaryService.getType());
            targetPostgresService.getPrimary().setEnabled(sourcePrimaryService.getEnabled());
        }
        final StackGresPostgresService sourceReplicaService = sourcePostgresServices.getReplicas();
        if (sourceReplicaService != null) {
            targetPostgresService.setReplicas(new PostgresService());
            targetPostgresService.getReplicas().setEnabled(sourceReplicaService.getEnabled());
            targetPostgresService.getReplicas().setType(sourceReplicaService.getType());
        }
    }
    targetPod.setScheduling(Optional.ofNullable(sourcePod.getScheduling()).map(sourcePodScheduling -> {
        return new ClusterPodSchedulingConverter().from(sourcePodScheduling);
    }).orElse(null));
    transformation.setDistributedLogs(getResourceDistributedLogs(source.getDistributedLogs()));
    if (source.getToInstallPostgresExtensions() != null) {
        transformation.setToInstallPostgresExtensions(source.getToInstallPostgresExtensions().stream().map(this::getClusterInstalledExtension).collect(ImmutableList.toImmutableList()));
    }
    return transformation;
}
Also used : StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) ClusterInitData(io.stackgres.apiweb.dto.cluster.ClusterInitData) StackGresClusterScriptEntry(io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry) ClusterScriptEntry(io.stackgres.apiweb.dto.cluster.ClusterScriptEntry) StackGresClusterRestore(io.stackgres.common.crd.sgcluster.StackGresClusterRestore) ClusterPodSchedulingConverter(io.stackgres.apiweb.transformer.converter.cluster.ClusterPodSchedulingConverter) StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices) ClusterPostgresServices(io.stackgres.apiweb.dto.cluster.ClusterPostgresServices) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ClusterSpec(io.stackgres.apiweb.dto.cluster.ClusterSpec) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) ClusterConfiguration(io.stackgres.apiweb.dto.cluster.ClusterConfiguration) ClusterSpecAnnotations(io.stackgres.apiweb.dto.cluster.ClusterSpecAnnotations) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) StackGresPostgresService(io.stackgres.common.crd.postgres.service.StackGresPostgresService) PostgresService(io.stackgres.apiweb.app.postgres.service.PostgresService) ClusterPod(io.stackgres.apiweb.dto.cluster.ClusterPod) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) StackGresClusterPostgres(io.stackgres.common.crd.sgcluster.StackGresClusterPostgres) ClusterPostgres(io.stackgres.apiweb.dto.cluster.ClusterPostgres) StackGresClusterSpecMetadata(io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata) ClusterSpecMetadata(io.stackgres.apiweb.dto.cluster.ClusterSpecMetadata) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) StackGresClusterSsl(io.stackgres.common.crd.sgcluster.StackGresClusterSsl) ClusterSsl(io.stackgres.apiweb.dto.cluster.ClusterSsl) StackGresClusterSsl(io.stackgres.common.crd.sgcluster.StackGresClusterSsl) StackGresClusterSpecLabels(io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels) StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) ClusterPodPersistentVolume(io.stackgres.apiweb.dto.cluster.ClusterPodPersistentVolume) StackGresClusterSpecMetadata(io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata) StackGresPostgresService(io.stackgres.common.crd.postgres.service.StackGresPostgresService) StackGresClusterScriptFrom(io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom) ClusterScriptFrom(io.stackgres.apiweb.dto.cluster.ClusterScriptFrom) StackGresClusterSpecLabels(io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels) ClusterSpecLabels(io.stackgres.apiweb.dto.cluster.ClusterSpecLabels) StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices)

Example 2 with StackGresClusterSpecLabels

use of io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels in project stackgres by ongres.

the class ClusterResourceMockedTest method checkCustomResource.

@Override
protected void checkCustomResource(StackGresCluster resource, ClusterDto resourceDto, Operation operation) {
    final Metadata dtoMetadata = resourceDto.getMetadata();
    final ObjectMeta resourceMetadata = resource.getMetadata();
    if (dtoMetadata != null) {
        assertNotNull(resourceMetadata);
        assertEquals(dtoMetadata.getName(), resourceMetadata.getName());
        assertEquals(dtoMetadata.getNamespace(), resourceMetadata.getNamespace());
        assertEquals(dtoMetadata.getUid(), resourceMetadata.getUid());
    } else {
        assertNull(resourceMetadata);
    }
    final ClusterSpec dtoSpec = resourceDto.getSpec();
    final StackGresClusterSpec resourceSpec = resource.getSpec();
    if (dtoSpec != null) {
        assertNotNull(resourceSpec);
        assertEquals(dtoSpec.getPrometheusAutobind(), resourceSpec.getPrometheusAutobind());
        assertEquals(dtoSpec.getInstances(), resourceSpec.getInstances());
        assertEquals(dtoSpec.getPostgres().getVersion(), resourceSpec.getPostgres().getVersion());
        assertEquals(dtoSpec.getSgInstanceProfile(), resourceSpec.getResourceProfile());
        final ClusterConfiguration dtoSpecConfigurations = dtoSpec.getConfigurations();
        final StackGresClusterConfiguration resourceSpecConfiguration = resourceSpec.getConfiguration();
        if (dtoSpecConfigurations != null) {
            assertNotNull(resourceSpecConfiguration);
            assertEquals(dtoSpecConfigurations.getSgBackupConfig(), resourceSpecConfiguration.getBackupConfig());
            assertEquals(dtoSpecConfigurations.getSgPoolingConfig(), resourceSpecConfiguration.getConnectionPoolingConfig());
            assertEquals(dtoSpecConfigurations.getSgPostgresConfig(), resourceSpecConfiguration.getPostgresConfig());
        } else {
            assertNull(resourceSpecConfiguration);
        }
        final ClusterPod dtoSpecPods = dtoSpec.getPods();
        if (dtoSpecPods != null) {
            final StackGresClusterPod resourceSpecPod = resourceSpec.getPod();
            assertNotNull(resourceSpecPod);
            assertEquals(dtoSpecPods.getDisableConnectionPooling(), resourceSpecPod.getDisableConnectionPooling());
            assertEquals(dtoSpecPods.getDisableMetricsExporter(), resourceSpecPod.getDisableMetricsExporter());
            assertEquals(dtoSpecPods.getDisableMetricsExporter(), resourceSpecPod.getDisableMetricsExporter());
            final ClusterPodPersistentVolume dtoPV = dtoSpecPods.getPersistentVolume();
            final StackGresPodPersistentVolume resourcePV = resourceSpecPod.getPersistentVolume();
            if (dtoPV != null) {
                assertNotNull(resourcePV);
                assertEquals(dtoPV.getSize(), resourcePV.getSize());
                assertEquals(dtoPV.getStorageClass(), resourcePV.getStorageClass());
            } else {
                assertNull(resourcePV);
            }
            final StackGresClusterSpecLabels resourceMetadataLabels = Optional.ofNullable(resourceSpec.getMetadata()).map(StackGresClusterSpecMetadata::getLabels).orElse(null);
            final ClusterSpecLabels dtoMetadataLabels = Optional.ofNullable(dtoSpec.getMetadata()).map(ClusterSpecMetadata::getLabels).orElse(null);
            if (dtoMetadataLabels != null) {
                assertNotNull(resourceMetadataLabels);
                assertEquals(dtoMetadataLabels.getClusterPods(), resourceMetadataLabels.getClusterPods());
            } else {
                assertNull(resourceMetadataLabels);
            }
            final ClusterPodScheduling podScheduling = dtoSpecPods.getScheduling();
            final StackGresClusterPodScheduling resourceScheduling = resourceSpecPod.getScheduling();
            if (podScheduling != null) {
                assertNotNull(resourceScheduling);
                assertEquals(podScheduling.getNodeSelector(), resourceScheduling.getNodeSelector());
                assertEquals(podScheduling.getNodeAffinity(), resourceScheduling.getNodeAffinity());
            } else {
                assertNull(resourceScheduling);
            }
        }
        final ClusterInitData dtoInitData = dtoSpec.getInitData();
        final StackGresClusterInitData resourceInitData = resourceSpec.getInitData();
        if (dtoInitData != null) {
            assertNotNull(resourceInitData);
            final ClusterRestore dtoRestore = dtoInitData.getRestore();
            final StackGresClusterRestore resourceRestore = resourceInitData.getRestore();
            if (dtoRestore != null) {
                assertNotNull(resourceRestore);
                assertEquals(dtoRestore.getFromBackup().getUid(), resourceRestore.getFromBackup().getUid());
            } else {
                assertNull(resourceRestore);
            }
            if (dtoInitData.getScripts() != null) {
                assertNotNull(resourceInitData.getScripts());
                assertEquals(dtoInitData.getScripts().size(), resourceInitData.getScripts().size());
                Seq.zip(dtoInitData.getScripts(), resourceInitData.getScripts()).forEach(entryTuple -> {
                    ClusterScriptEntry dtoEntry = entryTuple.v1;
                    StackGresClusterScriptEntry resourceEntry = entryTuple.v2;
                    assertEquals(dtoEntry.getDatabase(), resourceEntry.getDatabase());
                    assertEquals(dtoEntry.getName(), resourceEntry.getName());
                    assertEquals(dtoEntry.getScript(), resourceEntry.getScript());
                    final ClusterScriptFrom dtoScriptFrom = dtoEntry.getScriptFrom();
                    final StackGresClusterScriptFrom resourceScriptFrom = resourceEntry.getScriptFrom();
                    if (dtoScriptFrom != null) {
                        assertNotNull(resourceScriptFrom);
                        final SecretKeySelector dtoSecretKeyRef = dtoScriptFrom.getSecretKeyRef();
                        final SecretKeySelector resourceSecretKeyRef = resourceScriptFrom.getSecretKeyRef();
                        if (dtoSecretKeyRef != null) {
                            assertNotNull(resourceSecretKeyRef);
                            assertEquals(dtoSecretKeyRef.getName(), resourceSecretKeyRef.getName());
                            assertEquals(dtoSecretKeyRef.getKey(), resourceSecretKeyRef.getKey());
                        } else {
                            assertNull(resourceSecretKeyRef);
                        }
                        final ConfigMapKeySelector resourceConfigMapKeyRef = resourceScriptFrom.getConfigMapKeyRef();
                        final ConfigMapKeySelector dtoConfigMapKeyRef = dtoScriptFrom.getConfigMapKeyRef();
                        if (dtoConfigMapKeyRef != null) {
                            assertNotNull(resourceConfigMapKeyRef);
                            assertEquals(dtoConfigMapKeyRef.getName(), resourceConfigMapKeyRef.getName());
                            assertEquals(dtoConfigMapKeyRef.getKey(), resourceConfigMapKeyRef.getKey());
                        } else {
                            assertNull(resourceConfigMapKeyRef);
                        }
                    } else {
                        assertNull(resourceScriptFrom);
                    }
                });
            }
        } else {
            assertNull(resourceInitData);
        }
        if (dtoSpec.getDistributedLogs() != null) {
            assertNotNull(resourceSpec.getDistributedLogs());
            assertEquals(dtoSpec.getDistributedLogs().getDistributedLogs(), resourceSpec.getDistributedLogs().getDistributedLogs());
        } else {
            assertNull(resourceSpec.getDistributedLogs());
        }
    } else {
        assertNull(resourceSpec);
    }
}
Also used : StackGresClusterPodScheduling(io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling) StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) ClusterInitData(io.stackgres.apiweb.dto.cluster.ClusterInitData) StackGresClusterScriptEntry(io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry) ClusterScriptEntry(io.stackgres.apiweb.dto.cluster.ClusterScriptEntry) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterRestore(io.stackgres.common.crd.sgcluster.StackGresClusterRestore) StackGresClusterScriptEntry(io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry) StackGresClusterSpecMetadata(io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata) ClusterSpecMetadata(io.stackgres.apiweb.dto.cluster.ClusterSpecMetadata) Metadata(io.stackgres.apiweb.dto.Metadata) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ClusterSpec(io.stackgres.apiweb.dto.cluster.ClusterSpec) ClusterConfiguration(io.stackgres.apiweb.dto.cluster.ClusterConfiguration) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) ClusterPodScheduling(io.stackgres.apiweb.dto.cluster.ClusterPodScheduling) StackGresClusterPodScheduling(io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling) SecretKeySelector(io.stackgres.common.crd.SecretKeySelector) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) ClusterPod(io.stackgres.apiweb.dto.cluster.ClusterPod) StackGresPodPersistentVolume(io.stackgres.common.crd.sgcluster.StackGresPodPersistentVolume) StackGresClusterSpecLabels(io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels) ClusterPodPersistentVolume(io.stackgres.apiweb.dto.cluster.ClusterPodPersistentVolume) StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) StackGresClusterScriptFrom(io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) ClusterRestore(io.stackgres.apiweb.dto.cluster.ClusterRestore) StackGresClusterRestore(io.stackgres.common.crd.sgcluster.StackGresClusterRestore) ClusterSpecLabels(io.stackgres.apiweb.dto.cluster.ClusterSpecLabels) StackGresClusterSpecLabels(io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels) StackGresClusterScriptFrom(io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom) ClusterScriptFrom(io.stackgres.apiweb.dto.cluster.ClusterScriptFrom) ConfigMapKeySelector(io.stackgres.common.crd.ConfigMapKeySelector)

Example 3 with StackGresClusterSpecLabels

use of io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels 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;
}
Also used : StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) ClusterInitData(io.stackgres.apiweb.dto.cluster.ClusterInitData) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ClusterPodSchedulingConverter(io.stackgres.apiweb.transformer.converter.cluster.ClusterPodSchedulingConverter) StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices) ClusterPostgresServices(io.stackgres.apiweb.dto.cluster.ClusterPostgresServices) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) StackGresClusterPostgres(io.stackgres.common.crd.sgcluster.StackGresClusterPostgres) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) ClusterConfiguration(io.stackgres.apiweb.dto.cluster.ClusterConfiguration) ClusterSpecAnnotations(io.stackgres.apiweb.dto.cluster.ClusterSpecAnnotations) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) StackGresPostgresService(io.stackgres.common.crd.postgres.service.StackGresPostgresService) PostgresService(io.stackgres.apiweb.app.postgres.service.PostgresService) StackGresClusterSpecMetadata(io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata) ClusterSpecMetadata(io.stackgres.apiweb.dto.cluster.ClusterSpecMetadata) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) ClusterSsl(io.stackgres.apiweb.dto.cluster.ClusterSsl) StackGresClusterSsl(io.stackgres.common.crd.sgcluster.StackGresClusterSsl) StackGresClusterSsl(io.stackgres.common.crd.sgcluster.StackGresClusterSsl) StackGresClusterSpecLabels(io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels) StackGresPodPersistentVolume(io.stackgres.common.crd.sgcluster.StackGresPodPersistentVolume) StackGresClusterSpecMetadata(io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata) StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) StackGresPostgresService(io.stackgres.common.crd.postgres.service.StackGresPostgresService) StackGresClusterSpecLabels(io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels) ClusterSpecLabels(io.stackgres.apiweb.dto.cluster.ClusterSpecLabels) StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices)

Aggregations

ClusterConfiguration (io.stackgres.apiweb.dto.cluster.ClusterConfiguration)3 ClusterInitData (io.stackgres.apiweb.dto.cluster.ClusterInitData)3 ClusterSpecLabels (io.stackgres.apiweb.dto.cluster.ClusterSpecLabels)3 ClusterSpecMetadata (io.stackgres.apiweb.dto.cluster.ClusterSpecMetadata)3 StackGresClusterConfiguration (io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration)3 StackGresClusterInitData (io.stackgres.common.crd.sgcluster.StackGresClusterInitData)3 StackGresClusterPod (io.stackgres.common.crd.sgcluster.StackGresClusterPod)3 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)3 StackGresClusterSpecLabels (io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels)3 StackGresClusterSpecMetadata (io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata)3 PostgresService (io.stackgres.apiweb.app.postgres.service.PostgresService)2 ClusterPod (io.stackgres.apiweb.dto.cluster.ClusterPod)2 ClusterPodPersistentVolume (io.stackgres.apiweb.dto.cluster.ClusterPodPersistentVolume)2 ClusterPostgresServices (io.stackgres.apiweb.dto.cluster.ClusterPostgresServices)2 ClusterScriptEntry (io.stackgres.apiweb.dto.cluster.ClusterScriptEntry)2 ClusterScriptFrom (io.stackgres.apiweb.dto.cluster.ClusterScriptFrom)2 ClusterSpec (io.stackgres.apiweb.dto.cluster.ClusterSpec)2 ClusterSpecAnnotations (io.stackgres.apiweb.dto.cluster.ClusterSpecAnnotations)2 ClusterSsl (io.stackgres.apiweb.dto.cluster.ClusterSsl)2 ClusterPodSchedulingConverter (io.stackgres.apiweb.transformer.converter.cluster.ClusterPodSchedulingConverter)2