Search in sources :

Example 1 with CSVGenerationConfiguration

use of io.quarkiverse.operatorsdk.csv.runtime.CSVGenerationConfiguration 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)

Aggregations

Serialization (io.dekorate.utils.Serialization)1 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)1 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)1 ClusterRole (io.fabric8.kubernetes.api.model.rbac.ClusterRole)1 ClusterRoleBinding (io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding)1 Role (io.fabric8.kubernetes.api.model.rbac.Role)1 RoleBinding (io.fabric8.kubernetes.api.model.rbac.RoleBinding)1 ClassUtils (io.quarkiverse.operatorsdk.common.ClassUtils)1 ConfigurationUtils (io.quarkiverse.operatorsdk.common.ConfigurationUtils)1 ResourceInfo (io.quarkiverse.operatorsdk.common.ResourceInfo)1 CSVGenerationConfiguration (io.quarkiverse.operatorsdk.csv.runtime.CSVGenerationConfiguration)1 CSVMetadata (io.quarkiverse.operatorsdk.csv.runtime.CSVMetadata)1 CSVMetadataHolder (io.quarkiverse.operatorsdk.csv.runtime.CSVMetadataHolder)1 SharedCSVMetadata (io.quarkiverse.operatorsdk.csv.runtime.SharedCSVMetadata)1 ALL_VERBS (io.quarkiverse.operatorsdk.deployment.AddClusterRolesDecorator.ALL_VERBS)1 ConfigurationServiceBuildItem (io.quarkiverse.operatorsdk.deployment.ConfigurationServiceBuildItem)1 GeneratedCRDInfoBuildItem (io.quarkiverse.operatorsdk.deployment.GeneratedCRDInfoBuildItem)1 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)1