Search in sources :

Example 1 with ApplicationInfoBuildItem

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

the class ContainerImageProcessor method publishImageInfo.

@BuildStep
public void publishImageInfo(ApplicationInfoBuildItem app, ContainerImageConfig containerImageConfig, Optional<FallbackContainerImageRegistryBuildItem> containerImageRegistry, Capabilities capabilities, BuildProducer<ContainerImageInfoBuildItem> containerImage) {
    ensureSingleContainerImageExtension(capabilities);
    // additionalTags are used even containerImageConfig.image is set because that string cannot contain multiple tags
    if (containerImageConfig.additionalTags.isPresent()) {
        for (String additionalTag : containerImageConfig.additionalTags.get()) {
            if (!ImageReference.isValidTag(additionalTag)) {
                throw new IllegalArgumentException("The supplied additional container-image tag '" + additionalTag + "' is invalid");
            }
        }
    }
    String effectiveGroup = containerImageConfig.getEffectiveGroup().orElse("");
    // This can be the case when running inside kubernetes/minikube in dev-mode. Instead of failing, we should just catch and log.
    if (UNKNOWN_USER.equals(effectiveGroup)) {
        log.warn("Can't get the current user name, which is used as default for container image group. Can't publish container image info.");
        return;
    }
    // if the user supplied the entire image string, use it
    if (containerImageConfig.image.isPresent()) {
        ImageReference imageReference = ImageReference.parse(containerImageConfig.image.get());
        String repository = imageReference.getRepository();
        containerImage.produce(new ContainerImageInfoBuildItem(Optional.of(imageReference.getRegistry()), repository, imageReference.getTag(), containerImageConfig.additionalTags.orElse(Collections.emptyList())));
        return;
    }
    String registry = containerImageConfig.registry.orElseGet(() -> containerImageRegistry.map(FallbackContainerImageRegistryBuildItem::getRegistry).orElse(null));
    if ((registry != null) && !ImageReference.isValidRegistry(registry)) {
        throw new IllegalArgumentException("The supplied container-image registry '" + registry + "' is invalid");
    }
    String effectiveName = containerImageConfig.name.orElse(app.getName());
    String repository = (containerImageConfig.getEffectiveGroup().map(s -> s + "/").orElse("")) + effectiveName;
    if (!ImageReference.isValidRepository(repository)) {
        throw new IllegalArgumentException("The supplied combination of container-image group '" + effectiveGroup + "' and name '" + effectiveName + "' is invalid");
    }
    final String effectiveTag = containerImageConfig.tag.orElse(app.getVersion());
    if (!ImageReference.isValidTag(effectiveTag)) {
        throw new IllegalArgumentException("The supplied container-image tag '" + effectiveTag + "' is invalid");
    }
    containerImage.produce(new ContainerImageInfoBuildItem(Optional.ofNullable(registry), containerImageConfig.getEffectiveGroup(), effectiveName, effectiveTag, containerImageConfig.additionalTags.orElse(Collections.emptyList())));
}
Also used : ContainerImageBuildRequestBuildItem(io.quarkus.container.spi.ContainerImageBuildRequestBuildItem) ContainerImagePushRequestBuildItem(io.quarkus.container.spi.ContainerImagePushRequestBuildItem) Logger(org.jboss.logging.Logger) EnablementUtil(io.quarkus.container.image.deployment.util.EnablementUtil) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) Capabilities(io.quarkus.deployment.Capabilities) BuildStep(io.quarkus.deployment.annotations.BuildStep) SuppressNonRuntimeConfigChangedWarningBuildItem(io.quarkus.deployment.builditem.SuppressNonRuntimeConfigChangedWarningBuildItem) FallbackContainerImageRegistryBuildItem(io.quarkus.container.spi.FallbackContainerImageRegistryBuildItem) ImageReference(io.quarkus.container.spi.ImageReference) ApplicationInfoBuildItem(io.quarkus.deployment.builditem.ApplicationInfoBuildItem) Optional(java.util.Optional) NativeSourcesBuild(io.quarkus.deployment.pkg.steps.NativeSourcesBuild) Collections(java.util.Collections) ImageReference(io.quarkus.container.spi.ImageReference) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) FallbackContainerImageRegistryBuildItem(io.quarkus.container.spi.FallbackContainerImageRegistryBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with ApplicationInfoBuildItem

use of io.quarkus.deployment.builditem.ApplicationInfoBuildItem in project quarkus-operator-sdk by quarkiverse.

the class BundleProcessor method generateBundle.

@BuildStep
void generateBundle(ApplicationInfoBuildItem configuration, BundleGenerationConfiguration bundleConfiguration, BuildTimeOperatorConfiguration operatorConfiguration, OutputTargetBuildItem outputTarget, CSVMetadataBuildItem csvMetadata, BuildProducer<GeneratedBundleBuildItem> doneGeneratingCSV, GeneratedCRDInfoBuildItem generatedCustomResourcesDefinitions, List<GeneratedKubernetesResourceBuildItem> generatedKubernetesManifests, BuildProducer<GeneratedFileSystemResourceBuildItem> generatedCSVs) {
    if (bundleConfiguration.enabled) {
        try {
            final var crds = generatedCustomResourcesDefinitions.getCRDGenerationInfo().getCrds().values().stream().flatMap(entry -> entry.values().stream()).collect(Collectors.toList());
            final var outputDir = outputTarget.getOutputDirectory().resolve(BUNDLE);
            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);
                    }
                });
            });
            final var generated = BundleGenerator.prepareGeneration(bundleConfiguration, operatorConfiguration, csvMetadata.getCsvGroups(), crds);
            generated.forEach(manifestBuilder -> {
                final var fileName = manifestBuilder.getFileName();
                try {
                    generatedCSVs.produce(new GeneratedFileSystemResourceBuildItem(Path.of(BUNDLE).resolve(manifestBuilder.getName()).resolve(fileName).toString(), manifestBuilder.getManifestData(serviceAccounts, clusterRoleBindings, clusterRoles, roleBindings, roles, deployments)));
                    log.infov("Generating {0} for {1} controller -> {2}", manifestBuilder.getManifestType(), manifestBuilder.getName(), outputDir.resolve(manifestBuilder.getName()).resolve(fileName));
                } catch (IOException e) {
                    log.errorv("Cannot generate {0} for {1}: {2}", manifestBuilder.getManifestType(), manifestBuilder.getName(), e.getMessage());
                }
            });
            doneGeneratingCSV.produce(new GeneratedBundleBuildItem());
        } catch (Exception e) {
            log.infov(e, "Couldn't generate bundle:");
        }
    }
}
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) ClassInfo(org.jboss.jandex.ClassInfo) CSVMetadataHolder(io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadataHolder) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) GeneratedCRDInfoBuildItem(io.quarkiverse.operatorsdk.deployment.GeneratedCRDInfoBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ArrayList(java.util.ArrayList) GeneratedKubernetesResourceBuildItem(io.quarkus.kubernetes.spi.GeneratedKubernetesResourceBuildItem) RoleBinding(io.fabric8.kubernetes.api.model.rbac.RoleBinding) BuildStep(io.quarkus.deployment.annotations.BuildStep) BundleGenerationConfiguration(io.quarkiverse.operatorsdk.bundle.runtime.BundleGenerationConfiguration) ByteArrayInputStream(java.io.ByteArrayInputStream) ConfigurationUtils(io.quarkiverse.operatorsdk.common.ConfigurationUtils) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) IndexView(org.jboss.jandex.IndexView) AnnotationValue(org.jboss.jandex.AnnotationValue) ResourceInfo(io.quarkiverse.operatorsdk.runtime.ResourceInfo) BuildTimeOperatorConfiguration(io.quarkiverse.operatorsdk.runtime.BuildTimeOperatorConfiguration) IOException(java.io.IOException) Serialization(io.dekorate.utils.Serialization) ConfigurationServiceBuildItem(io.quarkiverse.operatorsdk.deployment.ConfigurationServiceBuildItem) Collectors(java.util.stream.Collectors) CSVMetadata(io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata) Objects(java.util.Objects) List(java.util.List) SharedCSVMetadata(io.quarkiverse.operatorsdk.bundle.runtime.SharedCSVMetadata) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ApplicationInfoBuildItem(io.quarkus.deployment.builditem.ApplicationInfoBuildItem) 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) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with ApplicationInfoBuildItem

