Search in sources :

Example 6 with StackGresCluster

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);
    }
}
Also used : StackGresBackup(io.stackgres.common.crd.sgbackup.StackGresBackup) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster)

Example 7 with StackGresCluster

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);
        }
    }
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresBackupConfig(io.stackgres.common.crd.sgbackupconfig.StackGresBackupConfig)

Example 8 with StackGresCluster

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);
    }
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresProfile(io.stackgres.common.crd.sgprofile.StackGresProfile)

Example 9 with StackGresCluster

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();
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster)

Example 10 with StackGresCluster

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();
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterRestore(io.stackgres.common.crd.sgcluster.StackGresClusterRestore) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)127 Test (org.junit.jupiter.api.Test)48 Optional (java.util.Optional)32 List (java.util.List)31 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)27 StackGresClusterInstalledExtension (io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension)25 ImmutableList (com.google.common.collect.ImmutableList)24 Inject (javax.inject.Inject)22 ArrayList (java.util.ArrayList)19 StackGresClusterStatus (io.stackgres.common.crd.sgcluster.StackGresClusterStatus)18 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)15 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)15 StackGresComponent (io.stackgres.common.StackGresComponent)15 StackGresClusterPodStatus (io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus)14 ExtensionInstaller (io.stackgres.common.extension.ExtensionManager.ExtensionInstaller)14 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)13 Collectors (java.util.stream.Collectors)13 BeforeEach (org.junit.jupiter.api.BeforeEach)13 ExtensionUninstaller (io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller)12 JsonUtil (io.stackgres.testutil.JsonUtil)12