use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ClusterValidator method checkIfClusterExists.
private void checkIfClusterExists(BackupReview review, String onError) throws ValidationFailed {
StackGresBackup backup = review.getRequest().getObject();
String cluster = backup.getSpec().getSgCluster();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
Optional<StackGresCluster> clusterOpt = clusterFinder.findByNameAndNamespace(cluster, namespace);
if (!clusterOpt.isPresent()) {
fail(onError);
}
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class BackupConfigValidator method checkIfBackupConfigExists.
private void checkIfBackupConfigExists(StackGresClusterReview review, String onError) throws ValidationFailed {
StackGresCluster cluster = review.getRequest().getObject();
String backupConfig = cluster.getSpec().getConfiguration().getBackupConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
if (backupConfig != null) {
Optional<StackGresBackupConfig> backupConfigOpt = configFinder.findByNameAndNamespace(backupConfig, namespace);
if (!backupConfigOpt.isPresent()) {
fail(onError);
}
}
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ProfileReferenceValidator method checkIfProfileExists.
private void checkIfProfileExists(StackGresClusterReview review, String onError) throws ValidationFailed {
StackGresCluster cluster = review.getRequest().getObject();
String resourceProfile = cluster.getSpec().getResourceProfile();
String namespace = cluster.getMetadata().getNamespace();
Optional<StackGresProfile> profileOpt = profileFinder.findByNameAndNamespace(resourceProfile, namespace);
if (!profileOpt.isPresent()) {
fail(onError);
}
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class AbstractDefaultResourceMutator method mutate.
@Override
public List<JsonPatchOperation> mutate(StackGresClusterReview review) {
if (review.getRequest().getOperation() == Operation.CREATE) {
T defaultResource = resourceFactory.buildResource();
StackGresCluster targetCluster = review.getRequest().getObject();
String targetNamespace = targetCluster.getMetadata().getNamespace();
String defaultResourceName = defaultResource.getMetadata().getName();
if (applyDefault(targetCluster)) {
if (!finder.findByNameAndNamespace(defaultResourceName, targetNamespace).isPresent()) {
defaultResource.getMetadata().setNamespace(targetNamespace);
scheduler.create(defaultResource);
}
return Collections.singletonList(buildAddOperation(targetPointer, defaultResourceName));
}
}
return Collections.emptyList();
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class RestoreConfigValidatorTest method givenAInvalidCreation_shouldFail.
@Test
void givenAInvalidCreation_shouldFail() {
final StackGresClusterReview review = getCreationReview();
StackGresCluster cluster = review.getRequest().getObject();
StackGresClusterRestore restoreConfig = cluster.getSpec().getInitData().getRestore();
String stackgresBackup = restoreConfig.getFromBackup().getUid();
when(scanner.findResources()).thenReturn(Optional.empty());
ValidationUtils.assertValidationFailed(() -> validator.validate(review), "Backup uid " + stackgresBackup + " not found");
verify(scanner).findResources();
}
Aggregations