use of io.quarkus.deployment.builditem.ApplicationInfoBuildItem in project quarkus-operator-sdk by quarkiverse.

the class BundleProcessor method gatherCSVMetadata.

@SuppressWarnings("unchecked")
@BuildStep
CSVMetadataBuildItem gatherCSVMetadata(ApplicationInfoBuildItem configuration, BundleGenerationConfiguration bundleConfiguration, CombinedIndexBuildItem combinedIndexBuildItem, ConfigurationServiceBuildItem configurations) {
    final var controllerConfigs = configurations.getControllerConfigs();
    final var index = combinedIndexBuildItem.getIndex();
    final var operatorCsvMetadata = getCSVMetadataForOperator(bundleConfiguration.packageName.orElse(configuration.getName()), index);
    final var csvGroups = new HashMap<CSVMetadataHolder, List<AugmentedResourceInfo>>();
    ClassUtils.getKnownReconcilers(index, log).forEach(reconcilerInfo -> {
        // figure out which group should be used to generate CSV
        final var name = reconcilerInfo.name();
        log.debugv("Processing reconciler: {0}", name);
        final var config = controllerConfigs.get(name);
        if (config == null) {
            throw new IllegalStateException("Missing configuration for reconciler " + name);
        }
        // Check whether the reconciler must be shipped using a custom bundle
        CSVMetadataHolder csvMetadata = getCsvMetadataFromAnnotation(operatorCsvMetadata, reconcilerInfo.classInfo()).orElse(operatorCsvMetadata);
        final var resourceFullName = config.getResourceTypeName();
        final var resourceInfo = ResourceInfo.createFrom(config.getResourceClass(), resourceFullName, name, config.getSpecClassName(), config.getStatusClassName());
        csvGroups.computeIfAbsent(csvMetadata, m -> new ArrayList<>()).add(new AugmentedResourceInfo(resourceInfo, csvMetadata.name));
    });
    return new CSVMetadataBuildItem(csvGroups);
}
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) ClassInfo(org.jboss.jandex.ClassInfo) CSVMetadataHolder(io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadataHolder) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) GeneratedCRDInfoBuildItem(io.quarkiverse.operatorsdk.deployment.GeneratedCRDInfoBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ArrayList(java.util.ArrayList) GeneratedKubernetesResourceBuildItem(io.quarkus.kubernetes.spi.GeneratedKubernetesResourceBuildItem) RoleBinding(io.fabric8.kubernetes.api.model.rbac.RoleBinding) BuildStep(io.quarkus.deployment.annotations.BuildStep) BundleGenerationConfiguration(io.quarkiverse.operatorsdk.bundle.runtime.BundleGenerationConfiguration) ByteArrayInputStream(java.io.ByteArrayInputStream) ConfigurationUtils(io.quarkiverse.operatorsdk.common.ConfigurationUtils) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) IndexView(org.jboss.jandex.IndexView) AnnotationValue(org.jboss.jandex.AnnotationValue) ResourceInfo(io.quarkiverse.operatorsdk.runtime.ResourceInfo) BuildTimeOperatorConfiguration(io.quarkiverse.operatorsdk.runtime.BuildTimeOperatorConfiguration) IOException(java.io.IOException) Serialization(io.dekorate.utils.Serialization) ConfigurationServiceBuildItem(io.quarkiverse.operatorsdk.deployment.ConfigurationServiceBuildItem) Collectors(java.util.stream.Collectors) CSVMetadata(io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata) Objects(java.util.Objects) List(java.util.List) SharedCSVMetadata(io.quarkiverse.operatorsdk.bundle.runtime.SharedCSVMetadata) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ApplicationInfoBuildItem(io.quarkus.deployment.builditem.ApplicationInfoBuildItem) 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) CSVMetadataHolder(io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadataHolder) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 4 with ApplicationInfoBuildItem

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

