Search in sources :

Example 1 with SecretKeySelector

use of io.stackgres.common.crd.SecretKeySelector in project stackgres by ongres.

the class ClusterConstraintValidatorTest method validScriptFromSecret_shouldPass.

@Test
void validScriptFromSecret_shouldPass() throws ValidationFailed {
    StackGresClusterReview review = getValidReview();
    review.getRequest().getObject().getSpec().setInitData(new StackGresClusterInitData());
    review.getRequest().getObject().getSpec().getInitData().setScripts(new ArrayList<>());
    review.getRequest().getObject().getSpec().getInitData().getScripts().add(new StackGresClusterScriptEntry());
    review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).setScriptFrom(new StackGresClusterScriptFrom());
    review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().setSecretKeyRef(new SecretKeySelector());
    review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getSecretKeyRef().setName("test");
    review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getSecretKeyRef().setKey("test");
    validator.validate(review);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterScriptEntry(io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry) StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) StackGresClusterScriptFrom(io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom) SecretKeySelector(io.stackgres.common.crd.SecretKeySelector) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with SecretKeySelector

use of io.stackgres.common.crd.SecretKeySelector in project stackgres by ongres.

the class ClusterConstraintValidatorTest method sslPrivateKeySecretNull_shouldFail.

@Test
void sslPrivateKeySecretNull_shouldFail() {
    StackGresClusterReview review = getValidReview();
    review.getRequest().getObject().getSpec().getPostgres().setSsl(new StackGresClusterSsl());
    review.getRequest().getObject().getSpec().getPostgres().getSsl().setEnabled(true);
    review.getRequest().getObject().getSpec().getPostgres().getSsl().setCertificateSecretKeySelector(new SecretKeySelector("test", "test"));
    checkErrorCause(StackGresClusterSsl.class, "spec.postgres.ssl.privateKeySecretKeySelector", "isNotEnabledSecretKeySecretKeySelectorRequired", review, AssertTrue.class);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterSsl(io.stackgres.common.crd.sgcluster.StackGresClusterSsl) SecretKeySelector(io.stackgres.common.crd.SecretKeySelector) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with SecretKeySelector

use of io.stackgres.common.crd.SecretKeySelector in project stackgres by ongres.

the class ClusterResourceMockedTest method buildSecretScriptEntry.

private ClusterScriptEntry buildSecretScriptEntry() {
    ClusterScriptEntry entry = new ClusterScriptEntry();
    entry.setScript(null);
    final ClusterScriptFrom scriptFrom = new ClusterScriptFrom();
    entry.setScriptFrom(scriptFrom);
    scriptFrom.setSecretScript("CREATE DATABASE test");
    final SecretKeySelector secretKeyRef = new SecretKeySelector();
    scriptFrom.setSecretKeyRef(secretKeyRef);
    final String randomKey = StringUtil.generateRandom(30);
    final String randomSecretName = StringUtil.generateRandom(30);
    secretKeyRef.setKey(randomKey);
    secretKeyRef.setName(randomSecretName);
    return entry;
}
Also used : StackGresClusterScriptEntry(io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry) ClusterScriptEntry(io.stackgres.apiweb.dto.cluster.ClusterScriptEntry) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackGresClusterScriptFrom(io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom) ClusterScriptFrom(io.stackgres.apiweb.dto.cluster.ClusterScriptFrom) SecretKeySelector(io.stackgres.common.crd.SecretKeySelector)

Example 4 with SecretKeySelector

use of io.stackgres.common.crd.SecretKeySelector in project stackgres by ongres.

the class ClusterResourceQuarkusTest method givenACreationWithSecretAndConfigMapScripts_shouldNotFail.

@Test
void givenACreationWithSecretAndConfigMapScripts_shouldNotFail() {
    ClusterDto cluster = getClusterInlineScripts();
    ClusterScriptEntry secretScriptEntry = getSecretScriptEntry();
    ClusterScriptEntry configMapScriptEntry = getConfigMapScriptEntry();
    cluster.getSpec().getInitData().setScripts(ImmutableList.of(secretScriptEntry, configMapScriptEntry));
    final Metadata metadata = cluster.getMetadata();
    metadata.setNamespace("test");
    given().header(AUTHENTICATION_HEADER).body(cluster).contentType(ContentType.JSON).accept(ContentType.JSON).post("/stackgres/sgclusters").then().statusCode(204);
    try (KubernetesClient client = factory.create()) {
        final ClusterScriptFrom secretScriptFrom = secretScriptEntry.getScriptFrom();
        final SecretKeySelector secretKeyRef = secretScriptFrom.getSecretKeyRef();
        Secret secret = client.secrets().inNamespace("test").withName(secretKeyRef.getName()).get();
        assertNotNull(secret);
        byte[] actualScript = Base64.getDecoder().decode(secret.getData().get(secretKeyRef.getKey()));
        assertEquals(secretScriptFrom.getSecretScript(), new String(actualScript, StandardCharsets.UTF_8));
        final ClusterScriptFrom configMapScriptFrom = configMapScriptEntry.getScriptFrom();
        final ConfigMapKeySelector configMapKeyRef = configMapScriptFrom.getConfigMapKeyRef();
        ConfigMap configMap = client.configMaps().inNamespace("test").withName(configMapKeyRef.getName()).get();
        assertNotNull(configMap);
        assertEquals(configMapScriptFrom.getConfigMapScript(), configMap.getData().get(configMapKeyRef.getKey()));
    }
}
Also used : ClusterScriptEntry(io.stackgres.apiweb.dto.cluster.ClusterScriptEntry) Secret(io.fabric8.kubernetes.api.model.Secret) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ClusterDto(io.stackgres.apiweb.dto.cluster.ClusterDto) Metadata(io.stackgres.apiweb.dto.Metadata) ClusterScriptFrom(io.stackgres.apiweb.dto.cluster.ClusterScriptFrom) SecretKeySelector(io.stackgres.common.crd.SecretKeySelector) ConfigMapKeySelector(io.stackgres.common.crd.ConfigMapKeySelector) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 5 with SecretKeySelector

use of io.stackgres.common.crd.SecretKeySelector in project stackgres by ongres.

the class SslValidatorTest method prepareForSsl.

private void prepareForSsl(StackGresClusterReview review) {
    review.getRequest().getObject().getSpec().setPostgres(new StackGresClusterPostgres());
    review.getRequest().getObject().getSpec().getPostgres().setSsl(new StackGresClusterSsl());
    review.getRequest().getObject().getSpec().getPostgres().getSsl().setEnabled(true);
    review.getRequest().getObject().getSpec().getPostgres().getSsl().setCertificateSecretKeySelector(new SecretKeySelector());
    review.getRequest().getObject().getSpec().getPostgres().getSsl().getCertificateSecretKeySelector().setName("secret1");
    review.getRequest().getObject().getSpec().getPostgres().getSsl().getCertificateSecretKeySelector().setKey("test");
    review.getRequest().getObject().getSpec().getPostgres().getSsl().setPrivateKeySecretKeySelector(new SecretKeySelector());
    review.getRequest().getObject().getSpec().getPostgres().getSsl().getPrivateKeySecretKeySelector().setName("secret2");
    review.getRequest().getObject().getSpec().getPostgres().getSsl().getPrivateKeySecretKeySelector().setKey("test");
}
Also used : StackGresClusterSsl(io.stackgres.common.crd.sgcluster.StackGresClusterSsl) StackGresClusterPostgres(io.stackgres.common.crd.sgcluster.StackGresClusterPostgres) SecretKeySelector(io.stackgres.common.crd.SecretKeySelector)

Aggregations

SecretKeySelector (io.stackgres.common.crd.SecretKeySelector)21 Test (org.junit.jupiter.api.Test)12 StackGresClusterScriptFrom (io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom)9 StackGresClusterScriptEntry (io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry)8 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)8 ConstraintValidationTest (io.stackgres.operator.validation.ConstraintValidationTest)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 ClusterScriptEntry (io.stackgres.apiweb.dto.cluster.ClusterScriptEntry)7 ClusterScriptFrom (io.stackgres.apiweb.dto.cluster.ClusterScriptFrom)7 StackGresClusterInitData (io.stackgres.common.crd.sgcluster.StackGresClusterInitData)5 StackGresClusterSsl (io.stackgres.common.crd.sgcluster.StackGresClusterSsl)5 Secret (io.fabric8.kubernetes.api.model.Secret)4 AwsSecretKeySelector (io.stackgres.common.crd.storages.AwsSecretKeySelector)4 AzureBlobSecretKeySelector (io.stackgres.common.crd.storages.AzureBlobSecretKeySelector)4 BackupStorage (io.stackgres.common.crd.storages.BackupStorage)4 GoogleCloudSecretKeySelector (io.stackgres.common.crd.storages.GoogleCloudSecretKeySelector)4 Metadata (io.stackgres.apiweb.dto.Metadata)3 ConfigMapKeySelector (io.stackgres.common.crd.ConfigMapKeySelector)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2