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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations