Search in sources :

Example 1 with BackupScanner

use of io.stackgres.common.resource.BackupScanner in project stackgres by ongres.

the class ClusterRequiredResourcesGeneratorTest method givenValidCluster_getRequiredResourcesAllReturnedResourcesShouldHaveTheOwnerReference.

@Test
void givenValidCluster_getRequiredResourcesAllReturnedResourcesShouldHaveTheOwnerReference() {
    final ObjectMeta metadata = cluster.getMetadata();
    final String clusterNamespace = metadata.getNamespace();
    final StackGresClusterSpec clusterSpec = cluster.getSpec();
    final StackGresClusterConfiguration clusterConfiguration = clusterSpec.getConfiguration();
    final String backupConfigName = clusterConfiguration.getBackupConfig();
    mockBackupConfig(clusterNamespace, backupConfigName);
    final String postgresConfigName = clusterConfiguration.getPostgresConfig();
    mockPgConfig(clusterNamespace, postgresConfigName);
    final String connectionPoolingConfig = clusterConfiguration.getConnectionPoolingConfig();
    mockPoolingConfig(clusterNamespace, connectionPoolingConfig);
    final String resourceProfile = clusterSpec.getResourceProfile();
    when(profileConfigFinder.findByNameAndNamespace(resourceProfile, clusterNamespace)).thenReturn(Optional.of(instanceProfile));
    when(backupScanner.getResources()).thenReturn(backups);
    mockSecrets(clusterNamespace);
    List<HasMetadata> resources = generator.getRequiredResources(cluster);
    resources.forEach(resource -> {
        assertNotNull(resource.getMetadata().getOwnerReferences(), "Resource " + resource.getMetadata().getName() + " doesn't owner references");
        if (resource.getMetadata().getOwnerReferences().size() == 0) {
            fail("Resource " + resource.getMetadata().getName() + " doesn't have any owner");
        }
        assertTrue(resource.getMetadata().getOwnerReferences().stream().anyMatch(ownerReference -> ownerReference.getApiVersion().equals(HasMetadata.getApiVersion(StackGresCluster.class)) && ownerReference.getKind().equals(HasMetadata.getKind(StackGresCluster.class)) && ownerReference.getName().equals(cluster.getMetadata().getName()) && ownerReference.getUid().equals(cluster.getMetadata().getUid()) && Optional.ofNullable(ownerReference.getBlockOwnerDeletion()).orElse(Boolean.FALSE).equals(Boolean.FALSE)));
    });
    verify(backupConfigFinder).findByNameAndNamespace(backupConfigName, clusterNamespace);
    verify(postgresConfigFinder).findByNameAndNamespace(postgresConfigName, clusterNamespace);
    verify(poolingConfigFinder).findByNameAndNamespace(connectionPoolingConfig, clusterNamespace);
    verify(profileConfigFinder).findByNameAndNamespace(resourceProfile, clusterNamespace);
    verify(backupScanner, atLeastOnce()).getResources();
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StackGresBackupList(io.stackgres.common.crd.sgbackup.StackGresBackupList) BeforeEach(org.junit.jupiter.api.BeforeEach) PoolingConfigFinder(io.stackgres.common.resource.PoolingConfigFinder) StackGresPostgresConfigStatus(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfigStatus) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) StackGresBackup(io.stackgres.common.crd.sgbackup.StackGresBackup) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresPoolingConfigStatus(io.stackgres.common.crd.sgpooling.StackGresPoolingConfigStatus) StackGresPostgresConfig(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig) PrometheusConfigList(io.stackgres.operator.customresource.prometheus.PrometheusConfigList) QuarkusTest(io.quarkus.test.junit.QuarkusTest) ServiceMonitor(io.stackgres.operator.customresource.prometheus.ServiceMonitor) Inject(javax.inject.Inject) StackGresClusterRestoreFromBackup(io.stackgres.common.crd.sgcluster.StackGresClusterRestoreFromBackup) ProfileConfigFinder(io.stackgres.common.resource.ProfileConfigFinder) SecretFinder(io.stackgres.common.resource.SecretFinder) BackupScanner(io.stackgres.common.resource.BackupScanner) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) InjectMock(io.quarkus.test.junit.mockito.InjectMock) StackGresBackupConfig(io.stackgres.common.crd.sgbackupconfig.StackGresBackupConfig) PgBouncerDefaultValues(io.stackgres.operator.conciliation.factory.cluster.sidecars.pooling.parameters.PgBouncerDefaultValues) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) StackGresPoolingConfig(io.stackgres.common.crd.sgpooling.StackGresPoolingConfig) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StackGresProfile(io.stackgres.common.crd.sgprofile.StackGresProfile) JsonUtil(io.stackgres.testutil.JsonUtil) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) StackGresComponent(io.stackgres.common.StackGresComponent) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) Mockito.never(org.mockito.Mockito.never) List(java.util.List) BackupConfigFinder(io.stackgres.common.resource.BackupConfigFinder) StackGresPoolingConfigPgBouncerStatus(io.stackgres.common.crd.sgpooling.StackGresPoolingConfigPgBouncerStatus) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PostgresDefaultValues(io.stackgres.operator.conciliation.factory.cluster.patroni.parameters.PostgresDefaultValues) Optional(java.util.Optional) Secret(io.fabric8.kubernetes.api.model.Secret) PostgresConfigFinder(io.stackgres.common.resource.PostgresConfigFinder) PrometheusScanner(io.stackgres.operator.resource.PrometheusScanner) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)1 Secret (io.fabric8.kubernetes.api.model.Secret)1 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 InjectMock (io.quarkus.test.junit.mockito.InjectMock)1 StackGresComponent (io.stackgres.common.StackGresComponent)1 StackGresBackup (io.stackgres.common.crd.sgbackup.StackGresBackup)1 StackGresBackupList (io.stackgres.common.crd.sgbackup.StackGresBackupList)1 StackGresBackupConfig (io.stackgres.common.crd.sgbackupconfig.StackGresBackupConfig)1 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)1 StackGresClusterConfiguration (io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration)1 StackGresClusterRestoreFromBackup (io.stackgres.common.crd.sgcluster.StackGresClusterRestoreFromBackup)1 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)1 StackGresPostgresConfig (io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig)1 StackGresPostgresConfigStatus (io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfigStatus)1 StackGresPoolingConfig (io.stackgres.common.crd.sgpooling.StackGresPoolingConfig)1 StackGresPoolingConfigPgBouncerStatus (io.stackgres.common.crd.sgpooling.StackGresPoolingConfigPgBouncerStatus)1 StackGresPoolingConfigStatus (io.stackgres.common.crd.sgpooling.StackGresPoolingConfigStatus)1 StackGresProfile (io.stackgres.common.crd.sgprofile.StackGresProfile)1 BackupConfigFinder (io.stackgres.common.resource.BackupConfigFinder)1