Search in sources :

Example 86 with StackGresCluster

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;
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) AbstractPatroniTemplatesConfigMap(io.stackgres.operator.conciliation.factory.v09.AbstractPatroniTemplatesConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 87 with StackGresCluster

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;
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Example 88 with StackGresCluster

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();
    });
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) NotNull(org.jetbrains.annotations.NotNull)

Example 89 with StackGresCluster

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();
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with StackGresCluster

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);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterScriptEntry(io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry) Test(org.junit.jupiter.api.Test)

Aggregations

StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)127 Test (org.junit.jupiter.api.Test)48 Optional (java.util.Optional)32 List (java.util.List)31 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)27 StackGresClusterInstalledExtension (io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension)25 ImmutableList (com.google.common.collect.ImmutableList)24 Inject (javax.inject.Inject)22 ArrayList (java.util.ArrayList)19 StackGresClusterStatus (io.stackgres.common.crd.sgcluster.StackGresClusterStatus)18 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)15 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)15 StackGresComponent (io.stackgres.common.StackGresComponent)15 StackGresClusterPodStatus (io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus)14 ExtensionInstaller (io.stackgres.common.extension.ExtensionManager.ExtensionInstaller)14 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)13 Collectors (java.util.stream.Collectors)13 BeforeEach (org.junit.jupiter.api.BeforeEach)13 ExtensionUninstaller (io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller)12 JsonUtil (io.stackgres.testutil.JsonUtil)12