Search in sources :

Example 1 with GeneratedFileSystemResourceBuildItem

use of io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem in project quarkus by quarkusio.

the class S2iProcessor method s2iBuildFromNative.

@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, S2iBuild.class, NativeBuild.class })
public void s2iBuildFromNative(S2iConfig s2iConfig, ContainerImageConfig containerImageConfig, KubernetesClientBuildItem kubernetesClient, ContainerImageInfoBuildItem containerImage, ArchiveRootBuildItem archiveRoot, OutputTargetBuildItem out, PackageConfig packageConfig, List<GeneratedFileSystemResourceBuildItem> generatedResources, Optional<ContainerImageBuildRequestBuildItem> buildRequest, Optional<ContainerImagePushRequestBuildItem> pushRequest, BuildProducer<ArtifactResultBuildItem> artifactResultProducer, BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder, NativeImageBuildItem nativeImage) {
    if (containerImageConfig.isBuildExplicitlyDisabled()) {
        return;
    }
    if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled() && !buildRequest.isPresent() && !pushRequest.isPresent()) {
        return;
    }
    String namespace = Optional.ofNullable(kubernetesClient.getClient().getNamespace()).orElse("default");
    LOG.info("Performing s2i binary build with native image on server: " + kubernetesClient.getClient().getMasterUrl() + " in namespace:" + namespace + ".");
    Optional<GeneratedFileSystemResourceBuildItem> openshiftYml = generatedResources.stream().filter(r -> r.getName().endsWith("kubernetes" + File.separator + "openshift.yml")).findFirst();
    if (openshiftYml.isEmpty()) {
        LOG.warn("No Openshift manifests were generated so no s2i process will be taking place");
        return;
    }
    createContainerImage(kubernetesClient, openshiftYml.get(), s2iConfig, out.getOutputDirectory(), nativeImage.getPath());
    artifactResultProducer.produce(new ArtifactResultBuildItem(null, "native-container", Collections.emptyMap()));
    containerImageBuilder.produce(new ContainerImageBuilderBuildItem(S2I));
}
Also used : Arrays(java.util.Arrays) KubernetesClientBuildItem(io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem) KubernetesEnvBuildItem(io.quarkus.kubernetes.spi.KubernetesEnvBuildItem) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) LogWatch(io.fabric8.kubernetes.client.dsl.LogWatch) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ArchiveRootBuildItem(io.quarkus.deployment.builditem.ArchiveRootBuildItem) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Build(io.fabric8.openshift.api.model.Build) KubernetesCommandBuildItem(io.quarkus.kubernetes.spi.KubernetesCommandBuildItem) Path(java.nio.file.Path) IsNormalNotRemoteDev(io.quarkus.deployment.IsNormalNotRemoteDev) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) Predicate(java.util.function.Predicate) ContainerImagePushRequestBuildItem(io.quarkus.container.spi.ContainerImagePushRequestBuildItem) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) Collection(java.util.Collection) ContainerImageConfig(io.quarkus.container.image.deployment.ContainerImageConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Executors(java.util.concurrent.Executors) PackageConfig(io.quarkus.deployment.pkg.PackageConfig) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) Config(io.fabric8.kubernetes.client.Config) List(java.util.List) Stream(java.util.stream.Stream) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) Optional(java.util.Optional) Secret(io.fabric8.kubernetes.api.model.Secret) AvailableContainerImageExtensionBuildItem(io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem) Logger(org.jboss.logging.Logger) KubernetesClientErrorHandler(io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHandler) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) CompiledJavaVersionBuildItem(io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) ImageUtil(io.quarkus.container.image.deployment.util.ImageUtil) BuildStep(io.quarkus.deployment.annotations.BuildStep) BaseImageInfoBuildItem(io.quarkus.container.spi.BaseImageInfoBuildItem) ImageStream(io.fabric8.openshift.api.model.ImageStream) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) ContainerImageBuildRequestBuildItem(io.quarkus.container.spi.ContainerImageBuildRequestBuildItem) Files(java.nio.file.Files) Executor(java.util.concurrent.Executor) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) IOException(java.io.IOException) Serialization(io.dekorate.utils.Serialization) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) InputStreamReader(java.io.InputStreamReader) NativeBuild(io.quarkus.deployment.pkg.steps.NativeBuild) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Clients(io.dekorate.utils.Clients) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) Closeable(java.io.Closeable) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with GeneratedFileSystemResourceBuildItem

