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);
}
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);
}
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);
}
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;
}
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);
}
Aggregations