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);
}
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;
}
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;
}
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()));
}
}
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);
}
Aggregations