Search in sources :

Example 1 with OutputTargetBuildItem

use of io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem in project kogito-runtimes by kiegroup.

the class KogitoAddOnKnativeEventingProcessorTest method checkKogitoFileIsGeneratedWithKogitoSource.

@Test
void checkKogitoFileIsGeneratedWithKogitoSource() {
    final OutputTargetBuildItem outputTargetBuildItem = new OutputTargetBuildItem(Paths.get("/"), "", false, null, Optional.empty());
    final Set<CloudEventMeta> ces = new HashSet<>();
    ces.add(new CloudEventMeta("myProducedEvent", "/local/test", EventKind.PRODUCED));
    final KogitoServiceDeploymentTarget deploymentTarget = new KogitoServiceDeploymentTarget("apps", "v1", "Deployment", "kogito-service");
    final KogitoKnativeResourcesMetadataBuildItem resourcesMetadataBuildItem = new KogitoKnativeResourcesMetadataBuildItem(ces, deploymentTarget);
    final KogitoAddOnKnativeEventingProcessor eventingProcessor = buildTestProcessorWithDefaultConfig();
    eventingProcessor.config.generateKogitoSource = true;
    final MockGeneratedFSProducer producer = new MockGeneratedFSProducer();
    eventingProcessor.generate(outputTargetBuildItem, Optional.of(resourcesMetadataBuildItem), producer);
    assertNotNull(producer.getItem().getData());
    assertTrue(producer.getItem().getData().length > 0);
    assertFalse(new String(producer.getItem().getData()).contains("SinkBinding"));
    assertTrue(new String(producer.getItem().getData()).contains("KogitoSource"));
    assertFalse(new String(producer.getItem().getData()).contains("Trigger"));
    assertTrue(new String(producer.getItem().getData()).contains("Broker"));
}
Also used : CloudEventMeta(org.kie.kogito.event.cloudevents.CloudEventMeta) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with OutputTargetBuildItem

use of io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem in project kogito-runtimes by kiegroup.

the class KogitoAddOnKnativeEventingProcessorTest method checkKogitoFileIsGeneratedWithDefaultConfig.

@Test
void checkKogitoFileIsGeneratedWithDefaultConfig() {
    final OutputTargetBuildItem outputTargetBuildItem = new OutputTargetBuildItem(Paths.get("/"), "", false, null, Optional.empty());
    final Set<CloudEventMeta> ces = new HashSet<>();
    ces.add(new CloudEventMeta("myProducedEvent", "/local/test", EventKind.PRODUCED));
    ces.add(new CloudEventMeta("myConsumedEvent", "/local/test", EventKind.CONSUMED));
    final KogitoServiceDeploymentTarget deploymentTarget = new KogitoServiceDeploymentTarget("apps", "v1", "Deployment", "kogito-service");
    final KogitoKnativeResourcesMetadataBuildItem resourcesMetadataBuildItem = new KogitoKnativeResourcesMetadataBuildItem(ces, deploymentTarget);
    final KogitoAddOnKnativeEventingProcessor eventingProcessor = buildTestProcessorWithDefaultConfig();
    final MockGeneratedFSProducer producer = new MockGeneratedFSProducer();
    eventingProcessor.generate(outputTargetBuildItem, Optional.of(resourcesMetadataBuildItem), producer);
    assertNotNull(producer.getItem().getData());
    assertTrue(producer.getItem().getData().length > 0);
    assertTrue(new String(producer.getItem().getData()).contains("SinkBinding"));
    assertFalse(new String(producer.getItem().getData()).contains("KogitoSource"));
    assertTrue(new String(producer.getItem().getData()).contains("Trigger"));
    assertTrue(new String(producer.getItem().getData()).contains("Broker"));
}
Also used : CloudEventMeta(org.kie.kogito.event.cloudevents.CloudEventMeta) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with OutputTargetBuildItem

use of io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem 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)

Example 4 with OutputTargetBuildItem

use of io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem in project quarkus-operator-sdk by quarkiverse.

the class ManifestsProcessor method generateCSV.

