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