the class ContainerImageInfoTest method whenPublishImageInfo.

private void whenPublishImageInfo() {
    BuildTimeConfigurationReader reader = new BuildTimeConfigurationReader(Collections.singletonList(ContainerImageConfig.class));
    SmallRyeConfigBuilder builder = ConfigUtils.configBuilder(false, LaunchMode.NORMAL);
    DefaultValuesConfigurationSource ds = new DefaultValuesConfigurationSource(reader.getBuildTimePatternMap());
    PropertiesConfigSource pcs = new PropertiesConfigSource(new Properties(), "Test Properties");
    builder.withSources(ds, pcs);
    SmallRyeConfig src = builder.build();
    BuildTimeConfigurationReader.ReadResult readResult = reader.readConfiguration(src);
    ContainerImageConfig containerImageConfig = (ContainerImageConfig) readResult.requireObjectForClass(ContainerImageConfig.class);
    ApplicationInfoBuildItem app = new ApplicationInfoBuildItem(Optional.of(APP_NAME), Optional.of(APP_VERSION));
    Capabilities capabilities = new Capabilities(Collections.emptySet());
    BuildProducer<ContainerImageInfoBuildItem> containerImage = actualImageConfig -> actualContainerImageInfo = actualImageConfig;
    ContainerImageProcessor processor = new ContainerImageProcessor();
    processor.publishImageInfo(app, containerImageConfig, Optional.empty(), capabilities, containerImage);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) ConfigUtils(io.quarkus.runtime.configuration.ConfigUtils) Properties(java.util.Properties) LaunchMode(io.quarkus.runtime.LaunchMode) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) BuildTimeConfigurationReader(io.quarkus.deployment.configuration.BuildTimeConfigurationReader) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) DefaultValuesConfigurationSource(io.quarkus.deployment.configuration.DefaultValuesConfigurationSource) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) Capabilities(io.quarkus.deployment.Capabilities) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ApplicationInfoBuildItem(io.quarkus.deployment.builditem.ApplicationInfoBuildItem) SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) Optional(java.util.Optional) PropertiesConfigSource(io.smallrye.config.PropertiesConfigSource) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collections(java.util.Collections) PropertiesConfigSource(io.smallrye.config.PropertiesConfigSource) DefaultValuesConfigurationSource(io.quarkus.deployment.configuration.DefaultValuesConfigurationSource) Properties(java.util.Properties) BuildTimeConfigurationReader(io.quarkus.deployment.configuration.BuildTimeConfigurationReader) SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) Capabilities(io.quarkus.deployment.Capabilities) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) ApplicationInfoBuildItem(io.quarkus.deployment.builditem.ApplicationInfoBuildItem)