@BuildStep
void generateCSV(CSVGenerationConfiguration configuration, OutputTargetBuildItem outputTarget, CSVMetadataBuildItem csvMetadata, BuildProducer<GeneratedCSVBuildItem> doneGeneratingCSV, GeneratedCRDInfoBuildItem generatedCustomResourcesDefinitions, List<GeneratedKubernetesResourceBuildItem> generatedKubernetesManifests, BuildProducer<GeneratedFileSystemResourceBuildItem> generatedCSVs) {
    if (configuration.generateCSV.orElse(false)) {
        try {
            final var outputDir = outputTarget.getOutputDirectory().resolve(MANIFESTS);
            final var serviceAccounts = new LinkedList<ServiceAccount>();
            final var clusterRoleBindings = new LinkedList<ClusterRoleBinding>();
            final var clusterRoles = new LinkedList<ClusterRole>();
            final var roleBindings = new LinkedList<RoleBinding>();
            final var roles = new LinkedList<Role>();
            final var deployments = new LinkedList<Deployment>();
            generatedKubernetesManifests.stream().filter(bi -> bi.getName().equals("kubernetes.yml")).findAny().ifPresent(bi -> {
                final var resources = Serialization.unmarshalAsList(new ByteArrayInputStream(bi.getContent()));
                resources.getItems().forEach(r -> {
                    if (r instanceof ServiceAccount) {
                        serviceAccounts.add((ServiceAccount) r);
                        return;
                    }
                    if (r instanceof ClusterRoleBinding) {
                        clusterRoleBindings.add((ClusterRoleBinding) r);
                        return;
                    }
                    if (r instanceof ClusterRole) {
                        clusterRoles.add((ClusterRole) r);
                        return;
                    }
                    if (r instanceof RoleBinding) {
                        roleBindings.add((RoleBinding) r);
                        return;
                    }
                    if (r instanceof Role) {
                        roles.add((Role) r);
                        return;
                    }
                    if (r instanceof Deployment) {
                        deployments.add((Deployment) r);
                        return;
                    }
                });
            });
            final var generated = ManifestsGenerator.prepareGeneration(csvMetadata.getAugmentedCustomResourceInfos(), csvMetadata.getCSVMetadata());
            generated.forEach(manifestBuilder -> {
                final var fileName = manifestBuilder.getFileName();
                try {
                    generatedCSVs.produce(new GeneratedFileSystemResourceBuildItem(Path.of(MANIFESTS, fileName).toString(), manifestBuilder.getYAMLData(serviceAccounts, clusterRoleBindings, clusterRoles, roleBindings, roles, deployments)));
                    log.infov("Generating CSV for {0} controller -> {1}", manifestBuilder.getControllerName(), outputDir.resolve(fileName));
                } catch (IOException e) {
                    log.errorv("Cannot generate CSV for {0}: {1}", manifestBuilder.getControllerName(), e.getMessage());
                }
            });
            // copy custom resources to the manifests folder
            generatedCustomResourcesDefinitions.getCRDGenerationInfo().getCrds().values().stream().flatMap(crds -> crds.values().stream()).forEach(crd -> {
                try {
                    FileUtils.copyFileToDirectory(new File(crd.getFilePath()), outputDir.toFile());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            });
            doneGeneratingCSV.produce(new GeneratedCSVBuildItem());
        } catch (Exception e) {
            log.infov(e, "Couldn't generate CSV:");
        }
    }
}
Also used : ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) ClassUtils(io.quarkiverse.operatorsdk.common.ClassUtils) Logger(org.jboss.logging.Logger) DotName(org.jboss.jandex.DotName) Role(io.fabric8.kubernetes.api.model.rbac.Role) HashMap(java.util.HashMap) SharedCSVMetadata(io.quarkiverse.operatorsdk.csv.runtime.SharedCSVMetadata) ClassInfo(org.jboss.jandex.ClassInfo) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) GeneratedCRDInfoBuildItem(io.quarkiverse.operatorsdk.deployment.GeneratedCRDInfoBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) GeneratedKubernetesResourceBuildItem(io.quarkus.kubernetes.spi.GeneratedKubernetesResourceBuildItem) RoleBinding(io.fabric8.kubernetes.api.model.rbac.RoleBinding) BuildStep(io.quarkus.deployment.annotations.BuildStep) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceInfo(io.quarkiverse.operatorsdk.common.ResourceInfo) ConfigurationUtils(io.quarkiverse.operatorsdk.common.ConfigurationUtils) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) IndexView(org.jboss.jandex.IndexView) CSVGenerationConfiguration(io.quarkiverse.operatorsdk.csv.runtime.CSVGenerationConfiguration) AnnotationValue(org.jboss.jandex.AnnotationValue) CSVMetadata(io.quarkiverse.operatorsdk.csv.runtime.CSVMetadata) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Serialization(io.dekorate.utils.Serialization) CSVMetadataHolder(io.quarkiverse.operatorsdk.csv.runtime.CSVMetadataHolder) ConfigurationServiceBuildItem(io.quarkiverse.operatorsdk.deployment.ConfigurationServiceBuildItem) File(java.io.File) List(java.util.List) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) AnnotationInstance(org.jboss.jandex.AnnotationInstance) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) ClusterRole(io.fabric8.kubernetes.api.model.rbac.ClusterRole) ALL_VERBS(io.quarkiverse.operatorsdk.deployment.AddClusterRolesDecorator.ALL_VERBS) Optional(java.util.Optional) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) IOException(java.io.IOException) LinkedList(java.util.LinkedList) ClusterRole(io.fabric8.kubernetes.api.model.rbac.ClusterRole) IOException(java.io.IOException) Role(io.fabric8.kubernetes.api.model.rbac.Role) ClusterRole(io.fabric8.kubernetes.api.model.rbac.ClusterRole) ByteArrayInputStream(java.io.ByteArrayInputStream) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) RoleBinding(io.fabric8.kubernetes.api.model.rbac.RoleBinding) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) File(java.io.File) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 5 with OutputTargetBuildItem

