Search in sources :

Example 6 with BasicDeploymentSpecBuilder

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));
}
Also used : SerializedEntandoResource(org.entando.kubernetes.controller.spi.client.SerializedEntandoResource) StartupEvent(io.quarkus.runtime.StartupEvent) ExecutorService(java.util.concurrent.ExecutorService) TestResource(org.entando.kubernetes.fluentspi.TestResource) ValueHolder(org.entando.kubernetes.test.common.ValueHolder) BasicDeploymentSpecBuilder(org.entando.kubernetes.fluentspi.BasicDeploymentSpecBuilder) Description(io.qameta.allure.Description) Test(org.junit.jupiter.api.Test)

Aggregations

SerializedEntandoResource (org.entando.kubernetes.controller.spi.client.SerializedEntandoResource)6 BasicDeploymentSpecBuilder (org.entando.kubernetes.fluentspi.BasicDeploymentSpecBuilder)6 TestResource (org.entando.kubernetes.fluentspi.TestResource)6 Description (io.qameta.allure.Description)5 ValueHolder (org.entando.kubernetes.test.common.ValueHolder)5 Test (org.junit.jupiter.api.Test)5 StartupEvent (io.quarkus.runtime.StartupEvent)4 Pod (io.fabric8.kubernetes.api.model.Pod)2 ExecutorService (java.util.concurrent.ExecutorService)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 Event (io.fabric8.kubernetes.api.model.Event)1 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)1 CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition)1 CustomResourceDefinitionBuilder (io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionBuilder)1 WatcherException (io.fabric8.kubernetes.client.WatcherException)1 Allure.attachment (io.qameta.allure.Allure.attachment)1 Allure.step (io.qameta.allure.Allure.step)1 Feature (io.qameta.allure.Feature)1 Issue (io.qameta.allure.Issue)1