use of io.quarkus.runtime.StartupEvent in project entando-k8s-controller-coordinator by entando-k8s.
the class CrdManagementTest method testCustomResourceEventWithControllerImageOverride.
@Test
@Description("New instances of my CustomResourceDefinitions should result in the image specified in the " + CoordinatorUtils.CONTROLLER_IMAGE_OVERRIDES_CONFIGMAP + " ConfigMap to be executed against the resource rather than the one on my CRD's annotation")
void testCustomResourceEventWithControllerImageOverride() throws IOException {
step("Given I have prepared a cluster scoped deployment of the EntandoOperator", () -> System.setProperty(EntandoOperatorConfigProperty.ENTANDO_NAMESPACES_TO_OBSERVE.getJvmSystemProperty(), "*"));
step("And I have started the Entando Operator", () -> entandoControllerCoordinator.onStartup(new StartupEvent()));
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
final CustomResourceDefinition value = objectMapper.readValue(Thread.currentThread().getContextClassLoader().getResource("mycrds.test.org.crd.yaml"), CustomResourceDefinition.class);
final MetadataNested<CustomResourceDefinitionBuilder> builder = new CustomResourceDefinitionBuilder(value).editMetadata();
step("And I have a CustomResourceDefinition with", () -> {
step(format("the %s label ", LabelNames.CRD_OF_INTEREST.getName()), () -> {
builder.addToLabels(LabelNames.CRD_OF_INTEREST.getName(), "MyCRD");
});
step(format("and the %s annotation ", AnnotationNames.CONTROLLER_IMAGE.getName()), () -> {
builder.addToAnnotations(AnnotationNames.CONTROLLER_IMAGE.getName(), "test/my-controller");
});
});
step("And I have registered my custom resource definition", () -> {
client.getCluster().putCustomResourceDefinition(builder.endMetadata().build());
});
step(format("But I have overridden the image to 'test/image-override' in the %s ConfigMap", CoordinatorUtils.CONTROLLER_IMAGE_OVERRIDES_CONFIGMAP), () -> {
client.patchControllerConfigMap(new ConfigMapBuilder(client.findOrCreateControllerConfigMap(CoordinatorUtils.CONTROLLER_IMAGE_OVERRIDES_CONFIGMAP)).addToData("MyCRD.test.org", "test/image-override").build());
});
final SerializedEntandoResource resource = new SerializedEntandoResource();
resource.setMetadata(new ObjectMetaBuilder().withName("my-resource").withNamespace(MY_NAMESPACE).build());
resource.setDefinition(CustomResourceDefinitionContext.fromCrd(builder.endMetadata().build()));
step("When I create a new custom resource based on my CustomResourceDefinition the overriding controller image is used to " + "execute" + " a " + "Controller pod that runs to completion", () -> client.createOrPatchEntandoResource(resource));
step(format("Then a controller pod has been created with the image that I specified in the %s ConfigMap", CoordinatorUtils.CONTROLLER_IMAGE_OVERRIDES_CONFIGMAP), () -> {
await().atMost(10, TimeUnit.SECONDS).ignoreExceptions().until(() -> client.loadPod(AbstractK8SClientDouble.CONTROLLER_NAMESPACE, CoordinatorUtils.podLabelsFor(resource)) != null);
assertThat(client.loadPod(AbstractK8SClientDouble.CONTROLLER_NAMESPACE, CoordinatorUtils.podLabelsFor(resource)).getSpec().getContainers().get(0).getImage()).contains("test/image-override");
});
}
use of io.quarkus.runtime.StartupEvent in project entando-k8s-controller-coordinator by entando-k8s.
the class PodManagementTests method shouldKillAllPreviousPods.
@Test
@Description("Should always kill existing pods running against the same resource to avoid racing conditions")
void shouldKillAllPreviousPods() {
step("Given the Coordinator observes its own namespace", () -> {
System.setProperty(EntandoOperatorConfigProperty.ENTANDO_NAMESPACES_TO_OBSERVE.getJvmSystemProperty(), clientDouble.getNamespace());
coordinator.onStartup(new StartupEvent());
});
step("And automatic controller pod garbage collections has been switched off", () -> System.setProperty(EntandoOperatorConfigProperty.ENTANDO_K8S_OPERATOR_GC_CONTROLLER_PODS.getJvmSystemProperty(), "false"));
ValueHolder<SerializedEntandoResource> testResource = new ValueHolder<>();
step("And I have created a new TestResource resource", () -> {
final TestResource entandoCustomResource = new TestResource().withNames(clientDouble.getNamespace(), "test-keycloak").withSpec(new BasicDeploymentSpecBuilder().withDbms(DbmsVendor.EMBEDDED).build());
testResource.set(clientDouble.createOrPatchEntandoResource(CoordinatorTestUtils.toSerializedResource(entandoCustomResource)));
attachment("TestResource", objectMapper.writeValueAsString(testResource.get()));
});
ValueHolder<Pod> firstPod = new ValueHolder<>();
step("And I have waited to see at least one controller pod", () -> {
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("FirstPod", objectMapper.writeValueAsString(firstPod.get()));
});
step("When I force a second attempt at processing the resource", () -> {
final SerializedEntandoResource reloaded = clientDouble.reload(testResource.get());
reloaded.getMetadata().setAnnotations(Map.of(AnnotationNames.PROCESSING_INSTRUCTION.getName(), "force"));
clientDouble.createOrPatchEntandoResource(reloaded);
});
step("Then a new pod was created", () -> {
await().atMost(4, TimeUnit.SECONDS).ignoreExceptions().until(() -> {
final List<Pod> pods = clientDouble.loadPods(clientDouble.getNamespace(), labelsFromResource(testResource.get()));
return !pods.get(pods.size() - 1).getMetadata().getUid().equals(firstPod.get().getMetadata().getUid());
});
final List<Pod> pods = clientDouble.loadPods(clientDouble.getNamespace(), labelsFromResource(testResource.get()));
attachment("Second Pod", objectMapper.writeValueAsString(pods.get(pods.size() - 1)));
});
step("And the old pod was removed", () -> {
final List<Pod> pods = clientDouble.loadPods(clientDouble.getNamespace(), labelsFromResource(testResource.get()));
assertThat(pods.size()).isOne();
});
}
use of io.quarkus.runtime.StartupEvent in project entando-k8s-controller-coordinator by entando-k8s.
the class ControllerCoordinatorProcessingCriteriaTest method testDuplicatesIgnored.
@Test
@Description("Resource modification events should be ignored when Kubernetes it twice with the same resource version")
void testDuplicatesIgnored() {
step("Given the Coordinator observes this namespace", () -> {
System.setProperty(EntandoOperatorConfigProperty.ENTANDO_NAMESPACES_TO_OBSERVE.getJvmSystemProperty(), OBSERVED_NAMESPACE);
coordinator.onStartup(new StartupEvent());
});
final ValueHolder<SerializedEntandoResource> testResource = new ValueHolder<>();
step("And I have created an TestResource resource", () -> {
testResource.set(createTestResource(1L, Collections.emptyMap()));
attachment("TestResource", objectMapper.writeValueAsString(testResource.get()));
});
final ValueHolder<Pod> oldPod = new ValueHolder<>();
step("And its controller pod has been created", () -> {
await().ignoreExceptions().atMost(3, TimeUnit.SECONDS).until(() -> clientDouble.loadPod(CONTROLLER_NAMESPACE, labelsFromResource(testResource.get())) != null);
oldPod.set(clientDouble.loadPod(CONTROLLER_NAMESPACE, labelsFromResource(testResource.get())));
attachment("Controller Pod", objectMapper.writeValueAsString(oldPod.get()));
});
step("When a duplicate event is fired", () -> {
// NB we have to invoke the observer directly as our test double doesn't generate duplicate events
coordinator.getObserver(CustomResourceDefinitionContext.fromCustomResourceType(TestResource.class)).eventReceived(Action.ADDED, testResource.get());
coordinator.shutdownObservers(10, TimeUnit.SECONDS);
attachment("Duplicate Resource", objectMapper.writeValueAsString(testResource.get()));
});
step("Then no new pod gets created", () -> {
// NB This assertion assumes the ClientDouble is storing the objects without cloning/serialization
assertThat(clientDouble.loadPod(CONTROLLER_NAMESPACE, labelsFromResource(testResource.get()))).isSameAs(oldPod.get());
});
step("And the duplicate event was logged", () -> {
final Optional<String> logEntry = LogInterceptor.getLogEntries().stream().filter(s -> s.startsWith("Duplicate event")).findFirst();
assertThat(logEntry).isPresent();
});
}
use of io.quarkus.runtime.StartupEvent in project kogito-apps by kiegroup.
the class KafkaConfigurationIT method topicConfiguration.
@Test
void topicConfiguration() {
tested = new KafkaConfiguration(defaultKafkaConfiguration, vertx, Optional.of(Boolean.TRUE), TOPIC);
assertThat(tested.getAdminClient()).isNull();
tested.topicConfiguration(new StartupEvent());
assertThat(tested.getAdminClient()).isNotNull();
await().atMost(Duration.ofSeconds(4)).untilAsserted(() -> assertThat(tested.getAdminClient().listTopicsAndAwait()).contains(TOPIC));
tested.getAdminClient().deleteTopicsAndAwait(Arrays.asList(TOPIC));
}
use of io.quarkus.runtime.StartupEvent in project kogito-apps by kiegroup.
the class InfinispanConfigurationTest method initializeCaches.
@Test
void initializeCaches(@Mock Event<InfinispanInitialized> initializedEvent, @Mock RemoteCacheManager remoteCacheManager, @Mock Instance<RemoteCacheManager> instance, @Mock RemoteCache<Object, Object> cache) {
when(instance.get()).thenReturn(remoteCacheManager);
when(remoteCacheManager.getCache(InfinispanConfiguration.Caches.JOB_DETAILS)).thenReturn(cache);
assertThat(tested.isInitialized()).isFalse();
tested.initializeCaches(new StartupEvent(), instance, initializedEvent);
verify(remoteCacheManager).getCache(eq(InfinispanConfiguration.Caches.JOB_DETAILS));
verify(initializedEvent).fire(any(InfinispanInitialized.class));
assertThat(tested.isInitialized()).isTrue();
}
Aggregations