use of io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem in project kogito-runtimes by kiegroup.

the class KogitoAddOnKnativeEventingProcessorTest method checkKogitoFileIsGeneratedOnlyConsumed.

@Test
void checkKogitoFileIsGeneratedOnlyConsumed() {
    final OutputTargetBuildItem outputTargetBuildItem = new OutputTargetBuildItem(Paths.get("/"), "", false, null, Optional.empty());
    final Set<CloudEventMeta> ces = new HashSet<>();
    ces.add(new CloudEventMeta("myConsumedEvent", "/local/test", EventKind.CONSUMED));
    final KogitoServiceDeploymentTarget deploymentTarget = new KogitoServiceDeploymentTarget("apps", "v1", "Deployment", "kogito-service");
    final KogitoKnativeResourcesMetadataBuildItem resourcesMetadataBuildItem = new KogitoKnativeResourcesMetadataBuildItem(ces, deploymentTarget);
    final KogitoAddOnKnativeEventingProcessor eventingProcessor = buildTestProcessorWithDefaultConfig();
    final MockGeneratedFSProducer producer = new MockGeneratedFSProducer();
    eventingProcessor.generate(outputTargetBuildItem, Optional.of(resourcesMetadataBuildItem), producer);
    assertNotNull(producer.getItem().getData());
    assertTrue(producer.getItem().getData().length > 0);
    assertFalse(new String(producer.getItem().getData()).contains("SinkBinding"));
    assertFalse(new String(producer.getItem().getData()).contains("KogitoSource"));
    assertTrue(new String(producer.getItem().getData()).contains("Trigger"));
    assertTrue(new String(producer.getItem().getData()).contains("Broker"));
}
Also used : CloudEventMeta(org.kie.kogito.event.cloudevents.CloudEventMeta) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

OutputTargetBuildItem (io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem)7 HashSet (java.util.HashSet)5 Test (org.junit.jupiter.api.Test)5 CloudEventMeta (org.kie.kogito.event.cloudevents.CloudEventMeta)5 ClassUtils (io.quarkiverse.operatorsdk.common.ClassUtils)2 ConfigurationUtils (io.quarkiverse.operatorsdk.common.ConfigurationUtils)2 ResourceInfo (io.quarkiverse.operatorsdk.common.ResourceInfo)2 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)2 BuildStep (io.quarkus.deployment.annotations.BuildStep)2 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Optional (java.util.Optional)2 AnnotationInstance (org.jboss.jandex.AnnotationInstance)2 AnnotationValue (org.jboss.jandex.AnnotationValue)2 ClassInfo (org.jboss.jandex.ClassInfo)2 DotName (org.jboss.jandex.DotName)2 IndexView (org.jboss.jandex.IndexView)2 Logger (org.jboss.logging.Logger)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1