use of io.quarkiverse.operatorsdk.bundle.runtime.BundleGenerationConfiguration 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:");
}
}
}
use of io.quarkiverse.operatorsdk.bundle.runtime.BundleGenerationConfiguration 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;
}
use of io.quarkiverse.operatorsdk.bundle.runtime.BundleGenerationConfiguration 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);
}
Aggregations