use of io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem in project quarkus by quarkusio.

the class S2iProcessor method createContainerImage.

public static void createContainerImage(KubernetesClientBuildItem kubernetesClient, GeneratedFileSystemResourceBuildItem openshiftManifests, S2iConfig s2iConfig, Path output, Path... additional) {
    File tar;
    try {
        File original = PackageUtil.packageFile(output, additional);
        // Let's rename the archive and give it a more descriptive name, as it may appear in the logs.
        tar = Files.createTempFile("quarkus-", "-s2i").toFile();
        Files.move(original.toPath(), tar.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (Exception e) {
        throw new RuntimeException("Error creating the s2i binary build archive.", e);
    }
    Config config = kubernetesClient.getClient().getConfiguration();
    // Let's disable http2 as it causes issues with duplicate build triggers.
    config.setHttp2Disable(true);
    try (KubernetesClient client = Clients.fromConfig(config)) {
        OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class);
        KubernetesList kubernetesList = Serialization.unmarshalAsList(new ByteArrayInputStream(openshiftManifests.getData()));
        List<HasMetadata> buildResources = kubernetesList.getItems().stream().filter(i -> i instanceof BuildConfig || i instanceof ImageStream || i instanceof Secret).collect(Collectors.toList());
        applyS2iResources(openShiftClient, buildResources);
        s2iBuild(openShiftClient, buildResources, tar, s2iConfig);
    }
}
Also used : Arrays(java.util.Arrays) KubernetesClientBuildItem(io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem) KubernetesEnvBuildItem(io.quarkus.kubernetes.spi.KubernetesEnvBuildItem) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) LogWatch(io.fabric8.kubernetes.client.dsl.LogWatch) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ArchiveRootBuildItem(io.quarkus.deployment.builditem.ArchiveRootBuildItem) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Build(io.fabric8.openshift.api.model.Build) KubernetesCommandBuildItem(io.quarkus.kubernetes.spi.KubernetesCommandBuildItem) Path(java.nio.file.Path) IsNormalNotRemoteDev(io.quarkus.deployment.IsNormalNotRemoteDev) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) Predicate(java.util.function.Predicate) ContainerImagePushRequestBuildItem(io.quarkus.container.spi.ContainerImagePushRequestBuildItem) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) Collection(java.util.Collection) ContainerImageConfig(io.quarkus.container.image.deployment.ContainerImageConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Executors(java.util.concurrent.Executors) PackageConfig(io.quarkus.deployment.pkg.PackageConfig) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) Config(io.fabric8.kubernetes.client.Config) List(java.util.List) Stream(java.util.stream.Stream) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) Optional(java.util.Optional) Secret(io.fabric8.kubernetes.api.model.Secret) AvailableContainerImageExtensionBuildItem(io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem) Logger(org.jboss.logging.Logger) KubernetesClientErrorHandler(io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHandler) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) CompiledJavaVersionBuildItem(io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) ImageUtil(io.quarkus.container.image.deployment.util.ImageUtil) BuildStep(io.quarkus.deployment.annotations.BuildStep) BaseImageInfoBuildItem(io.quarkus.container.spi.BaseImageInfoBuildItem) ImageStream(io.fabric8.openshift.api.model.ImageStream) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) ContainerImageBuildRequestBuildItem(io.quarkus.container.spi.ContainerImageBuildRequestBuildItem) Files(java.nio.file.Files) Executor(java.util.concurrent.Executor) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) IOException(java.io.IOException) Serialization(io.dekorate.utils.Serialization) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) InputStreamReader(java.io.InputStreamReader) NativeBuild(io.quarkus.deployment.pkg.steps.NativeBuild) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Clients(io.dekorate.utils.Clients) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) Closeable(java.io.Closeable) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ContainerImageConfig(io.quarkus.container.image.deployment.ContainerImageConfig) PackageConfig(io.quarkus.deployment.pkg.PackageConfig) Config(io.fabric8.kubernetes.client.Config) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) ImageStream(io.fabric8.openshift.api.model.ImageStream) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException) Secret(io.fabric8.kubernetes.api.model.Secret) ByteArrayInputStream(java.io.ByteArrayInputStream) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) File(java.io.File)

