use of org.entando.kubernetes.fluentspi.TestResource in project entando-k8s-controller-coordinator by entando-k8s.
the class PodManagementTests method shouldCreateControllerPodPointingToResource.
@Test
@Description("Should create a controller pod that points to the newly created resource")
void shouldCreateControllerPodPointingToResource() {
step("Given 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", () -> {
final TestResource r = new TestResource().withNames(clientDouble.getNamespace(), "test-keycloak").withSpec(new BasicDeploymentSpecBuilder().withDbms(DbmsVendor.EMBEDDED).build());
r.getMetadata().setGeneration(1L);
testResource.set(clientDouble.createOrPatchEntandoResource(CoordinatorTestUtils.toSerializedResource(r)));
attachment("TestResource", objectMapper.writeValueAsString(testResource.get()));
});
ValueHolder<Pod> firstPod = new ValueHolder<>();
step("Then one controller pod gets created", () -> {
await().ignoreExceptions().atMost(5, TimeUnit.SECONDS).until(() -> clientDouble.loadPod(clientDouble.getNamespace(), labelsFromResource(testResource.get())) != null);
firstPod.set(clientDouble.loadPod(clientDouble.getNamespace(), labelsFromResource(testResource.get())));
attachment("Controller Pod", objectMapper.writeValueAsString(firstPod.get()));
});
step("And the pod is given the necessary information to resolve the resource being processed", () -> {
assertThat(theVariableNamed(EntandoOperatorSpiConfigProperty.ENTANDO_RESOURCE_NAME.name()).on(thePrimaryContainerOn(firstPod.get()))).isEqualTo(testResource.get().getMetadata().getName());
assertThat(theVariableNamed(EntandoOperatorSpiConfigProperty.ENTANDO_RESOURCE_NAMESPACE.name()).on(thePrimaryContainerOn(firstPod.get()))).isEqualTo(testResource.get().getMetadata().getNamespace());
assertThat(theVariableNamed(EntandoOperatorSpiConfigProperty.ENTANDO_RESOURCE_KIND.name()).on(thePrimaryContainerOn(firstPod.get()))).isEqualTo(testResource.get().getKind());
});
step("And this pod remains present even if I complete the deployment of the TestResource successfully", () -> {
clientDouble.updatePodStatus(podWithSucceededStatus(clientDouble.loadPod(clientDouble.getNamespace(), labelsFromResource(testResource.get()))));
attachment("Successful Resource", objectMapper.writeValueAsString(clientDouble.updatePhase(testResource.get(), EntandoDeploymentPhase.SUCCESSFUL)));
await().ignoreExceptions().atMost(2, TimeUnit.SECONDS).ignoreExceptions().until(() -> LogInterceptor.getLogEntries().stream().anyMatch(s -> s.contains("was processed successfully")));
assertThat(clientDouble.loadPod(clientDouble.getNamespace(), labelsFromResource(testResource.get()))).isNotNull();
});
}
use of org.entando.kubernetes.fluentspi.TestResource 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