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:");
}
}
}
Aggregations