Search in sources :

Example 21 with StackGresClusterConfiguration

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

the class ClusterRequiredResourcesGeneratorTest method givenAClusterWithoutInstanceProfile_shouldFail.

@Test
void givenAClusterWithoutInstanceProfile_shouldFail() {
    final ObjectMeta metadata = cluster.getMetadata();
    final String clusterName = metadata.getName();
    final String clusterNamespace = metadata.getNamespace();
    final StackGresClusterSpec clusterSpec = cluster.getSpec();
    final StackGresClusterConfiguration clusterConfiguration = clusterSpec.getConfiguration();
    final String postgresConfigName = clusterConfiguration.getPostgresConfig();
    mockPgConfig(clusterNamespace, postgresConfigName);
    final String resourceProfile = clusterSpec.getResourceProfile();
    when(profileConfigFinder.findByNameAndNamespace(resourceProfile, clusterNamespace)).thenReturn(Optional.empty());
    assertException("SGCluster " + clusterNamespace + "/" + clusterName + " have a non existent SGInstanceProfile " + resourceProfile);
    verify(postgresConfigFinder).findByNameAndNamespace(postgresConfigName, clusterNamespace);
    verify(profileConfigFinder).findByNameAndNamespace(resourceProfile, clusterNamespace);
    verify(backupConfigFinder, never()).findByNameAndNamespace(any(), any());
    verify(poolingConfigFinder, never()).findByNameAndNamespace(any(), any());
    verify(backupScanner, never()).getResources();
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 22 with StackGresClusterConfiguration

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

the class ClusterRequiredResourcesGeneratorTest method givenClusterWithNoBackupConfig_NotFail.

@Test
void givenClusterWithNoBackupConfig_NotFail() {
    final ObjectMeta metadata = cluster.getMetadata();
    final String clusterNamespace = metadata.getNamespace();
    final StackGresClusterSpec clusterSpec = cluster.getSpec();
    final StackGresClusterConfiguration clusterConfiguration = clusterSpec.getConfiguration();
    final String backupConfigName = clusterConfiguration.getBackupConfig();
    when(backupConfigFinder.findByNameAndNamespace(backupConfigName, clusterNamespace)).thenReturn(Optional.empty());
    final String postgresConfigName = clusterConfiguration.getPostgresConfig();
    mockPgConfig(clusterNamespace, postgresConfigName);
    final String connectionPoolingConfig = clusterConfiguration.getConnectionPoolingConfig();
    mockPoolingConfig(clusterNamespace, connectionPoolingConfig);
    final String resourceProfile = clusterSpec.getResourceProfile();
    when(profileConfigFinder.findByNameAndNamespace(resourceProfile, clusterNamespace)).thenReturn(Optional.of(instanceProfile));
    when(backupScanner.getResources()).thenReturn(backups);
    mockSecrets(clusterNamespace);
    generator.getRequiredResources(cluster);
    verify(backupConfigFinder).findByNameAndNamespace(backupConfigName, clusterNamespace);
    verify(postgresConfigFinder).findByNameAndNamespace(postgresConfigName, clusterNamespace);
    verify(poolingConfigFinder).findByNameAndNamespace(connectionPoolingConfig, clusterNamespace);
    verify(profileConfigFinder).findByNameAndNamespace(resourceProfile, clusterNamespace);
    verify(backupScanner, atLeastOnce()).getResources();
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 23 with StackGresClusterConfiguration

use of io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration 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

StackGresClusterConfiguration (io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration)23 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)22 QuarkusTest (io.quarkus.test.junit.QuarkusTest)16 Test (org.junit.jupiter.api.Test)16 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)15 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)7 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)6 StackGresBackup (io.stackgres.common.crd.sgbackup.StackGresBackup)6 StackGresBackupConfig (io.stackgres.common.crd.sgbackupconfig.StackGresBackupConfig)5 List (java.util.List)5 Optional (java.util.Optional)5 Inject (javax.inject.Inject)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Secret (io.fabric8.kubernetes.api.model.Secret)4 InjectMock (io.quarkus.test.junit.mockito.InjectMock)4 StackGresComponent (io.stackgres.common.StackGresComponent)4 StackGresClusterInitData (io.stackgres.common.crd.sgcluster.StackGresClusterInitData)4 Collectors (java.util.stream.Collectors)4 StackGresClusterRestoreFromBackup (io.stackgres.common.crd.sgcluster.StackGresClusterRestoreFromBackup)3 StackGresPostgresConfig (io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig)3