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"));
}
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"));
}
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);
}
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:");
}
}
}
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"));
}
Aggregations