use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class PgConfigUpdateValidator method validate.
@Override
public void validate(PgConfigReview review) throws ValidationFailed {
if (review.getRequest().getOperation() == Operation.UPDATE) {
String oldPgVersion = review.getRequest().getOldObject().getSpec().getPostgresVersion();
String newPgVersion = review.getRequest().getObject().getSpec().getPostgresVersion();
if (!oldPgVersion.equals(newPgVersion)) {
String detail = "postgresVersion is not updatable";
Status failedStatus = new StatusBuilder().withCode(400).withKind(HasMetadata.getKind(StackGresPostgresConfig.class)).withReason(ErrorType.getErrorTypeUri(ErrorType.FORBIDDEN_CR_UPDATE)).withDetails(new StatusDetailsBuilder().addNewCause(pgVersionPath, detail, "FieldNotUpdatable").withKind(HasMetadata.getKind(StackGresPostgresConfig.class)).withGroup(CommonDefinition.GROUP).withName(pgVersionPath).build()).build();
throw new ValidationFailed(failedStatus);
}
}
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class StorageValidatorTest method givenCreationWithoutVolumeProperties_shouldFail.
@Test
void givenCreationWithoutVolumeProperties_shouldFail() {
BackupConfigReview review = JsonUtil.readFromJson("backupconfig_allow_request/invalid_creation_no_s3.json", BackupConfigReview.class);
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String errorMessage = ex.getResult().getMessage();
assertEquals("Invalid backup configuration," + " source s3 must be set when source type is s3", errorMessage);
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class BackupConfigValidatorTest method giveInvalidStackGresBackupOnCreation_shouldFail.
@Test
void giveInvalidStackGresBackupOnCreation_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
String backupConfig = review.getRequest().getObject().getSpec().getConfiguration().getBackupConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(configFinder.findByNameAndNamespace(backupConfig, namespace)).thenReturn(Optional.empty());
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = ex.getMessage();
assertEquals("Backup config " + backupConfig + " not found", resultMessage);
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class BackupConfigValidatorTest method giveAnAttemptToUpdateToAnUnknownBackupConfig_shouldFail.
@Test
void giveAnAttemptToUpdateToAnUnknownBackupConfig_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/backup_config_update.json", StackGresClusterReview.class);
String backupConfig = review.getRequest().getObject().getSpec().getConfiguration().getBackupConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(configFinder.findByNameAndNamespace(backupConfig, namespace)).thenReturn(Optional.empty());
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = ex.getMessage();
assertEquals("Cannot update to backup config " + backupConfig + " because it doesn't exists", resultMessage);
verify(configFinder).findByNameAndNamespace(eq(backupConfig), eq(namespace));
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class BackupSourceValidatorTest method giveInvalidStackGresBackupOnCreation_shouldFail.
@Test
void giveInvalidStackGresBackupOnCreation_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
String backupConfig = review.getRequest().getObject().getSpec().getConfiguration().getBackupConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(configFinder.findByNameAndNamespace(backupConfig, namespace)).thenReturn(Optional.empty());
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = ex.getMessage();
assertEquals("Backup config " + backupConfig + " not found", resultMessage);
}
Aggregations