Aggregations

BuildProducer (io.quarkus.deployment.annotations.BuildProducer)4 ApplicationInfoBuildItem (io.quarkus.deployment.builditem.ApplicationInfoBuildItem)4 Optional (java.util.Optional)4 BuildStep (io.quarkus.deployment.annotations.BuildStep)3 Serialization (io.dekorate.utils.Serialization)2 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)2 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)2 ClusterRole (io.fabric8.kubernetes.api.model.rbac.ClusterRole)2 ClusterRoleBinding (io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding)2 Role (io.fabric8.kubernetes.api.model.rbac.Role)2 RoleBinding (io.fabric8.kubernetes.api.model.rbac.RoleBinding)2 BundleGenerationConfiguration (io.quarkiverse.operatorsdk.bundle.runtime.BundleGenerationConfiguration)2 CSVMetadata (io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata)2 CSVMetadataHolder (io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadataHolder)2 SharedCSVMetadata (io.quarkiverse.operatorsdk.bundle.runtime.SharedCSVMetadata)2 ClassUtils (io.quarkiverse.operatorsdk.common.ClassUtils)2 ConfigurationUtils (io.quarkiverse.operatorsdk.common.ConfigurationUtils)2 ALL_VERBS (io.quarkiverse.operatorsdk.deployment.AddClusterRolesDecorator.ALL_VERBS)2 ConfigurationServiceBuildItem (io.quarkiverse.operatorsdk.deployment.ConfigurationServiceBuildItem)2 GeneratedCRDInfoBuildItem (io.quarkiverse.operatorsdk.deployment.GeneratedCRDInfoBuildItem)2