Example 3 with GeneratedFileSystemResourceBuildItem

use of io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem in project quarkus by quarkusio.

the class OpenshiftProcessor method createContainerImage.

public static void createContainerImage(KubernetesClientBuildItem kubernetesClient, GeneratedFileSystemResourceBuildItem openshiftManifests, OpenshiftConfig openshiftConfig, String base, Path output, Path... additional) {
    File tar;
    try {
        File original = Packaging.packageFile(output, base, additional);
        // Let's rename the archive and give it a more descriptive name, as it may appear in the logs.
        tar = Files.createTempFile("quarkus-", "-openshift").toFile();
        Files.move(original.toPath(), tar.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (Exception e) {
        throw new RuntimeException("Error creating the openshift binary build archive.", e);
    }
    Config config = kubernetesClient.getClient().getConfiguration();
    // Let's disable http2 as it causes issues with duplicate build triggers.
    config.setHttp2Disable(true);
    try (KubernetesClient client = Clients.fromConfig(config)) {
        OpenShiftClient openShiftClient = toOpenshiftClient(client);
        KubernetesList kubernetesList = Serialization.unmarshalAsList(new ByteArrayInputStream(openshiftManifests.getData()));
        List<HasMetadata> buildResources = kubernetesList.getItems().stream().filter(i -> i instanceof BuildConfig || i instanceof ImageStream || i instanceof Secret).collect(Collectors.toList());
        applyOpenshiftResources(openShiftClient, buildResources);
        openshiftBuild(openShiftClient, buildResources, tar, openshiftConfig);
    }
}
Also used : Arrays(java.util.Arrays) KubernetesClientBuildItem(io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem) KubernetesEnvBuildItem(io.quarkus.kubernetes.spi.KubernetesEnvBuildItem) Packaging(io.dekorate.utils.Packaging) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) LogWatch(io.fabric8.kubernetes.client.dsl.LogWatch) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ArchiveRootBuildItem(io.quarkus.deployment.builditem.ArchiveRootBuildItem) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Build(io.fabric8.openshift.api.model.Build) KubernetesCommandBuildItem(io.quarkus.kubernetes.spi.KubernetesCommandBuildItem) Path(java.nio.file.Path) IsNormalNotRemoteDev(io.quarkus.deployment.IsNormalNotRemoteDev) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) OpenshiftUtils.mergeConfig(io.quarkus.container.image.openshift.deployment.OpenshiftUtils.mergeConfig) DEFAULT_FAST_JAR_DIRECTORY_NAME(io.quarkus.deployment.pkg.steps.JarResultBuildStep.DEFAULT_FAST_JAR_DIRECTORY_NAME) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) Predicate(java.util.function.Predicate) ContainerImagePushRequestBuildItem(io.quarkus.container.spi.ContainerImagePushRequestBuildItem) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) PathsUtil.findMainSourcesRoot(io.quarkus.container.util.PathsUtil.findMainSourcesRoot) Collection(java.util.Collection) ContainerImageConfig(io.quarkus.container.image.deployment.ContainerImageConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DecoratorBuildItem(io.quarkus.kubernetes.spi.DecoratorBuildItem) Reader(java.io.Reader) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) PackageConfig(io.quarkus.deployment.pkg.PackageConfig) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) Config(io.fabric8.kubernetes.client.Config) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) Secret(io.fabric8.kubernetes.api.model.Secret) AvailableContainerImageExtensionBuildItem(io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem) Logger(org.jboss.logging.Logger) KubernetesClientErrorHandler(io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHandler) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) CompiledJavaVersionBuildItem(io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) ImageUtil(io.quarkus.container.image.deployment.util.ImageUtil) BuildStep(io.quarkus.deployment.annotations.BuildStep) BaseImageInfoBuildItem(io.quarkus.container.spi.BaseImageInfoBuildItem) ImageStream(io.fabric8.openshift.api.model.ImageStream) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) ContainerImageBuildRequestBuildItem(io.quarkus.container.spi.ContainerImageBuildRequestBuildItem) Files(java.nio.file.Files) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) IOException(java.io.IOException) Serialization(io.dekorate.utils.Serialization) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) InputStreamReader(java.io.InputStreamReader) NativeBuild(io.quarkus.deployment.pkg.steps.NativeBuild) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Clients(io.dekorate.utils.Clients) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OpenshiftUtils.mergeConfig(io.quarkus.container.image.openshift.deployment.OpenshiftUtils.mergeConfig) ContainerImageConfig(io.quarkus.container.image.deployment.ContainerImageConfig) PackageConfig(io.quarkus.deployment.pkg.PackageConfig) Config(io.fabric8.kubernetes.client.Config) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) ImageStream(io.fabric8.openshift.api.model.ImageStream) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException) Secret(io.fabric8.kubernetes.api.model.Secret) ByteArrayInputStream(java.io.ByteArrayInputStream) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) File(java.io.File)

