Search in sources :

Example 1 with ConfigMapKeySelector

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

the class ClusterConstraintValidatorTest method scriptFromConfigMapWithEmptyName_shouldFail.

@Test
void scriptFromConfigMapWithEmptyName_shouldFail() {
    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().setConfigMapKeyRef(new ConfigMapKeySelector());
    review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setName("");
    review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setKey("test");
    checkErrorCause(SecretKeySelector.class, "spec.initData.scripts[0].scriptFrom.configMapKeyRef.name", "isNameNotEmpty", review, AssertTrue.class);
}
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) ConfigMapKeySelector(io.stackgres.common.crd.ConfigMapKeySelector) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ConfigMapKeySelector

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

the class ClusterResourceMockedTest method buildConfigMapScriptEntry.

private ClusterScriptEntry buildConfigMapScriptEntry() {
    ClusterScriptEntry entry = new ClusterScriptEntry();
    entry.setScript(null);
    final ClusterScriptFrom scriptFrom = new ClusterScriptFrom();
    entry.setScriptFrom(scriptFrom);
    scriptFrom.setConfigMapScript("CREATE DATABASE test");
    final ConfigMapKeySelector configMapKeyRef = new ConfigMapKeySelector();
    scriptFrom.setConfigMapKeyRef(configMapKeyRef);
    final String randomKey = StringUtil.generateRandom(30);
    final String randomSecretName = StringUtil.generateRandom(30);
    configMapKeyRef.setKey(randomKey);
    configMapKeyRef.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) ConfigMapKeySelector(io.stackgres.common.crd.ConfigMapKeySelector)

Example 3 with ConfigMapKeySelector

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

the class ClusterResourceQuarkusTest method getConfigMapScriptEntry.

private ClusterScriptEntry getConfigMapScriptEntry() {
    ClusterScriptEntry entry = new ClusterScriptEntry();
    entry.setName("init");
    final ClusterScriptFrom scriptFrom = new ClusterScriptFrom();
    scriptFrom.setConfigMapScript("CREATE DATABASE test");
    final ConfigMapKeySelector configMapKeyRef = new ConfigMapKeySelector();
    scriptFrom.setConfigMapKeyRef(configMapKeyRef);
    configMapKeyRef.setKey("script");
    configMapKeyRef.setName("initScript");
    entry.setScriptFrom(scriptFrom);
    return entry;
}
Also used : ClusterScriptEntry(io.stackgres.apiweb.dto.cluster.ClusterScriptEntry) ClusterScriptFrom(io.stackgres.apiweb.dto.cluster.ClusterScriptFrom) ConfigMapKeySelector(io.stackgres.common.crd.ConfigMapKeySelector)

Example 4 with ConfigMapKeySelector

use of io.stackgres.common.crd.ConfigMapKeySelector 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 ConfigMapKeySelector

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

the class ClusterConstraintValidatorTest method validScriptFromConfigMapAndSecret_shouldFail.

@Test
void validScriptFromConfigMapAndSecret_shouldFail() {
    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().setConfigMapKeyRef(new ConfigMapKeySelector());
    review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setName("test");
    review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setKey("test");
    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");
    checkErrorCause(StackGresClusterScriptFrom.class, new String[] { "spec.initData.scripts[0].scriptFrom.secretKeyRef", "spec.initData.scripts[0].scriptFrom.configMapKeyRef" }, "isSecretKeySelectorAndConfigMapKeySelectorMutuallyExclusiveAndRequired", review, AssertTrue.class);
}
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) ConfigMapKeySelector(io.stackgres.common.crd.ConfigMapKeySelector) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ConfigMapKeySelector (io.stackgres.common.crd.ConfigMapKeySelector)11 StackGresClusterScriptFrom (io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom)9 StackGresClusterScriptEntry (io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry)8 Test (org.junit.jupiter.api.Test)7 StackGresClusterInitData (io.stackgres.common.crd.sgcluster.StackGresClusterInitData)6 ClusterScriptEntry (io.stackgres.apiweb.dto.cluster.ClusterScriptEntry)5 ClusterScriptFrom (io.stackgres.apiweb.dto.cluster.ClusterScriptFrom)5 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)5 ConstraintValidationTest (io.stackgres.operator.validation.ConstraintValidationTest)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 SecretKeySelector (io.stackgres.common.crd.SecretKeySelector)3 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 Metadata (io.stackgres.apiweb.dto.Metadata)2 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)1 Secret (io.fabric8.kubernetes.api.model.Secret)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 ClusterConfiguration (io.stackgres.apiweb.dto.cluster.ClusterConfiguration)1 ClusterDto (io.stackgres.apiweb.dto.cluster.ClusterDto)1 ClusterInitData (io.stackgres.apiweb.dto.cluster.ClusterInitData)1