Search in sources :

Example 16 with StackGresClusterConfiguration

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

the class ClusterRequiredResourcesGeneratorTest method givenAClusterWithInvalidPgConfig_getRequiredResourcesShouldFail.

@Test
void givenAClusterWithInvalidPgConfig_getRequiredResourcesShouldFail() {
    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();
    when(postgresConfigFinder.findByNameAndNamespace(postgresConfigName, clusterNamespace)).thenReturn(Optional.empty());
    assertException("SGCluster " + clusterNamespace + "/" + clusterName + " have a non existent SGPostgresConfig " + postgresConfigName);
    verify(postgresConfigFinder).findByNameAndNamespace(postgresConfigName, clusterNamespace);
    verify(profileConfigFinder, never()).findByNameAndNamespace(any(), any());
    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 17 with StackGresClusterConfiguration

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

the class ClusterRequiredResourcesGeneratorTest method givenValidClusterWithNoPoolingConfig_getRequiredResourcesShouldNotFail.

@Test
void givenValidClusterWithNoPoolingConfig_getRequiredResourcesShouldNotFail() {
    final ObjectMeta metadata = cluster.getMetadata();
    final String clusterNamespace = metadata.getNamespace();
    final StackGresClusterSpec clusterSpec = cluster.getSpec();
    final StackGresClusterConfiguration clusterConfiguration = clusterSpec.getConfiguration();
    clusterConfiguration.setConnectionPoolingConfig(null);
    final String backupConfigName = clusterConfiguration.getBackupConfig();
    mockBackupConfig(clusterNamespace, backupConfigName);
    final String postgresConfigName = clusterConfiguration.getPostgresConfig();
    mockPgConfig(clusterNamespace, postgresConfigName);
    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, never()).findByNameAndNamespace(any(), any());
    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 18 with StackGresClusterConfiguration

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

the class ClusterRequiredResourcesGeneratorTest method givenValidClusterWithoutBackupConfig_getRequiredResourcesShouldNotFail.

@Test
void givenValidClusterWithoutBackupConfig_getRequiredResourcesShouldNotFail() {
    final ObjectMeta metadata = cluster.getMetadata();
    final String clusterNamespace = metadata.getNamespace();
    final StackGresClusterSpec clusterSpec = cluster.getSpec();
    final StackGresClusterConfiguration clusterConfiguration = clusterSpec.getConfiguration();
    clusterConfiguration.setBackupConfig(null);
    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, never()).findByNameAndNamespace(any(), any());
    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 19 with StackGresClusterConfiguration

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

the class ClusterRequiredResourcesGeneratorTest method givenValidCluster_getRequiredResourcesShouldNotFail.

@Test
void givenValidCluster_getRequiredResourcesShouldNotFail() {
    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();
    mockBackupConfig(clusterNamespace, backupConfigName);
    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 20 with StackGresClusterConfiguration

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

the class ClusterRequiredResourcesGeneratorTest method givenADefaultPrometheusInstallation_shouldGenerateServiceMonitors.

@Test
void givenADefaultPrometheusInstallation_shouldGenerateServiceMonitors() {
    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();
    mockBackupConfig(clusterNamespace, backupConfigName);
    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);
    when(prometheusScanner.findResources()).thenReturn(Optional.of(JsonUtil.readFromJson("prometheus/prometheus_list.json", PrometheusConfigList.class).getItems()));
    List<HasMetadata> generatedResources = generator.getRequiredResources(cluster);
    var serviceMonitors = generatedResources.stream().filter(r -> r.getKind().equals(ServiceMonitor.KIND)).collect(Collectors.toUnmodifiableList());
    assertEquals(2, serviceMonitors.size());
    verify(prometheusScanner).findResources();
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StackGresBackupList(io.stackgres.common.crd.sgbackup.StackGresBackupList) BeforeEach(org.junit.jupiter.api.BeforeEach) PoolingConfigFinder(io.stackgres.common.resource.PoolingConfigFinder) StackGresPostgresConfigStatus(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfigStatus) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) StackGresBackup(io.stackgres.common.crd.sgbackup.StackGresBackup) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresPoolingConfigStatus(io.stackgres.common.crd.sgpooling.StackGresPoolingConfigStatus) StackGresPostgresConfig(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig) PrometheusConfigList(io.stackgres.operator.customresource.prometheus.PrometheusConfigList) QuarkusTest(io.quarkus.test.junit.QuarkusTest) ServiceMonitor(io.stackgres.operator.customresource.prometheus.ServiceMonitor) Inject(javax.inject.Inject) StackGresClusterRestoreFromBackup(io.stackgres.common.crd.sgcluster.StackGresClusterRestoreFromBackup) ProfileConfigFinder(io.stackgres.common.resource.ProfileConfigFinder) SecretFinder(io.stackgres.common.resource.SecretFinder) BackupScanner(io.stackgres.common.resource.BackupScanner) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) InjectMock(io.quarkus.test.junit.mockito.InjectMock) StackGresBackupConfig(io.stackgres.common.crd.sgbackupconfig.StackGresBackupConfig) PgBouncerDefaultValues(io.stackgres.operator.conciliation.factory.cluster.sidecars.pooling.parameters.PgBouncerDefaultValues) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) StackGresPoolingConfig(io.stackgres.common.crd.sgpooling.StackGresPoolingConfig) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StackGresProfile(io.stackgres.common.crd.sgprofile.StackGresProfile) JsonUtil(io.stackgres.testutil.JsonUtil) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) StackGresComponent(io.stackgres.common.StackGresComponent) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) Mockito.never(org.mockito.Mockito.never) List(java.util.List) BackupConfigFinder(io.stackgres.common.resource.BackupConfigFinder) StackGresPoolingConfigPgBouncerStatus(io.stackgres.common.crd.sgpooling.StackGresPoolingConfigPgBouncerStatus) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PostgresDefaultValues(io.stackgres.operator.conciliation.factory.cluster.patroni.parameters.PostgresDefaultValues) Optional(java.util.Optional) Secret(io.fabric8.kubernetes.api.model.Secret) PostgresConfigFinder(io.stackgres.common.resource.PostgresConfigFinder) PrometheusScanner(io.stackgres.operator.resource.PrometheusScanner) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) PrometheusConfigList(io.stackgres.operator.customresource.prometheus.PrometheusConfigList) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

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