use of io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom in project stackgres by ongres.
the class ScriptsConfigValidator method checkSecretKeySelectors.
private void checkSecretKeySelectors(StackGresClusterReview review, List<StackGresClusterScriptEntry> scripts) throws ValidationFailed {
String clusterNamespace = review.getRequest().getObject().getMetadata().getNamespace();
List<SecretKeySelector> secretKeySelectors = scripts.stream().map(StackGresClusterScriptEntry::getScriptFrom).filter(Objects::nonNull).map(StackGresClusterScriptFrom::getSecretKeyRef).filter(Objects::nonNull).collect(Collectors.toList());
for (SecretKeySelector secretRef : secretKeySelectors) {
Optional<Secret> scriptSecret = secretFinder.findByNameAndNamespace(secretRef.getName(), clusterNamespace);
if (!scriptSecret.isPresent()) {
fail(invalidReference, "Referenced Secret " + secretRef.getName() + " does not exists in namespace " + clusterNamespace);
} else if (!scriptSecret.get().getData().containsKey(secretRef.getKey())) {
fail(invalidReference, "Key " + secretRef.getKey() + " does not exists in Secret " + secretRef.getName());
}
}
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom 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);
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom in project stackgres by ongres.
the class ClusterConstraintValidatorTest method scriptFromSecretWithEmptyKey_shouldFail.
@Test
void scriptFromSecretWithEmptyKey_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().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("");
checkErrorCause(SecretKeySelector.class, "spec.initData.scripts[0].scriptFrom.secretKeyRef.key", "isKeyNotEmpty", review, AssertTrue.class);
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom 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);
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom in project stackgres by ongres.
the class ClusterConstraintValidatorTest method scriptFromSecretWithEmptyName_shouldFail.
@Test
void scriptFromSecretWithEmptyName_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().setSecretKeyRef(new SecretKeySelector());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getSecretKeyRef().setName("");
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getSecretKeyRef().setKey("test");
checkErrorCause(SecretKeySelector.class, "spec.initData.scripts[0].scriptFrom.secretKeyRef.name", "isNameNotEmpty", review, AssertTrue.class);
}
Aggregations