Search in sources :

Example 6 with ConfigMapKeySelector

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

the class ClusterConstraintValidatorTest method validScriptFromConfigMap_shouldPass.

@Test
void validScriptFromConfigMap_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().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");
    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) 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 7 with ConfigMapKeySelector

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

the class ClusterConstraintValidatorTest method validScriptAndScriptFrom_shouldFail.

@Test
void validScriptAndScriptFrom_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).setScript("SELECT 1");
    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");
    checkErrorCause(StackGresClusterScriptEntry.class, new String[] { "spec.initData.scripts[0].script", "spec.initData.scripts[0].scriptFrom" }, "isScriptMutuallyExclusiveAndRequired", 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 8 with ConfigMapKeySelector

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

the class ClusterConstraintValidatorTest method scriptFromConfigMapWithEmptyKey_shouldFail.

@Test
void scriptFromConfigMapWithEmptyKey_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("");
    checkErrorCause(SecretKeySelector.class, "spec.initData.scripts[0].scriptFrom.configMapKeyRef.key", "isKeyNotEmpty", 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 9 with ConfigMapKeySelector

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

the class ScriptsConfigValidatorTest method prepareForConfigMap.

private void prepareForConfigMap(StackGresClusterReview review, String name, String key) {
    review.getRequest().getObject().getSpec().getInitData().getScripts().forEach(s -> {
        s.setName(null);
        s.setScript(null);
        s.setDatabase(null);
        s.setScriptFrom(new StackGresClusterScriptFrom());
        s.getScriptFrom().setConfigMapKeyRef(new ConfigMapKeySelector(key, name));
    });
}
Also used : StackGresClusterScriptFrom(io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom) ConfigMapKeySelector(io.stackgres.common.crd.ConfigMapKeySelector)

Example 10 with ConfigMapKeySelector

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

the class ClusterResourceMockedTest method createClusterWithConfigMapScriptReference_shouldNotFail.

@Test
void createClusterWithConfigMapScriptReference_shouldNotFail() {
    dto = getClusterInlineScripts();
    ClusterScriptEntry entry = buildConfigMapScriptEntry();
    dto.getSpec().getInitData().setScripts(Collections.singletonList(entry));
    doNothing().when(configMapTransactionHandler).create(any(ConfigMap.class), any(Runnable.class));
    super.createShouldNotFail();
    ArgumentCaptor<ConfigMap> secretArgument = ArgumentCaptor.forClass(ConfigMap.class);
    verify(configMapTransactionHandler).create(secretArgument.capture(), any(Runnable.class));
    ConfigMap createdSecret = secretArgument.getValue();
    assertEquals(dto.getMetadata().getNamespace(), createdSecret.getMetadata().getNamespace());
    final ClusterScriptFrom scriptFrom = entry.getScriptFrom();
    final ConfigMapKeySelector configMapKeyRef = scriptFrom.getConfigMapKeyRef();
    assertEquals(configMapKeyRef.getName(), createdSecret.getMetadata().getName());
    assertTrue(createdSecret.getData().containsKey(configMapKeyRef.getKey()));
    assertEquals(scriptFrom.getConfigMapScript(), createdSecret.getData().get(configMapKeyRef.getKey()));
}
Also used : StackGresClusterScriptEntry(io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry) ClusterScriptEntry(io.stackgres.apiweb.dto.cluster.ClusterScriptEntry) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) StackGresClusterScriptFrom(io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom) ClusterScriptFrom(io.stackgres.apiweb.dto.cluster.ClusterScriptFrom) ConfigMapKeySelector(io.stackgres.common.crd.ConfigMapKeySelector) Test(org.junit.jupiter.api.Test)

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