use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class TemplatesConfigMap method buildSource.
@NotNull
public HasMetadata buildSource(StackGresClusterContext context) {
Map<String, String> data = getPatroniTemplates();
final StackGresCluster cluster = context.getSource();
ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(context)).withLabels(labelFactory.clusterLabels(cluster)).endMetadata().withData(data).build();
return configMap;
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class Patroni method postInitName.
public String postInitName(StackGresClusterContext clusterContext) {
final StackGresCluster cluster = clusterContext.getSource();
final String clusterName = labelFactory.resourceName(cluster);
return clusterName + POST_INIT_SUFFIX;
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class RestoreConfigMap method buildSource.
@NotNull
public Optional<HasMetadata> buildSource(StackGresClusterContext context) {
return context.getRestoreBackup().map(restoreBackup -> {
final Map<String, String> data = new HashMap<>();
data.put("BACKUP_RESOURCE_VERSION", restoreBackup.getMetadata().getResourceVersion());
data.put("RESTORE_BACKUP_ID", restoreBackup.getStatus().getInternalName());
data.putAll(getBackupEnvVars(context, restoreBackup.getMetadata().getNamespace(), restoreBackup.getSpec().getSgCluster(), restoreBackup.getStatus().getBackupConfig()));
final StackGresCluster cluster = context.getSource();
Optional.ofNullable(cluster.getSpec()).map(StackGresClusterSpec::getInitData).map(StackGresClusterInitData::getRestore).map(StackGresClusterRestore::getDownloadDiskConcurrency).ifPresent(downloadDiskConcurrency -> data.put("WALG_DOWNLOAD_CONCURRENCY", convertEnvValue(downloadDiskConcurrency)));
return new ConfigMapBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(context)).withLabels(labelFactory.patroniClusterLabels(cluster)).endMetadata().withData(StackGresUtil.addMd5Sum(data)).build();
});
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class AbstractPgPooling method buildSource.
@NotNull
public HasMetadata buildSource(@NotNull StackGresClusterContext context) {
final StackGresCluster sgCluster = context.getSource();
String configFile = getConfigFile(context.getPoolingConfig());
Map<String, String> data = ImmutableMap.of("pgbouncer.ini", configFile);
String namespace = sgCluster.getMetadata().getNamespace();
String configMapName = configName(context);
return new ConfigMapBuilder().withNewMetadata().withNamespace(namespace).withName(configMapName).withLabels(labelFactory.clusterLabels(sgCluster)).endMetadata().withData(data).build();
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ScriptsConfigValidatorTest method givenACreationUsingScriptFromSecret_shouldValidateSecretKeyReference.
@Test
void givenACreationUsingScriptFromSecret_shouldValidateSecretKeyReference() throws ValidationFailed {
final StackGresClusterReview review = getCreationReview();
String randomSecretKey = StringUtil.generateRandom();
String randomSecretName = StringUtil.generateRandom();
final StackGresCluster cluster = review.getRequest().getObject();
prepareForSecret(review, randomSecretName, randomSecretKey);
final String namespace = cluster.getMetadata().getNamespace();
when(secretFinder.findByNameAndNamespace(randomSecretName, namespace)).thenReturn(Optional.of(new SecretBuilder().withNewMetadata().withName(randomSecretName).withNamespace(namespace).endMetadata().withData(ImmutableMap.of(randomSecretKey, "CREATE DATABASE test;")).build()));
validator.validate(review);
final List<StackGresClusterScriptEntry> scripts = cluster.getSpec().getInitData().getScripts();
verify(secretFinder, times(scripts.size())).findByNameAndNamespace(randomSecretName, namespace);
}
Aggregations