use of io.stackgres.common.crd.sgcluster.StackGresClusterSpec in project stackgres by ongres.
the class ExtensionsResourceTest method getIndexAnyVersion.
private StackGresExtensionIndexAnyVersion getIndexAnyVersion(String postgresVersion, StackGresClusterExtension clusterExtension) {
StackGresCluster cluster = new StackGresCluster();
cluster.setSpec(new StackGresClusterSpec());
cluster.getSpec().setPostgres(new StackGresClusterPostgres());
cluster.getSpec().getPostgres().setVersion(postgresVersion);
return new StackGresExtensionIndexAnyVersion(cluster, clusterExtension);
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterSpec in project stackgres by ongres.
the class ClusterPatroniEnvVarFactory method createResource.
@Override
public List<EnvVar> createResource(StackGresClusterContext context) {
StackGresCluster cluster = context.getSource();
List<EnvVar> additionalEnvVars = Optional.ofNullable(cluster.getSpec()).map(StackGresClusterSpec::getInitData).map(StackGresClusterInitData::getRestore).map(StackGresClusterRestore::getFromBackup).map(StackGresClusterRestoreFromBackup::getPointInTimeRecovery).map(StackGresClusterRestorePitr::getRestoreToTimestamp).map(Instant::parse).map(restoreToTimestamp -> new EnvVarBuilder().withName("RECOVERY_TARGET_TIME").withValue(DateTimeFormatter.ISO_LOCAL_DATE.withZone(ZoneId.from(ZoneOffset.UTC)).format(restoreToTimestamp) + " " + DateTimeFormatter.ISO_LOCAL_TIME.withZone(ZoneId.from(ZoneOffset.UTC)).format(restoreToTimestamp)).build()).map(List::of).orElse(List.of());
List<EnvVar> patroniEnvVars = createPatroniEnvVars(cluster);
return ImmutableList.<EnvVar>builder().add(new EnvVarBuilder().withName("PATRONI_RESTAPI_LISTEN").withValue("0.0.0.0:" + EnvoyUtil.PATRONI_PORT).build()).addAll(patroniEnvVars).addAll(additionalEnvVars).build();
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterSpec in project stackgres by ongres.
the class ClusterRequiredResourcesGeneratorTest method givenAPrometheusInstallationWithNoServiceMonitorSelector_shouldGenerateServiceMonitors.
@Test
void givenAPrometheusInstallationWithNoServiceMonitorSelector_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().stream().peek(pc -> pc.getSpec().setServiceMonitorSelector(null)).collect(Collectors.toUnmodifiableList())));
List<HasMetadata> generatedResources = generator.getRequiredResources(cluster);
var serviceMonitors = generatedResources.stream().filter(r -> r.getKind().equals(ServiceMonitor.KIND)).collect(Collectors.toUnmodifiableList());
assertEquals(2, serviceMonitors.size());
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterSpec in project stackgres by ongres.
the class ClusterRequiredResourcesGeneratorTest method givenValidClusterWithoutRestoreData_getRequiredResourcesShouldNotScanForBackups.
@Test
void givenValidClusterWithoutRestoreData_getRequiredResourcesShouldNotScanForBackups() {
cluster.getSpec().getInitData().setRestore(null);
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));
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, never()).getResources();
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterSpec in project stackgres by ongres.
the class BackupRequiredResourcesGeneratorTest method givenValidCluster_getRequiredResourcesShouldNotFail.
@Test
void givenValidCluster_getRequiredResourcesShouldNotFail() {
final String backupNamespace = backup.getMetadata().getNamespace();
final String clusterName = backup.getSpec().getSgCluster();
final StackGresClusterSpec clusterSpec = cluster.getSpec();
final StackGresClusterConfiguration clusterConfiguration = clusterSpec.getConfiguration();
final String backupConfigName = clusterConfiguration.getBackupConfig();
when(clusterFinder.findByNameAndNamespace(any(), any())).thenReturn(Optional.of(cluster));
when(backupConfigFinder.findByNameAndNamespace(backupConfigName, backupNamespace)).thenReturn(Optional.of(this.backupConfig));
generator.getRequiredResources(backup);
verify(clusterFinder, times(1)).findByNameAndNamespace(any(), any());
verify(clusterFinder).findByNameAndNamespace(eq(clusterName), eq(backupNamespace));
verify(backupConfigFinder, times(1)).findByNameAndNamespace(any(), any());
verify(backupConfigFinder).findByNameAndNamespace(eq(backupConfigName), eq(backupNamespace));
}
Aggregations