[WIP] Unify Grafana Kind and Kubernetes Kind Formats #32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is some initial scratch work to unify the way grafana kinds are represented in both the API Server responses/consumption (Kubernetes format) and in-code (Grafana format). This unification changes the structure of the metadata into a "composed set" of metadata which is sourced from both the kubernetes metadata and grafana common and kind-specific metadata, to which how they are implemented relies on the encoder (to preserve compatibility with CRD expression if/when needed). When using an aggregated API server for grafana kinds, additional subresources will be exposed for the non-kubernetes metadata, creating the following shape:
This format then is mirrored exactly in the
UnstructuredResource
, and is the "exposed" format via theResource
interface.However, in order to allow for standard kubernetes tooling which may not understand the additional metadata subresources, the following must be done on encoding the resource into JSON/YAML/etc:
GrafanaMetadata
must be JSON-encoded and placed inmetadata.annotations
with a key ofgrafana.com/X
, whereX
is theGrafanaMetadata
field key.KindMetadata
must be JSON-encoded and placed inmetadata.annotations
with a key ofext.grafana.com/X
whereX
is theKindMetadata
field key.These annotations are essentially read-only, as the source of truth is always the appropriate metadata subresource, but they are exposed via annotations so tooling can make use of them if incapable of handling non-standard subresources.
This is somewhat analogous to how currently
CommonMetadata
has the non-kubernetes keys encoded intometadata.annotations
andCustomMetadata
has all keys encoded intometadata.annotations
, but now with the additional ability to have non-string values for keys, as we no longer need to decode said annotations when unmarshaling.There are additional concerns to be worked out, but I wanted to get this scratch space up to allow for conversation on the subject of properly unifying in-code (grafana) and API Server (kubernetes) forms of a Resource, as having to work with multiple forms creates what may be an undue mental burden.
Note that there still will be encoders/decoders for working with standard CRD's (basically using the same "encode" logic, but then inverting that logic for "decode"), but as these are only required for the
grafana-app-sdk
, they will likely live there.