use of io.quarkiverse.operatorsdk.runtime.CRDInfo 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.CRDInfo 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
* @param mode the mode in which the application is running
* @return a {@link CRDGenerationInfo} detailing information about the CRD generation
*/
CRDGenerationInfo generate(OutputTargetBuildItem outputTarget, CRDConfiguration crdConfig, boolean validateCustomResources, Map<String, Map<String, CRDInfo>> existing, LaunchMode mode) {
// 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()) {
if (!outputDir.mkdirs()) {
throw new IllegalArgumentException("Couldn't create " + outputDir.getAbsolutePath());
}
}
// 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(shouldApply(crdConfig.apply, mode), validateCustomResources, converted, generated);
}
use of io.quarkiverse.operatorsdk.runtime.CRDInfo in project quarkus-operator-sdk by quarkiverse.
the class BundleGenerator method prepareGeneration.
public static List<ManifestsBuilder> prepareGeneration(BundleGenerationConfiguration bundleConfiguration, BuildTimeOperatorConfiguration operatorConfiguration, Map<CSVMetadataHolder, List<AugmentedResourceInfo>> csvGroups, List<CRDInfo> crds) {
List<ManifestsBuilder> builders = new ArrayList<>();
for (Map.Entry<CSVMetadataHolder, List<AugmentedResourceInfo>> entry : csvGroups.entrySet()) {
final var labels = generateBundleLabels(entry.getKey(), bundleConfiguration, operatorConfiguration);
builders.add(new CsvManifestsBuilder(entry.getKey(), entry.getValue()));
builders.add(new AnnotationsManifestsBuilder(entry.getKey(), labels));
builders.add(new BundleDockerfileManifestsBuilder(entry.getKey(), labels));
entry.getValue().stream().map(controller -> findOwnedCustomResource(controller, crds)).filter(Objects::nonNull).map(crd -> new CustomResourceManifestsBuilder(entry.getKey(), crd)).forEach(builders::add);
}
return builders;
}
Aggregations