Example 4 with GeneratedFileSystemResourceBuildItem

use of io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem in project quarkus-openshift-test-suite by quarkus-qe.

the class AppMetadataCollector method collectAppMetadata.

@BuildStep
public void collectAppMetadata(ContainerImageInfoBuildItem containerImage, HttpRootPathBuildItem httpRoot, Optional<KubernetesHealthLivenessPathBuildItem> liveness, Optional<KubernetesHealthReadinessPathBuildItem> readiness, BuildProducer<GeneratedFileSystemResourceBuildItem> output) {
    String image = containerImage.getImage();
    int lastSlash = image.lastIndexOf('/');
    int lastColon = image.lastIndexOf(':');
    String appName = image.substring(lastSlash + 1, lastColon);
    // paths to Kubernetes probes are already httpRoot-adjusted
    String knownEndpoint;
    if (readiness.isPresent()) {
        knownEndpoint = readiness.get().getPath();
    } else if (liveness.isPresent()) {
        knownEndpoint = liveness.get().getPath();
    } else {
        // TODO ?
        knownEndpoint = httpRoot.resolvePath("/");
    }
    String deploymentTarget = ConfigProvider.getConfig().getOptionalValue("quarkus.kubernetes.deployment-target", String.class).orElse("");
    AppMetadata result = new AppMetadata(appName, httpRoot.getRootPath(), knownEndpoint, deploymentTarget);
    output.produce(new GeneratedFileSystemResourceBuildItem("app-metadata.properties", result.toString().getBytes(StandardCharsets.UTF_8)));
}
Also used : GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 5 with GeneratedFileSystemResourceBuildItem

use of io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem 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

GeneratedFileSystemResourceBuildItem (io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem)11 BuildStep (io.quarkus.deployment.annotations.BuildStep)10 Path (java.nio.file.Path)10 IOException (java.io.IOException)9 Serialization (io.dekorate.utils.Serialization)8 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)8 OutputTargetBuildItem (io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem)8 Clients (io.dekorate.utils.Clients)6 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)6 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)6 Secret (io.fabric8.kubernetes.api.model.Secret)6 Config (io.fabric8.kubernetes.client.Config)6 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)6 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)6 LogWatch (io.fabric8.kubernetes.client.dsl.LogWatch)6 Build (io.fabric8.openshift.api.model.Build)6 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)6 ImageStream (io.fabric8.openshift.api.model.ImageStream)6 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)6 ContainerImageConfig (io.quarkus.container.image.deployment.ContainerImageConfig)6