Search in sources :

Example 1 with CRDInfo

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);
}
Also used : HashMap(java.util.HashMap) CRDGenerationInfo(io.quarkiverse.operatorsdk.runtime.CRDGenerationInfo) CRDInfo(io.quarkiverse.operatorsdk.runtime.CRDInfo) HashSet(java.util.HashSet)

Example 2 with CRDInfo

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);
}
Also used : HashMap(java.util.HashMap) CRDGenerationInfo(io.quarkiverse.operatorsdk.runtime.CRDGenerationInfo) CRDInfo(io.quarkiverse.operatorsdk.runtime.CRDInfo) HashSet(java.util.HashSet)

Example 3 with CRDInfo

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;
}
Also used : CRDInfo(io.quarkiverse.operatorsdk.runtime.CRDInfo) BundleDockerfileManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.BundleDockerfileManifestsBuilder) BuildTimeOperatorConfiguration(io.quarkiverse.operatorsdk.runtime.BuildTimeOperatorConfiguration) HashMap(java.util.HashMap) CSVMetadataHolder(io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadataHolder) ManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.ManifestsBuilder) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) BundleGenerationConfiguration(io.quarkiverse.operatorsdk.bundle.runtime.BundleGenerationConfiguration) Map(java.util.Map) AnnotationsManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.AnnotationsManifestsBuilder) CsvManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.CsvManifestsBuilder) CustomResourceManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.CustomResourceManifestsBuilder) BundleDockerfileManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.BundleDockerfileManifestsBuilder) ManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.ManifestsBuilder) AnnotationsManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.AnnotationsManifestsBuilder) CsvManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.CsvManifestsBuilder) CustomResourceManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.CustomResourceManifestsBuilder) CustomResourceManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.CustomResourceManifestsBuilder) ArrayList(java.util.ArrayList) BundleDockerfileManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.BundleDockerfileManifestsBuilder) CSVMetadataHolder(io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadataHolder) AnnotationsManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.AnnotationsManifestsBuilder) Objects(java.util.Objects) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) CsvManifestsBuilder(io.quarkiverse.operatorsdk.bundle.deployment.builders.CsvManifestsBuilder)

Aggregations

CRDInfo (io.quarkiverse.operatorsdk.runtime.CRDInfo)3 HashMap (java.util.HashMap)3 CRDGenerationInfo (io.quarkiverse.operatorsdk.runtime.CRDGenerationInfo)2 HashSet (java.util.HashSet)2 AnnotationsManifestsBuilder (io.quarkiverse.operatorsdk.bundle.deployment.builders.AnnotationsManifestsBuilder)1 BundleDockerfileManifestsBuilder (io.quarkiverse.operatorsdk.bundle.deployment.builders.BundleDockerfileManifestsBuilder)1 CsvManifestsBuilder (io.quarkiverse.operatorsdk.bundle.deployment.builders.CsvManifestsBuilder)1 CustomResourceManifestsBuilder (io.quarkiverse.operatorsdk.bundle.deployment.builders.CustomResourceManifestsBuilder)1 ManifestsBuilder (io.quarkiverse.operatorsdk.bundle.deployment.builders.ManifestsBuilder)1 BundleGenerationConfiguration (io.quarkiverse.operatorsdk.bundle.runtime.BundleGenerationConfiguration)1 CSVMetadataHolder (io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadataHolder)1 BuildTimeOperatorConfiguration (io.quarkiverse.operatorsdk.runtime.BuildTimeOperatorConfiguration)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1