use of org.entando.kubernetes.fluentspi.BasicDeploymentSpecBuilder in project entando-k8s-controller-coordinator by entando-k8s.
the class PodManagementTests method shouldGarbageCollectSuccessulPods.
@Test
@Description("Should automatically remove successful controller pods once the resource has progress to the 'successful' phase")
void shouldGarbageCollectSuccessulPods() {
step("Given I have activated controller Pod garbage collection with a removal delay of 1 second", () -> {
System.setProperty(ControllerCoordinatorProperty.ENTANDO_K8S_CONTROLLER_REMOVAL_DELAY.getJvmSystemProperty(), "1");
System.setProperty(EntandoOperatorConfigProperty.ENTANDO_K8S_OPERATOR_GC_CONTROLLER_PODS.getJvmSystemProperty(), "true");
});
step("And the Coordinator observes its own namespace", () -> {
System.setProperty(EntandoOperatorConfigProperty.ENTANDO_NAMESPACES_TO_OBSERVE.getJvmSystemProperty(), clientDouble.getNamespace());
coordinator.onStartup(new StartupEvent());
});
ValueHolder<SerializedEntandoResource> testResource = new ValueHolder<>();
step("And I have created a new TestResource resource", () -> {
TestResource f = new TestResource().withNames(clientDouble.getNamespace(), "test-keycloak").withSpec(new BasicDeploymentSpecBuilder().withDbms(DbmsVendor.EMBEDDED).build());
f.getMetadata().setGeneration(1L);
testResource.set(clientDouble.createOrPatchEntandoResource(CoordinatorTestUtils.toSerializedResource(f)));
attachment("TestResource", objectMapper.writeValueAsString(testResource.get()));
});
step("And I have waited for the controller pod to be created", () -> {
await().ignoreExceptions().atMost(3, TimeUnit.SECONDS).until(() -> clientDouble.loadPod(clientDouble.getNamespace(), labelsFromResource(testResource.get())) != null);
attachment("Controller Pod", objectMapper.writeValueAsString(clientDouble.loadPod(clientDouble.getNamespace(), labelsFromResource(testResource.get()))));
});
step("When I complete the deployment of the TestResource successfully", () -> {
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> {
clientDouble.updatePodStatus(podWithSucceededStatus(clientDouble.loadPod(clientDouble.getNamespace(), labelsFromResource(testResource.get()))));
});
attachment("Suffessful Resource", objectMapper.writeValueAsString(clientDouble.updatePhase(testResource.get(), EntandoDeploymentPhase.SUCCESSFUL)));
});
step("Then the previously created, but successfully completed controller pod will be removed", () -> await().ignoreExceptions().atMost(3, TimeUnit.SECONDS).until(() -> clientDouble.loadPod(clientDouble.getNamespace(), labelsFromResource(testResource.get())) == null));
}
Aggregations