Search in sources :

Example 1 with AppEventListener

use of io.quarkiverse.operatorsdk.runtime.AppEventListener in project quarkus-operator-sdk by quarkiverse.

the class OperatorSDKProcessor method createConfigurationServiceAndOperator.

@BuildStep
ConfigurationServiceBuildItem createConfigurationServiceAndOperator(OutputTargetBuildItem outputTarget, CombinedIndexBuildItem combinedIndexBuildItem, BuildProducer<AdditionalBeanBuildItem> additionalBeans, BuildProducer<ReflectiveClassBuildItem> reflectionClasses, BuildProducer<ForceNonWeakReflectiveClassBuildItem> forcedReflectionClasses, BuildProducer<GeneratedCRDInfoBuildItem> generatedCRDInfo, LiveReloadBuildItem liveReload) {
    final CRDConfiguration crdConfig = buildTimeConfiguration.crd;
    final boolean validateCustomResources = ConfigurationUtils.shouldValidateCustomResources(buildTimeConfiguration.checkCRDAndValidateLocalModel, buildTimeConfiguration.crd.validate, log);
    // apply should imply generate: we cannot apply if we're not generating!
    final var crdGeneration = new CRDGeneration(crdConfig.generate || crdConfig.apply);
    final var index = combinedIndexBuildItem.getIndex();
    final List<QuarkusControllerConfiguration> controllerConfigs = ClassUtils.getKnownReconcilers(index, log).map(ci -> createControllerConfiguration(ci, additionalBeans, reflectionClasses, forcedReflectionClasses, index, crdGeneration, liveReload)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    // retrieve the known CRD information to make sure we always have a full view
    var storedCRDInfos = liveReload.getContextObject(ContextStoredCRDInfos.class);
    if (storedCRDInfos == null) {
        storedCRDInfos = new ContextStoredCRDInfos();
    }
    CRDGenerationInfo crdInfo = crdGeneration.generate(outputTarget, crdConfig, validateCustomResources, storedCRDInfos.getExisting());
    storedCRDInfos.putAll(crdInfo.getCrds());
    // record CRD generation info in context for future use
    liveReload.setContextObject(ContextStoredCRDInfos.class, storedCRDInfos);
    additionalBeans.produce(AdditionalBeanBuildItem.unremovableOf(OperatorProducer.class));
    // if the app doesn't provide a main class, add the AppEventListener
    if (index.getAllKnownImplementors(DotName.createSimple(QuarkusApplication.class.getName())).isEmpty()) {
        additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClass(AppEventListener.class).setDefaultScope(DotName.createSimple(Singleton.class.getName())).setUnremovable().build());
    }
    generatedCRDInfo.produce(new GeneratedCRDInfoBuildItem(crdInfo));
    return new ConfigurationServiceBuildItem(Version.loadFromProperties(), controllerConfigs);
}
Also used : ConfigurationServiceRecorder(io.quarkiverse.operatorsdk.runtime.ConfigurationServiceRecorder) UnremovableBeanBuildItem(io.quarkus.arc.deployment.UnremovableBeanBuildItem) JandexUtil(io.quarkus.deployment.util.JandexUtil) RunTimeOperatorConfiguration(io.quarkiverse.operatorsdk.runtime.RunTimeOperatorConfiguration) Version(io.quarkiverse.operatorsdk.runtime.Version) ClassInfo(org.jboss.jandex.ClassInfo) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) RECONCILER(io.quarkiverse.operatorsdk.common.Constants.RECONCILER) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) MetricsCapabilityBuildItem(io.quarkus.deployment.metrics.MetricsCapabilityBuildItem) BooleanSupplier(java.util.function.BooleanSupplier) Reconciler(io.javaoperatorsdk.operator.api.reconciler.Reconciler) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) ObserverConfiguratorBuildItem(io.quarkus.arc.deployment.ObserverRegistrationPhaseBuildItem.ObserverConfiguratorBuildItem) BuildException(io.quarkus.builder.BuildException) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) Operator(io.javaoperatorsdk.operator.Operator) ClassUtils.loadClass(io.quarkiverse.operatorsdk.common.ClassUtils.loadClass) ConfigurationUtils(io.quarkiverse.operatorsdk.common.ConfigurationUtils) CRDGenerationInfo(io.quarkiverse.operatorsdk.runtime.CRDGenerationInfo) Instance(javax.enterprise.inject.Instance) AnnotationValue(org.jboss.jandex.AnnotationValue) CUSTOM_RESOURCE(io.quarkiverse.operatorsdk.common.Constants.CUSTOM_RESOURCE) NoOpMetricsProvider(io.quarkiverse.operatorsdk.runtime.NoOpMetricsProvider) ObserverRegistrationPhaseBuildItem(io.quarkus.arc.deployment.ObserverRegistrationPhaseBuildItem) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) ForceNonWeakReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ForceNonWeakReflectiveClassBuildItem) DecoratorBuildItem(io.quarkus.kubernetes.spi.DecoratorBuildItem) CDI(javax.enterprise.inject.spi.CDI) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) APPLICATION_SCOPED(io.quarkus.arc.processor.DotNames.APPLICATION_SCOPED) List(java.util.List) AnnotationInstance(org.jboss.jandex.AnnotationInstance) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) QuarkusControllerConfiguration(io.quarkiverse.operatorsdk.runtime.QuarkusControllerConfiguration) ResultHandle(io.quarkus.gizmo.ResultHandle) CustomResource(io.fabric8.kubernetes.client.CustomResource) SyntheticBeanBuildItem(io.quarkus.arc.deployment.SyntheticBeanBuildItem) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) Record(io.quarkus.deployment.annotations.Record) AppEventListener(io.quarkiverse.operatorsdk.runtime.AppEventListener) ClassUtils(io.quarkiverse.operatorsdk.common.ClassUtils) Logger(org.jboss.logging.Logger) MethodCreator(io.quarkus.gizmo.MethodCreator) DotName(org.jboss.jandex.DotName) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) MetricsFactory(io.quarkus.runtime.metrics.MetricsFactory) IndexDependencyBuildItem(io.quarkus.deployment.builditem.IndexDependencyBuildItem) OperatorProducer(io.quarkiverse.operatorsdk.runtime.OperatorProducer) BuildStep(io.quarkus.deployment.annotations.BuildStep) ResourceInfo(io.quarkiverse.operatorsdk.common.ResourceInfo) AssignableResultHandle(io.quarkus.gizmo.AssignableResultHandle) IndexView(org.jboss.jandex.IndexView) ConfigurationService(io.javaoperatorsdk.operator.api.config.ConfigurationService) MethodDescriptor(io.quarkus.gizmo.MethodDescriptor) BuildTimeOperatorConfiguration(io.quarkiverse.operatorsdk.runtime.BuildTimeOperatorConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CONTROLLER_CONFIGURATION(io.quarkiverse.operatorsdk.common.Constants.CONTROLLER_CONFIGURATION) ReconcilerUtils(io.javaoperatorsdk.operator.ReconcilerUtils) ObserverConfigurator(io.quarkus.arc.processor.ObserverConfigurator) CRDConfiguration(io.quarkiverse.operatorsdk.runtime.CRDConfiguration) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) DelayRegistrationUntil(io.quarkiverse.operatorsdk.runtime.DelayRegistrationUntil) QuarkusApplication(io.quarkus.runtime.QuarkusApplication) QuarkusConfigurationService(io.quarkiverse.operatorsdk.runtime.QuarkusConfigurationService) Collections(java.util.Collections) LiveReloadBuildItem(io.quarkus.deployment.builditem.LiveReloadBuildItem) Optional(java.util.Optional) QuarkusControllerConfiguration(io.quarkiverse.operatorsdk.runtime.QuarkusControllerConfiguration) QuarkusApplication(io.quarkus.runtime.QuarkusApplication) CRDConfiguration(io.quarkiverse.operatorsdk.runtime.CRDConfiguration) CRDGenerationInfo(io.quarkiverse.operatorsdk.runtime.CRDGenerationInfo) OperatorProducer(io.quarkiverse.operatorsdk.runtime.OperatorProducer) Singleton(javax.inject.Singleton) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 CustomResource (io.fabric8.kubernetes.client.CustomResource)1 Operator (io.javaoperatorsdk.operator.Operator)1 ReconcilerUtils (io.javaoperatorsdk.operator.ReconcilerUtils)1 ConfigurationService (io.javaoperatorsdk.operator.api.config.ConfigurationService)1 Reconciler (io.javaoperatorsdk.operator.api.reconciler.Reconciler)1 ClassUtils (io.quarkiverse.operatorsdk.common.ClassUtils)1 ClassUtils.loadClass (io.quarkiverse.operatorsdk.common.ClassUtils.loadClass)1 ConfigurationUtils (io.quarkiverse.operatorsdk.common.ConfigurationUtils)1 CONTROLLER_CONFIGURATION (io.quarkiverse.operatorsdk.common.Constants.CONTROLLER_CONFIGURATION)1 CUSTOM_RESOURCE (io.quarkiverse.operatorsdk.common.Constants.CUSTOM_RESOURCE)1 RECONCILER (io.quarkiverse.operatorsdk.common.Constants.RECONCILER)1 ResourceInfo (io.quarkiverse.operatorsdk.common.ResourceInfo)1 AppEventListener (io.quarkiverse.operatorsdk.runtime.AppEventListener)1 BuildTimeOperatorConfiguration (io.quarkiverse.operatorsdk.runtime.BuildTimeOperatorConfiguration)1 CRDConfiguration (io.quarkiverse.operatorsdk.runtime.CRDConfiguration)1 CRDGenerationInfo (io.quarkiverse.operatorsdk.runtime.CRDGenerationInfo)1 ConfigurationServiceRecorder (io.quarkiverse.operatorsdk.runtime.ConfigurationServiceRecorder)1 DelayRegistrationUntil (io.quarkiverse.operatorsdk.runtime.DelayRegistrationUntil)1