use of io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus 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);
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus in project stackgres by ongres.
the class ExtensionReconciliationTest method testReconciliationWithExtAlreadyPresentButLinksNotCreated_installIsSkippedButLinksCreated.
@Test
void testReconciliationWithExtAlreadyPresentButLinksNotCreated_installIsSkippedButLinksCreated() throws Exception {
StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
ExtensionReconciliatorContext context = getContext(cluster -> {
cluster.getSpec().getPostgres().setExtensions(null);
cluster.getSpec().setToInstallPostgresExtensions(new ArrayList<>());
cluster.getSpec().getToInstallPostgresExtensions().add(installedExtension);
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.getExtensionInstaller(any(), any(StackGresClusterInstalledExtension.class))).thenReturn(extensionInstaller);
when(extensionInstaller.isExtensionInstalled()).thenReturn(true);
when(extensionInstaller.isLinksCreated()).thenReturn(false);
Assertions.assertFalse(reconciliator.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(installedExtension), 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(1)).isExtensionInstalled();
verify(extensionInstaller, times(1)).isLinksCreated();
verify(extensionUninstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(0)).downloadAndExtract();
verify(extensionInstaller, times(0)).verify();
verify(extensionInstaller, times(0)).installExtension();
verify(extensionInstaller, times(1)).createExtensionLinks();
verify(extensionInstaller, times(0)).doesInstallOverwriteAnySharedLibrary();
verify(extensionInstaller, times(0)).setExtensionAsPending();
verify(extensionUninstaller, times(0)).uninstallExtension();
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus in project stackgres by ongres.
the class ExtensionReconciliationTest method testInitReconciliationWithExtensionThatOverwrite_installIsPerformed.
@Test
void testInitReconciliationWithExtensionThatOverwrite_installIsPerformed() throws Exception {
StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
ExtensionReconciliatorContext context = getContext(cluster -> {
cluster.getSpec().getPostgres().setExtensions(null);
cluster.getSpec().setToInstallPostgresExtensions(new ArrayList<>());
cluster.getSpec().getToInstallPostgresExtensions().add(installedExtension);
});
when(extensionManager.getExtensionInstaller(any(), any(StackGresClusterInstalledExtension.class))).thenReturn(extensionInstaller);
when(extensionInstaller.isExtensionInstalled()).thenReturn(false);
doNothing().when(eventEmitter).emitExtensionDeployed(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(installedExtension), 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(1)).isExtensionInstalled();
verify(extensionInstaller, times(0)).isLinksCreated();
verify(extensionInstaller, times(0)).isExtensionPendingOverwrite();
verify(extensionUninstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(1)).downloadAndExtract();
verify(extensionInstaller, times(1)).verify();
verify(extensionInstaller, times(1)).installExtension();
verify(extensionInstaller, times(0)).createExtensionLinks();
verify(extensionInstaller, times(0)).doesInstallOverwriteAnySharedLibrary();
verify(extensionInstaller, times(0)).setExtensionAsPending();
verify(extensionUninstaller, times(0)).uninstallExtension();
verify(eventEmitter).emitExtensionDeployed(installedExtension);
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus in project stackgres by ongres.
the class ExtensionReconciliationTest method testReconciliationWithExtensionAlreadyInstalled_installIsSkipped.
@Test
void testReconciliationWithExtensionAlreadyInstalled_installIsSkipped() throws Exception {
StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
ExtensionReconciliatorContext context = getContext(cluster -> {
cluster.getSpec().getPostgres().setExtensions(null);
cluster.getSpec().setToInstallPostgresExtensions(new ArrayList<>());
cluster.getSpec().getToInstallPostgresExtensions().add(installedExtension);
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.getExtensionInstaller(any(), any(StackGresClusterInstalledExtension.class))).thenReturn(extensionInstaller);
when(extensionInstaller.isExtensionInstalled()).thenReturn(true);
when(extensionInstaller.isLinksCreated()).thenReturn(true);
Assertions.assertFalse(reconciliator.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(installedExtension), 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(1)).isExtensionInstalled();
verify(extensionInstaller, times(1)).isLinksCreated();
verify(extensionUninstaller, times(0)).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(0)).uninstallExtension();
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus in project stackgres by ongres.
the class ExtensionReconciliationTest method testReconciliationWithExtension_installIsPerformed.
@Test
void testReconciliationWithExtension_installIsPerformed() throws Exception {
StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
ExtensionReconciliatorContext context = getContext(cluster -> {
cluster.getSpec().getPostgres().setExtensions(null);
cluster.getSpec().setToInstallPostgresExtensions(new ArrayList<>());
cluster.getSpec().getToInstallPostgresExtensions().add(installedExtension);
});
when(extensionManager.getExtensionInstaller(any(), any(StackGresClusterInstalledExtension.class))).thenReturn(extensionInstaller);
when(extensionInstaller.isExtensionInstalled()).thenReturn(false);
when(extensionInstaller.isExtensionPendingOverwrite()).thenReturn(false);
doNothing().when(eventEmitter).emitExtensionDeployed(installedExtension);
Assertions.assertTrue(reconciliator.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(installedExtension), 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(1)).isExtensionInstalled();
verify(extensionInstaller, times(0)).isLinksCreated();
verify(extensionUninstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(1)).downloadAndExtract();
verify(extensionInstaller, times(1)).verify();
verify(extensionInstaller, times(1)).installExtension();
verify(extensionInstaller, times(0)).createExtensionLinks();
verify(extensionInstaller, times(1)).doesInstallOverwriteAnySharedLibrary();
verify(extensionInstaller, times(0)).setExtensionAsPending();
verify(extensionUninstaller, times(0)).uninstallExtension();
verify(eventEmitter).emitExtensionDeployed(installedExtension);
}
Aggregations