use of io.quarkiverse.operatorsdk.runtime.CRDGenerationInfo in project quarkus-operator-sdk by quarkiverse.
the class CRDGeneration method generate.
/**
* Generates the CRD in the location specified by the output target, using the specified CRD generation configuration
*
* @param outputTarget the {@link OutputTargetBuildItem} specifying where the CRDs should be generated
* @param crdConfig the {@link CRDConfiguration} specifying how the CRDs should be generated
* @param validateCustomResources whether the SDK should check if the CRDs are properly deployed on the server
* @param existing the already known CRDInfos
* @return a {@link CRDGenerationInfo} detailing information about the CRD generation
*/
CRDGenerationInfo generate(OutputTargetBuildItem outputTarget, CRDConfiguration crdConfig, boolean validateCustomResources, Map<String, Map<String, CRDInfo>> existing) {
// initialize CRDInfo with existing data to always have a full view even if we don't generate anything
final var converted = new HashMap<>(existing);
// record which CRDs got generated so that we only apply the changed ones
final var generated = new HashSet<String>();
if (needGeneration) {
final String outputDirName = crdConfig.outputDirectory;
final var outputDir = outputTarget.getOutputDirectory().resolve(outputDirName).toFile();
if (!outputDir.exists()) {
outputDir.mkdirs();
}
// generate CRDs with detailed information
final var info = generator.forCRDVersions(crdConfig.versions).inOutputDir(outputDir).detailedGenerate();
final var crdDetailsPerNameAndVersion = info.getCRDDetailsPerNameAndVersion();
crdDetailsPerNameAndVersion.forEach((crdName, initialVersionToCRDInfoMap) -> {
OperatorSDKProcessor.log.infov("Generated {0} CRD:", crdName);
generated.add(crdName);
final var versions = crMappings.getResourceInfos(crdName);
final var versionToCRDInfo = converted.computeIfAbsent(crdName, s -> new HashMap<>());
initialVersionToCRDInfoMap.forEach((version, crdInfo) -> {
final var filePath = crdInfo.getFilePath();
OperatorSDKProcessor.log.infov(" - {0} -> {1}", version, filePath);
versionToCRDInfo.put(version, new CRDInfo(crdInfo.getCrdName(), version, filePath, crdInfo.getDependentClassNames(), versions));
});
});
}
return new CRDGenerationInfo(crdConfig.apply, validateCustomResources, converted, generated);
}
use of io.quarkiverse.operatorsdk.runtime.CRDGenerationInfo 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);
}
Aggregations