use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ScriptsConfigValidatorTest method givenACreationUsingScriptFromNonexistentSecretKey_shouldFail.
@Test
void givenACreationUsingScriptFromNonexistentSecretKey_shouldFail() {
final StackGresClusterReview review = getCreationReview();
String randomSecretKey = StringUtil.generateRandom();
String randomSecretName = StringUtil.generateRandom();
final StackGresCluster cluster = review.getRequest().getObject();
prepareForSecret(review, randomSecretName, randomSecretKey);
final String namespace = cluster.getMetadata().getNamespace();
when(secretFinder.findByNameAndNamespace(randomSecretName, namespace)).thenReturn(Optional.of(new SecretBuilder().withNewMetadata().withName(randomSecretName).withNamespace(namespace).endMetadata().withData(ImmutableMap.of()).build()));
ValidationUtils.assertValidationFailed(() -> validator.validate(review), ErrorType.INVALID_CR_REFERENCE, "Key " + randomSecretKey + " does not exists in Secret " + randomSecretName);
verify(secretFinder).findByNameAndNamespace(randomSecretName, namespace);
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ScriptsConfigValidatorTest method givenACreationUsingScriptFromNonexistentSecret_shouldFail.
@Test
void givenACreationUsingScriptFromNonexistentSecret_shouldFail() {
final StackGresClusterReview review = getCreationReview();
String randomSecretKey = StringUtil.generateRandom();
String randomSecretName = StringUtil.generateRandom();
final StackGresCluster cluster = review.getRequest().getObject();
prepareForSecret(review, randomSecretName, randomSecretKey);
final String namespace = cluster.getMetadata().getNamespace();
when(secretFinder.findByNameAndNamespace(randomSecretName, namespace)).thenReturn(Optional.empty());
ValidationUtils.assertValidationFailed(() -> validator.validate(review), ErrorType.INVALID_CR_REFERENCE, "Referenced Secret " + randomSecretName + " does not exists in namespace " + namespace);
verify(secretFinder).findByNameAndNamespace(randomSecretName, namespace);
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ScriptsConfigValidatorTest method givenACreationUsingScriptsFromPlainConfigMap_shouldValidateConfigMapReference.
@Test
void givenACreationUsingScriptsFromPlainConfigMap_shouldValidateConfigMapReference() throws ValidationFailed {
final StackGresClusterReview review = getCreationReview();
String randomConfigMapName = StringUtil.generateRandom();
String randomConfigMapKey = StringUtil.generateRandom();
prepareForConfigMap(review, randomConfigMapName, randomConfigMapKey);
final StackGresCluster cluster = review.getRequest().getObject();
final String namespace = cluster.getMetadata().getNamespace();
when(configMapFinder.findByNameAndNamespace(randomConfigMapName, namespace)).thenReturn(Optional.of(new ConfigMapBuilder().withNewMetadata().withName(randomConfigMapName).withNamespace(namespace).endMetadata().withData(ImmutableMap.of(randomConfigMapKey, "CREATE DATABASE test;")).build()));
validator.validate(review);
final List<StackGresClusterScriptEntry> scripts = cluster.getSpec().getInitData().getScripts();
verify(configMapFinder, times(scripts.size())).findByNameAndNamespace(randomConfigMapName, namespace);
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ClusterValidationQuarkusTest method given_invalidStackGresClusterLongName_shouldFail.
@Test
void given_invalidStackGresClusterLongName_shouldFail() {
StackGresClusterReview clusterReview = getConstraintClusterReview();
StackGresCluster cluster = clusterReview.getRequest().getObject();
cluster.getMetadata().setName("husked-condition-calculus-ridden-pancreas-heave-extented");
RestAssured.given().body(clusterReview).contentType(ContentType.JSON).accept(ContentType.JSON).post(ValidationUtil.CLUSTER_VALIDATION_PATH).then().body("response.allowed", is(false), "kind", is("AdmissionReview"), "response.status.code", is(422), "response.status.message", is("Valid name must be 53 characters or less")).statusCode(200);
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ClusterControllerReconciliator method reconcile.
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "False positives")
@Override
protected ReconciliationResult<?> reconcile(KubernetesClient client, StackGresClusterContext context) throws Exception {
ReconciliationResult<Boolean> extensionReconciliationResult = extensionReconciliator.reconcile(client, context);
if (extensionReconciliationResult.result().orElse(false)) {
final String podName = propertyContext.getString(ClusterControllerProperty.CLUSTER_CONTROLLER_POD_NAME);
final StackGresCluster cluster = context.getCluster();
final StackGresClusterStatus status = cluster.getStatus();
String clusterName = cluster.getMetadata().getName();
String namespace = cluster.getMetadata().getNamespace();
clusterFinder.findByNameAndNamespace(clusterName, namespace).ifPresent(savedCluster -> {
var newPodStatus = findPodStatus(status.getPodStatuses(), podName).orElseThrow();
Optional.ofNullable(savedCluster.getStatus()).ifPresentOrElse(savedStatus -> Optional.ofNullable(savedStatus.getPodStatuses()).ifPresentOrElse(savedPodStatuses -> findPodStatus(savedPodStatuses, podName).ifPresentOrElse(savedPodStatus -> applyPodStatusChanges(newPodStatus, savedPodStatus), () -> savedPodStatuses.add(newPodStatus)), () -> savedStatus.setPodStatuses(status.getPodStatuses())), () -> savedCluster.setStatus(status));
clusterScheduler.updateStatus(savedCluster);
});
}
return extensionReconciliationResult;
}
Aggregations