Search in sources :

Example 1 with StackGresClusterStatus

use of io.stackgres.common.crd.sgcluster.StackGresClusterStatus in project stackgres by ongres.

the class ClusterRestartStateHandlerImplTest method initializeClusterStatus.

@Override
protected void initializeClusterStatus(StackGresCluster cluster, List<Pod> pods) {
    final StackGresClusterStatus status = new StackGresClusterStatus();
    final StackGresClusterDbOpsStatus dbOps = new StackGresClusterDbOpsStatus();
    final StackGresClusterDbOpsRestartStatus restartStatus = new StackGresClusterDbOpsRestartStatus();
    restartStatus.setInitialInstances(pods.stream().map(Pod::getMetadata).map(ObjectMeta::getName).collect(Collectors.toList()));
    restartStatus.setPrimaryInstance(getPrimaryInstance(pods).getMetadata().getName());
    dbOps.setRestart(restartStatus);
    status.setDbOps(dbOps);
    cluster.setStatus(status);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) StackGresClusterDbOpsStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus) StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus) StackGresClusterDbOpsRestartStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsRestartStatus)

Example 2 with StackGresClusterStatus

use of io.stackgres.common.crd.sgcluster.StackGresClusterStatus in project stackgres by ongres.

the class MinorVersionUpgradeRestartStateHandlerImplTest method initializeClusterStatus.

@Override
protected void initializeClusterStatus(StackGresCluster cluster, List<Pod> pods) {
    final StackGresClusterStatus status = new StackGresClusterStatus();
    final StackGresClusterDbOpsStatus dbOps = new StackGresClusterDbOpsStatus();
    final StackGresClusterDbOpsMinorVersionUpgradeStatus minorVersionUpgrade = new StackGresClusterDbOpsMinorVersionUpgradeStatus();
    minorVersionUpgrade.setInitialInstances(pods.stream().map(Pod::getMetadata).map(ObjectMeta::getName).collect(Collectors.toList()));
    minorVersionUpgrade.setPrimaryInstance(getPrimaryInstance(pods).getMetadata().getName());
    minorVersionUpgrade.setSourcePostgresVersion("11.6");
    minorVersionUpgrade.setTargetPostgresVersion(cluster.getSpec().getPostgres().getVersion());
    dbOps.setMinorVersionUpgrade(minorVersionUpgrade);
    status.setDbOps(dbOps);
    cluster.setStatus(status);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) StackGresClusterDbOpsStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus) StackGresClusterDbOpsMinorVersionUpgradeStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsMinorVersionUpgradeStatus) StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus)

Example 3 with StackGresClusterStatus

use of io.stackgres.common.crd.sgcluster.StackGresClusterStatus in project stackgres by ongres.

the class ClusterRestartStateHandlerImplTest method initializeClusterStatus.

@Override
protected void initializeClusterStatus(StackGresCluster cluster, List<Pod> pods) {
    final StackGresClusterStatus status = new StackGresClusterStatus();
    final StackGresClusterDbOpsStatus dbOps = new StackGresClusterDbOpsStatus();
    final StackGresClusterDbOpsSecurityUpgradeStatus securityUpgrade = new StackGresClusterDbOpsSecurityUpgradeStatus();
    securityUpgrade.setInitialInstances(pods.stream().map(Pod::getMetadata).map(ObjectMeta::getName).collect(Collectors.toList()));
    securityUpgrade.setPrimaryInstance(getPrimaryInstance(pods).getMetadata().getName());
    dbOps.setSecurityUpgrade(securityUpgrade);
    status.setDbOps(dbOps);
    cluster.setStatus(status);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) StackGresClusterDbOpsStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus) StackGresClusterDbOpsSecurityUpgradeStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsSecurityUpgradeStatus) StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus)

Example 4 with StackGresClusterStatus

