grafana / grafana-app-sdk

An SDK for developing apps for grafana using kubernetes-like storage and operators
Apache License 2.0
48 stars 8 forks source link

[codegen] Source Codegen from CUE App Manifest #483

Open IfSentient opened 1 week ago

IfSentient commented 1 week ago

What this PR Does

This PR changes the format of CUE codegen, moving from reading all top-level CUE selectors as kinds to reading a single manifest top-level field (or a different name if supplied). Other top-level fields are ignored, allowing kinds to still be defined as root-level keys, but they will only be parsed for codegen if listed in the kinds field in the manifest.

This change is required to properly generate a manifest that

There are some slight changes around writing a kind, namely that the fields previous in apiResource are either moved into the main body of the kind, or into the manifest itself, as all kinds are now always API resources.

The grafana-app-sdk project init command now generates a kinds/manifest.cue with a basic manifest, and grafana-app-sdk project kind add still creates a kind CUE file, but now also adds the kind to the list of kinds in manifest.cue, found under manifest.kinds.

In the codegen package, jennies may use codegen.Kind or codegen.AppManifest as their input, to allow for not requiring too much change there. The cuekind.Parser now doesn't implement codegen.Parser[codegen.Kind] itself, and instead has methods to get a parser that implements either codegen.Parser[codegen.Kind] or codegen.Parser[codegen.AppManifest]. This is likely an intermediary step as we continue to improve the codegen pipeline's structure. This PR aims mainly to change the input type of --format=cue to use the manifest, and define that manifest properly, with a low-impact changes as possible to the rest of the project.