Search in sources :

Example 36 with StackGresClusterSpec

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

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

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

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

Example 40 with StackGresClusterSpec

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

Aggregations

StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)46 Test (org.junit.jupiter.api.Test)26 StackGresClusterConfiguration (io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration)23 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)18 QuarkusTest (io.quarkus.test.junit.QuarkusTest)16 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)15 List (java.util.List)11 Optional (java.util.Optional)11 Inject (javax.inject.Inject)10 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 StackGresClusterPod (io.stackgres.common.crd.sgcluster.StackGresClusterPod)8 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)7 Collectors (java.util.stream.Collectors)7 StackGresClusterInitData (io.stackgres.common.crd.sgcluster.StackGresClusterInitData)6 StackGresClusterPostgres (io.stackgres.common.crd.sgcluster.StackGresClusterPostgres)6 StackGresComponent (io.stackgres.common.StackGresComponent)5 StackGresBackup (io.stackgres.common.crd.sgbackup.StackGresBackup)5 StackGresBackupConfig (io.stackgres.common.crd.sgbackupconfig.StackGresBackupConfig)5 ValidationFailed (io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed)5