use of io.stackgres.common.crd.sgcluster.StackGresClusterStatus 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;
}
Also used : StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus) ClusterControllerProperty(io.stackgres.common.ClusterControllerProperty) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ReconciliationResult(io.stackgres.operatorframework.reconciliation.ReconciliationResult) Reconciliator(io.stackgres.operatorframework.reconciliation.Reconciliator) ClusterControllerPropertyContext(io.stackgres.cluster.configuration.ClusterControllerPropertyContext) Inject(javax.inject.Inject) CdiUtil(io.stackgres.common.CdiUtil) List(java.util.List) Dependent(javax.enterprise.context.Dependent) CustomResourceScheduler(io.stackgres.common.resource.CustomResourceScheduler) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Optional(java.util.Optional) CustomResourceFinder(io.stackgres.common.resource.CustomResourceFinder) ApplicationScoped(javax.enterprise.context.ApplicationScoped) StackGresClusterContext(io.stackgres.cluster.common.StackGresClusterContext) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) StackGresClusterPodStatus(io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 5 with StackGresClusterStatus

use of io.stackgres.common.crd.sgcluster.StackGresClusterStatus in project stackgres by ongres.

the class ExtensionReconciliationTest method testInitReconciliationWithInstalledExtensions_uninstallIsPerformed.

@Test
void testInitReconciliationWithInstalledExtensions_uninstallIsPerformed() throws Exception {
    StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
    ExtensionReconciliatorContext context = getContext(cluster -> {
        cluster.getSpec().getPostgres().setExtensions(null);
        cluster.setStatus(new StackGresClusterStatus());
        cluster.getStatus().setPodStatuses(new ArrayList<>());
        StackGresClusterPodStatus podStatus = new StackGresClusterPodStatus();
        podStatus.setName("test-0");
        podStatus.setInstalledPostgresExtensions(new ArrayList<>());
        podStatus.getInstalledPostgresExtensions().add(installedExtension);
        cluster.getStatus().getPodStatuses().add(podStatus);
    });
    when(extensionManager.getExtensionUninstaller(any(), any(StackGresClusterInstalledExtension.class))).thenReturn(extensionUninstaller);
    when(extensionUninstaller.isExtensionInstalled()).thenReturn(true);
    doNothing().when(eventEmitter).emitExtensionRemoved(installedExtension);
    Assertions.assertTrue(initReconciliator.reconcile(null, context).result().get());
    Assertions.assertTrue(Optional.of(context.getCluster()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getPodStatuses).stream().flatMap(List::stream).anyMatch(podStatus -> podStatus.getName().equals("test-0")));
    Assertions.assertFalse(context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getPendingRestart).orElse(false));
    Assertions.assertIterableEquals(ImmutableList.of(), context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getInstalledPostgresExtensions).stream().flatMap(List::stream).collect(ImmutableList.toImmutableList()));
    verify(extensionInstaller, times(0)).isExtensionInstalled();
    verify(extensionInstaller, times(0)).isLinksCreated();
    verify(extensionUninstaller, times(1)).isExtensionInstalled();
    verify(extensionInstaller, times(0)).downloadAndExtract();
    verify(extensionInstaller, times(0)).verify();
    verify(extensionInstaller, times(0)).installExtension();
    verify(extensionInstaller, times(0)).createExtensionLinks();
    verify(extensionInstaller, times(0)).createExtensionLinks();
    verify(extensionInstaller, times(0)).doesInstallOverwriteAnySharedLibrary();
    verify(extensionInstaller, times(0)).setExtensionAsPending();
    verify(extensionUninstaller, times(1)).uninstallExtension();
    verify(eventEmitter).emitExtensionRemoved(installedExtension);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Mock(org.mockito.Mock) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterList(io.stackgres.common.crd.sgcluster.StackGresClusterList) ArrayList(java.util.ArrayList) ExtensionUninstaller(io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller) ImmutableList(com.google.common.collect.ImmutableList) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) StackGresClusterPodStatus(io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus) StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus) ExtensionInstaller(io.stackgres.common.extension.ExtensionManager.ExtensionInstaller) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mockito.times(org.mockito.Mockito.times) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) JsonUtil(io.stackgres.testutil.JsonUtil) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) StackGresComponent(io.stackgres.common.StackGresComponent) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) List(java.util.List) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) StackGresClusterPodStatus(io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus) StackGresClusterList(io.stackgres.common.crd.sgcluster.StackGresClusterList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus) Test(org.junit.jupiter.api.Test)

Aggregations

StackGresClusterStatus (io.stackgres.common.crd.sgcluster.StackGresClusterStatus)20 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)15 List (java.util.List)15 Optional (java.util.Optional)15 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)14 StackGresClusterPodStatus (io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus)14 ImmutableList (com.google.common.collect.ImmutableList)13 StackGresClusterInstalledExtension (io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension)13 ArrayList (java.util.ArrayList)13 StackGresComponent (io.stackgres.common.StackGresComponent)12 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)12 ExtensionInstaller (io.stackgres.common.extension.ExtensionManager.ExtensionInstaller)12 ExtensionUninstaller (io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller)12 StackGresClusterList (io.stackgres.common.crd.sgcluster.StackGresClusterList)11 JsonUtil (io.stackgres.testutil.JsonUtil)11 Consumer (java.util.function.Consumer)11 Assertions (org.junit.jupiter.api.Assertions)11 BeforeEach (org.junit.jupiter.api.BeforeEach)11 Test (org.junit.jupiter.api.Test)11 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)11